From d87c08a3c6e6a50106a56037a5dee7a9eb14d70d Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Tue, 18 Feb 2025 18:22:39 +0700 Subject: [PATCH 1/5] feat: start/stop controller --- changelog.md | 11 +- library.json | 2 +- library.properties | 2 +- src/Capabilities/StartStopController.h | 178 +++++++++++++++++++++++++ src/SinricProVersion.h | 2 +- 5 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 src/Capabilities/StartStopController.h diff --git a/changelog.md b/changelog.md index d9592afa..e63cbec0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,15 @@ # Changelog -## Version 3.4.1 +## Version 3.5.1 + Fixed: + - Logging messages. + New: - - Fix: invalid signature error message. + - Support Start/Stop Controller for custom device types + +## Version 3.4.1 + Fixed: + - Fix: invalid signature error message. ## Version 3.4.0 New: diff --git a/library.json b/library.json index d018e23c..eb8ad433 100644 --- a/library.json +++ b/library.json @@ -13,7 +13,7 @@ "maintainer": true } ], - "version": "3.4.1", + "version": "3.5.1", "frameworks": "arduino", "platforms": [ "espressif8266", diff --git a/library.properties b/library.properties index d610a1ad..d3cff445 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SinricPro -version=3.4.1 +version=3.5.1 author=Boris Jaeger maintainer=Boris Jaeger sentence=Library for https://sinric.pro - simple way to connect your device to alexa diff --git a/src/Capabilities/StartStopController.h b/src/Capabilities/StartStopController.h new file mode 100644 index 00000000..0dd0285b --- /dev/null +++ b/src/Capabilities/StartStopController.h @@ -0,0 +1,178 @@ +#pragma once + +#include "../SinricProRequest.h" +#include "../EventLimiter.h" +#include "../SinricProStrings.h" + +#include "../SinricProNamespace.h" +namespace SINRICPRO_NAMESPACE { + +FSTR(START_STOP, start); // "start" +FSTR(START_STOP, pause); // "pause" +FSTR(START_STOP, setStartStop); // "setStartStop" +FSTR(START_STOP, setPauseUnpause); // "setPauseUnpause" + +/** + * @brief Definition for onStartStop callback + * + * Gets called when device receive a `setStartStop` reuqest \n + * @param[in] deviceId String which contains the ID of device + * @param[in] start true for start, false for stop + * @return the success of the request + * @retval true request handled properly + * @retval false request was not handled properly because of some error + * + * @section StartStopCallback Example-Code + * @snippet callbacks.cpp onStartStop + **/ +using StartStopCallback = std::function; + +/** + * @brief Definition for onPauseUnpause callback + * + * Gets called when device receive a `setPauseUnpause` reuqest \n + * @param[in] deviceId String which contains the ID of device + * @param[in] pause true for pause, false for unpause + * @return the success of the request + * @retval true request handled properly + * @retval false request was not handled properly because of some error + * + * @section StartStopCallback Example-Code + * @snippet callbacks.cpp onPauseUnpause + **/ + +using PauseUnpauseCallback = std::function; + +/** + * @brief StartStopController class to handle start/stop and pause/unpause functionality + * + * This template class provides functionality to control devices that can be started, + * stopped, paused, and unpaused (like a vacuum cleaner, washing machine, etc.) + * + * @tparam T The device type that this controller is attached to + */ +template +class StartStopController { + public: + StartStopController(); + + /** + * @brief Set the callback function for start/stop events + * + * @param cb Callback function that will be called when a start/stop request is received + */ + void onStartStop(StartStopCallback cb); + + /** + * @brief Set the callback function for pause/unpause events + * + * @param cb Callback function that will be called when a pause/unpause request is received + */ + void onPauseUnpause(StartStopCallback cb); + + /** + * @brief Send a start/stop event to the SinricPro server + * + * @param start true for start, false for stop + * @param cause The cause of the event (default: "PHYSICAL_INTERACTION") + * @return true if event was sent successfully, false otherwise + */ + bool sendStartStopEvent(bool start, String cause = FSTR_SINRICPRO_PHYSICAL_INTERACTION); + + /** + * @brief Send a pause/unpause event to the SinricPro server + * + * @param pause true for pause, false for unpause + * @param cause The cause of the event (default: "PHYSICAL_INTERACTION") + * @return true if event was sent successfully, false otherwise + */ + bool sendPauseUnpauseEvent(bool pause, String cause = FSTR_SINRICPRO_PHYSICAL_INTERACTION); + + protected: + bool handleStartStopController(SinricProRequest &request); + + private: + EventLimiter event_limiter; + StartStopCallback startStopCallbackCallback; + PauseUnpauseCallback pauseUnpauseCallback; +}; + +template +StartStopController::StartStopController() +:event_limiter(EVENT_LIMIT_STATE) { + T* device = static_cast(this); + device->registerRequestHandler(std::bind(&StartStopController::handleStartStopController, this, std::placeholders::_1)); +} + +template +void StartStopController::onStartStop(StartStopCallback cb) { startStopCallbackCallback = cb; } + +template +void StartStopController::onPauseUnpause(PauseUnpauseCallback cb) { pauseUnpauseCallback = cb; } + +/** + * @brief Send a start/stop event to the SinricPro server + * + * Creates a JSON message with the start status and sends it to the server + * @param start `bool` true for start, false for stop + * @param cause (optional) Reason why event is sent (default = `"PHYSICAL_INTERACTION"`) + */ +template +bool StartStopController::sendStartStopEvent(bool start, String cause) { + if (event_limiter) return false; + T* device = static_cast(this); + + JsonDocument eventMessage = device->prepareEvent(FSTR_START_STOP_setStartStop, cause.c_str()); + JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value]; + event_value[FSTR_START_STOP_start] = start; + return device->sendEvent(eventMessage); +} + +/** + * @brief Send a pause/unpause event to the SinricPro server + * + * Creates a JSON message with the pause status and sends it to the server + * @param pause `bool` true for pause, false for unpause + * @param cause (optional) Reason why event is sent (default = `"PHYSICAL_INTERACTION"`) + */ +template +bool StartStopController::sendPauseUnpauseEvent(bool pause, String cause) { + if (event_limiter) return false; + T* device = static_cast(this); + + JsonDocument eventMessage = device->prepareEvent(FSTR_START_STOP_setPauseUnpause, cause.c_str()); + JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value]; + event_value[FSTR_START_STOP_pause] = pause; + return device->sendEvent(eventMessage); +} + +template +bool StartStopController::handleStartStopController(SinricProRequest &request) { + if (request.action != FSTR_START_STOP_setStartStop || request.action != FSTR_START_STOP_setPauseUnpause) { + return false; + } + + T* device = static_cast(this); + + bool success = false; + + if (startStopCallbackCallback && request.action == FSTR_START_STOP_setStartStop) { + bool start = request.request_value[FSTR_START_STOP_start]; + success = startStopCallbackCallback(device->deviceId, start); + request.response_value[FSTR_START_STOP_start] = start; + return success; + } + else if (startStopCallbackCallback && request.action == FSTR_START_STOP_setPauseUnpause) { + bool pause = request.request_value[FSTR_START_STOP_pause]; + success = startStopCallbackCallback(device->deviceId, pause); + request.response_value[FSTR_START_STOP_pause] = pause; + return success; + } + + return success; +} + +} // SINRICPRO_NAMESPACE + +template +using StartStopController = SINRICPRO_NAMESPACE::StartStopController; \ No newline at end of file diff --git a/src/SinricProVersion.h b/src/SinricProVersion.h index 749ec458..7f6b1d0a 100644 --- a/src/SinricProVersion.h +++ b/src/SinricProVersion.h @@ -5,7 +5,7 @@ // Version Configuration #define SINRICPRO_VERSION_MAJOR 3 -#define SINRICPRO_VERSION_MINOR 4 +#define SINRICPRO_VERSION_MINOR 5 #define SINRICPRO_VERSION_REVISION 1 #define SINRICPRO_VERSION STR(SINRICPRO_VERSION_MAJOR) "." STR(SINRICPRO_VERSION_MINOR) "." STR(SINRICPRO_VERSION_REVISION) #define SINRICPRO_VERSION_STR "SinricPro (v" SINRICPRO_VERSION ")" From 4fbf1292f20468df2ecd9a026d561b450b04d100 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Wed, 26 Feb 2025 08:05:08 +0700 Subject: [PATCH 2/5] feat: open/close support for GH --- src/Capabilities/OpenCloseController.h | 111 +++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/Capabilities/OpenCloseController.h diff --git a/src/Capabilities/OpenCloseController.h b/src/Capabilities/OpenCloseController.h new file mode 100644 index 00000000..eb8d3c1c --- /dev/null +++ b/src/Capabilities/OpenCloseController.h @@ -0,0 +1,111 @@ +#pragma once + +#include "../SinricProRequest.h" +#include "../EventLimiter.h" +#include "../SinricProStrings.h" + +#include "../SinricProNamespace.h" +namespace SINRICPRO_NAMESPACE { + +FSTR(OPEN_CLOSE, openPercent); // "openPercent" +FSTR(OPEN_CLOSE, openDirection); // "openDirection" +FSTR(OPEN_CLOSE, setOpenClose); // "setOpenClose" +FSTR(OPEN_CLOSE, adjustOpenClose); // "adjustOpenClose" + +using OpenCloseCallback = std::function; + +using AdjustOpenCloseCallback = std::function; + +template +class OpenCloseController { + public: + OpenCloseController(); + + void onOpenClose(OpenCloseCallback cb); + + void onAdjustOpenClose(AdjustOpenCloseCallback cb); + + bool sendOpenCloseEvent(int openPercent, String cause = FSTR_SINRICPRO_PHYSICAL_INTERACTION); + + bool sendOpenCloseEvent(String openDirection, int openPercent, String cause = FSTR_SINRICPRO_PHYSICAL_INTERACTION); + + protected: + bool handleOpenCloseController(SinricProRequest &request); + + private: + EventLimiter event_limiter; + OpenCloseCallback openCloseCallbackCallback; + AdjustOpenCloseCallback adjustOpenCloseCallback; +}; + +template +OpenCloseController::OpenCloseController() +:event_limiter(EVENT_LIMIT_STATE) { + T* device = static_cast(this); + device->registerRequestHandler(std::bind(&OpenCloseController::handleOpenCloseController, this, std::placeholders::_1)); +} + +template +void OpenCloseController::onOpenClose(OpenCloseCallback cb) { openCloseCallbackCallback = cb; } + +template +void OpenCloseController::onAdjustOpenClose(AdjustOpenCloseCallback cb) { adjustOpenCloseCallback = cb; } + +template +bool OpenCloseController::sendOpenCloseEvent(String openDirection, int openPercent, String cause) { + if (event_limiter) return false; + T* device = static_cast(this); + + JsonDocument eventMessage = device->prepareEvent(FSTR_OPEN_CLOSE_setOpenClose, cause.c_str()); + JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value]; + event_value[FSTR_OPEN_CLOSE_openDirection] = openDirection; + event_value[FSTR_OPEN_CLOSE_openPercent] = openPercent; + + return device->sendEvent(eventMessage); +} + +template +bool OpenCloseController::sendOpenCloseEvent(int openPercent, String cause) { + if (event_limiter) return false; + T* device = static_cast(this); + + JsonDocument eventMessage = device->prepareEvent(FSTR_OPEN_CLOSE_setOpenClose, cause.c_str()); + JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value]; + event_value[FSTR_OPEN_CLOSE_openPercent] = openPercent; + + return device->sendEvent(eventMessage); +} + +template +bool OpenCloseController::handleOpenCloseController(SinricProRequest &request) { + if (request.action != FSTR_OPEN_CLOSE_setOpenClose) { + return false; + } + + T* device = static_cast(this); + + bool success = false; + + if (openCloseCallbackCallback && request.action == FSTR_OPEN_CLOSE_setOpenClose) { + String openDirection = request.request_value[FSTR_OPEN_CLOSE_openDirection]; + int openPercent = request.request_value[FSTR_OPEN_CLOSE_openPercent]; + + success = openCloseCallbackCallback(device->deviceId, openDirection, openPercent); + + request.response_value[FSTR_OPEN_CLOSE_openDirection] = openDirection; + request.response_value[FSTR_OPEN_CLOSE_openPercent] = openPercent; + + return success; + } + + if (adjustOpenCloseCallback && request.action == FSTR_OPEN_CLOSE_adjustOpenClose) { + // TOOD: + } + + return success; +} + +} // SINRICPRO_NAMESPACE + +template +using OpenCloseController = SINRICPRO_NAMESPACE::OpenCloseController; \ No newline at end of file From a0abd1ce00818f76a3d5251959447a1266ee137d Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Wed, 26 Feb 2025 10:24:25 +0700 Subject: [PATCH 3/5] feat: open-close support added --- src/Capabilities/OpenCloseController.h | 212 ++++++++++++++++++++++--- 1 file changed, 193 insertions(+), 19 deletions(-) diff --git a/src/Capabilities/OpenCloseController.h b/src/Capabilities/OpenCloseController.h index eb8d3c1c..0c7ee39a 100644 --- a/src/Capabilities/OpenCloseController.h +++ b/src/Capabilities/OpenCloseController.h @@ -7,35 +7,159 @@ #include "../SinricProNamespace.h" namespace SINRICPRO_NAMESPACE { -FSTR(OPEN_CLOSE, openPercent); // "openPercent" -FSTR(OPEN_CLOSE, openDirection); // "openDirection" -FSTR(OPEN_CLOSE, setOpenClose); // "setOpenClose" -FSTR(OPEN_CLOSE, adjustOpenClose); // "adjustOpenClose" +FSTR(OPEN_CLOSE, openPercent); // "openPercent" +FSTR(OPEN_CLOSE, openRelativePercent); // "openRelativePercent" +FSTR(OPEN_CLOSE, openDirection); // "openDirection" +FSTR(OPEN_CLOSE, setOpenClose); // "setOpenClose" +FSTR(OPEN_CLOSE, adjustOpenClose); // "adjustOpenClose" -using OpenCloseCallback = std::function; -using AdjustOpenCloseCallback = std::function; +/** + * @brief Callback definition for onOpenClose callback + * + * Gets called when device receives a `setOpenClose` request + * @param[in] deviceId String containing the ID of device + * @param[in,out] openPercent Integer percentage (0-100) of how open the device should be set (0 = closed, 100 = fully open) + * @return Success status of the request + * @retval true Request handled successfully + * @retval false Request handling failed + * + * @section OpenCloseCallback Example-Code + * @snippet callbacks.cpp onSetOpenClose + **/ +using OpenCloseCallback = std::function; +/** + * @brief Callback definition for onAdjustOpenClose callback + * + * Gets called when device receives an `adjustOpenClose` request + * @param[in] deviceId String containing the ID of device + * @param[in,out] openRelativePercent Integer value representing the relative percentage change to apply + * On output, should contain the absolute percentage value the device has been set to + * @return Success status of the request + * @retval true Request handled successfully + * @retval false Request handling failed + * + * @section AdjustOpenCloseCallback Example-Code + * @snippet callbacks.cpp onAdjustOpenClose + **/ +using AdjustOpenCloseCallback = std::function; + +/** + * @brief Callback definition for onDirectionOpenClose callback + * + * Gets called when device receives a `setOpenClose` request with direction information + * @param[in] deviceId String containing the ID of device + * @param[in] openDirection String direction in which to open: `UP`, `DOWN`, `LEFT`, `RIGHT`, `IN`, `OUT` + * @param[in,out] openPercent Integer percentage (0-100) of how open the device should be set + * @return Success status of the request + * @retval true Request handled successfully + * @retval false Request handling failed + * + * @section DirectionOpenCloseCallback Example-Code + * @snippet callbacks.cpp onDirectionOpenClose + **/ +using DirectionOpenCloseCallback = std::function; + +/** + * @brief Callback definition for onAdjustDirectionOpenClose callback + * + * Gets called when device receives an `adjustOpenClose` request with direction information + * @param[in] deviceId String containing the ID of device + * @param[in] openDirection String direction in which to open: `UP`, `DOWN`, `LEFT`, `RIGHT`, `IN`, `OUT` + * @param[in,out] openRelativePercent Integer representing relative percentage change to apply + * On output, should contain the absolute percentage value the device has been set to + * @return Success status of the request + * @retval true Request handled successfully + * @retval false Request handling failed + * + * @section AdjustDirectionOpenCloseCallback Example-Code + * @snippet callbacks.cpp onAdjustDirectionOpenClose + **/ +using AdjustDirectionOpenCloseCallback = std::function; + +/** + * @brief Controller class for devices with open/close functionality + * @ingroup Capabilities + * This controller handles open/close operations for devices that can be opened or closed by percentage and may supports multiple directions. + * + * @tparam T Device type that implements this controller + */ template class OpenCloseController { public: OpenCloseController(); + /** + * @brief Set callback function for simple open/close operations + * + * @param cb Function pointer to a `OpenCloseCallback` function + * @return void + * @see OpenCloseCallback + **/ void onOpenClose(OpenCloseCallback cb); + /** + * @brief Set callback function for directional open/close operations + * + * @param cb Function pointer to a `DirectionOpenCloseCallback` function + * @return void + * @see DirectionOpenCloseCallback + **/ + void onDirectionOpenClose(DirectionOpenCloseCallback cb); + + /** + * @brief Set callback function for relative adjustments to open/close status + * + * @param cb Function pointer to a `AdjustOpenCloseCallback` function + * @return void + * @see AdjustOpenCloseCallback + **/ void onAdjustOpenClose(AdjustOpenCloseCallback cb); + /** + * @brief Set callback function for directional relative adjustments + * + * @param cb Function pointer to a `AdjustDirectionOpenCloseCallback` function + * @return void + * @see AdjustDirectionOpenCloseCallback + **/ + void onAdjustDirectionOpenClose(AdjustDirectionOpenCloseCallback cb); + + /** + * @brief Send an event to update the open/close status + * + * @param openPercent Current open percentage (0-100) + * @param cause Cause of the event (default: physical interaction) + * @return bool Whether the event was sent successfully + **/ bool sendOpenCloseEvent(int openPercent, String cause = FSTR_SINRICPRO_PHYSICAL_INTERACTION); + /** + * @brief Send an event to update the open/close status with direction + * + * @param openDirection Direction of opening (UP, DOWN, LEFT, RIGHT, IN, OUT) + * @param openPercent Current open percentage (0-100) + * @param cause Cause of the event (default: physical interaction) + * @return bool Whether the event was sent successfully + **/ bool sendOpenCloseEvent(String openDirection, int openPercent, String cause = FSTR_SINRICPRO_PHYSICAL_INTERACTION); protected: + /** + * @brief Handle incoming open/close control requests + * + * @param request The incoming request to process + * @return bool Whether the request was handled successfully + **/ bool handleOpenCloseController(SinricProRequest &request); private: EventLimiter event_limiter; - OpenCloseCallback openCloseCallbackCallback; + DirectionOpenCloseCallback directionOpenCloseCallback; + OpenCloseCallback openCloseCallback; AdjustOpenCloseCallback adjustOpenCloseCallback; + AdjustDirectionOpenCloseCallback adjustDirectionOpenCloseCallback; }; template @@ -46,11 +170,28 @@ OpenCloseController::OpenCloseController() } template -void OpenCloseController::onOpenClose(OpenCloseCallback cb) { openCloseCallbackCallback = cb; } +void OpenCloseController::onOpenClose(OpenCloseCallback cb) { openCloseCallback = cb; } + +template +void OpenCloseController::onDirectionOpenClose(DirectionOpenCloseCallback cb) { directionOpenCloseCallback = cb; } template void OpenCloseController::onAdjustOpenClose(AdjustOpenCloseCallback cb) { adjustOpenCloseCallback = cb; } +template +void OpenCloseController::onAdjustDirectionOpenClose(AdjustDirectionOpenCloseCallback cb) { adjustDirectionOpenCloseCallback = cb; } + +/** + * @brief Send an event to update open/close status with open direction and precent and information + * + * Sends the current open/close status with direction to the Sinric Pro cloud. + * The event will only be sent if the event rate limiter allows it. + * + * @param openDirection Direction in which the device is opening + * @param openPercent Current open percentage (0-100) + * @param cause Reason for the state change (default: physical interaction) + * @return bool Whether the event was sent successfully + */ template bool OpenCloseController::sendOpenCloseEvent(String openDirection, int openPercent, String cause) { if (event_limiter) return false; @@ -64,6 +205,16 @@ bool OpenCloseController::sendOpenCloseEvent(String openDirection, int openPe return device->sendEvent(eventMessage); } +/** + * @brief Send an event to update open/close status + * + * Sends the current open/close percentage to the Sinric Pro cloud. + * The event will only be sent if the event rate limiter allows it. + * + * @param openPercent Current open percentage (0-100) + * @param cause Reason for the state change (default: physical interaction) + * @return bool Whether the event was sent successfully + */ template bool OpenCloseController::sendOpenCloseEvent(int openPercent, String cause) { if (event_limiter) return false; @@ -76,9 +227,18 @@ bool OpenCloseController::sendOpenCloseEvent(int openPercent, String cause) { return device->sendEvent(eventMessage); } +/** + * @brief Handle incoming open/close requests + * + * Processes both setOpenClose and adjustOpenClose requests with or without direction information. + * Delegates to the appropriate callback function based on the request type and parameters. + * + * @param request The incoming request containing action and parameters + * @return bool Whether the request was handled successfully + */ template bool OpenCloseController::handleOpenCloseController(SinricProRequest &request) { - if (request.action != FSTR_OPEN_CLOSE_setOpenClose) { + if (request.action != FSTR_OPEN_CLOSE_setOpenClose && request.action != FSTR_OPEN_CLOSE_adjustOpenClose) { return false; } @@ -86,20 +246,34 @@ bool OpenCloseController::handleOpenCloseController(SinricProRequest &request bool success = false; - if (openCloseCallbackCallback && request.action == FSTR_OPEN_CLOSE_setOpenClose) { - String openDirection = request.request_value[FSTR_OPEN_CLOSE_openDirection]; + if ((directionOpenCloseCallback || openCloseCallback) && request.action == FSTR_OPEN_CLOSE_setOpenClose) { + bool hasOpenDirection = !request.request_value[FSTR_OPEN_CLOSE_openDirection].isNull(); int openPercent = request.request_value[FSTR_OPEN_CLOSE_openPercent]; - success = openCloseCallbackCallback(device->deviceId, openDirection, openPercent); - - request.response_value[FSTR_OPEN_CLOSE_openDirection] = openDirection; - request.response_value[FSTR_OPEN_CLOSE_openPercent] = openPercent; - - return success; + if (hasOpenDirection && directionOpenCloseCallback) { + String openDirection = request.request_value[FSTR_OPEN_CLOSE_openDirection]; + success = directionOpenCloseCallback(device->deviceId, openDirection, openPercent); + request.response_value[FSTR_OPEN_CLOSE_openDirection] = openDirection; + request.response_value[FSTR_OPEN_CLOSE_openPercent] = openPercent; + } else if (!hasOpenDirection && openCloseCallback) { + success = openCloseCallback(device->deviceId, openPercent); + request.response_value[FSTR_OPEN_CLOSE_openPercent] = openPercent; + } } - if (adjustOpenCloseCallback && request.action == FSTR_OPEN_CLOSE_adjustOpenClose) { - // TOOD: + if ((adjustOpenCloseCallback || adjustDirectionOpenCloseCallback) && request.action == FSTR_OPEN_CLOSE_adjustOpenClose) { + bool hasOpenDirection = !request.request_value[FSTR_OPEN_CLOSE_openDirection].isNull(); + int openRelativePercent = request.request_value[FSTR_OPEN_CLOSE_openRelativePercent]; + + if (hasOpenDirection && adjustDirectionOpenCloseCallback) { + String openDirection = request.request_value[FSTR_OPEN_CLOSE_openDirection]; + success = adjustDirectionOpenCloseCallback(device->deviceId, openDirection, openRelativePercent); + request.response_value[FSTR_OPEN_CLOSE_openDirection] = openDirection; + request.response_value[FSTR_OPEN_CLOSE_openPercent] = openRelativePercent; + } else if (!hasOpenDirection && adjustOpenCloseCallback) { + success = adjustOpenCloseCallback(device->deviceId, openRelativePercent); + request.response_value[FSTR_OPEN_CLOSE_openPercent] = openRelativePercent; + } } return success; From 4ba2a9dafbd3d48d38716612a01de9451117f609 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Tue, 4 Mar 2025 11:23:26 +0700 Subject: [PATCH 4/5] bugfix: start-stop not working --- src/Capabilities/OpenCloseController.h | 14 +++++++------- src/Capabilities/StartStopController.h | 11 ++++------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Capabilities/OpenCloseController.h b/src/Capabilities/OpenCloseController.h index 0c7ee39a..d04927f6 100644 --- a/src/Capabilities/OpenCloseController.h +++ b/src/Capabilities/OpenCloseController.h @@ -238,15 +238,11 @@ bool OpenCloseController::sendOpenCloseEvent(int openPercent, String cause) { */ template bool OpenCloseController::handleOpenCloseController(SinricProRequest &request) { - if (request.action != FSTR_OPEN_CLOSE_setOpenClose && request.action != FSTR_OPEN_CLOSE_adjustOpenClose) { - return false; - } - T* device = static_cast(this); bool success = false; - if ((directionOpenCloseCallback || openCloseCallback) && request.action == FSTR_OPEN_CLOSE_setOpenClose) { + if (request.action == FSTR_OPEN_CLOSE_setOpenClose) { bool hasOpenDirection = !request.request_value[FSTR_OPEN_CLOSE_openDirection].isNull(); int openPercent = request.request_value[FSTR_OPEN_CLOSE_openPercent]; @@ -259,9 +255,11 @@ bool OpenCloseController::handleOpenCloseController(SinricProRequest &request success = openCloseCallback(device->deviceId, openPercent); request.response_value[FSTR_OPEN_CLOSE_openPercent] = openPercent; } + + return success; } - if ((adjustOpenCloseCallback || adjustDirectionOpenCloseCallback) && request.action == FSTR_OPEN_CLOSE_adjustOpenClose) { + if (request.action == FSTR_OPEN_CLOSE_adjustOpenClose) { bool hasOpenDirection = !request.request_value[FSTR_OPEN_CLOSE_openDirection].isNull(); int openRelativePercent = request.request_value[FSTR_OPEN_CLOSE_openRelativePercent]; @@ -274,9 +272,11 @@ bool OpenCloseController::handleOpenCloseController(SinricProRequest &request success = adjustOpenCloseCallback(device->deviceId, openRelativePercent); request.response_value[FSTR_OPEN_CLOSE_openPercent] = openRelativePercent; } + + return success; } - return success; + return false; } } // SINRICPRO_NAMESPACE diff --git a/src/Capabilities/StartStopController.h b/src/Capabilities/StartStopController.h index 0dd0285b..f4994fdd 100644 --- a/src/Capabilities/StartStopController.h +++ b/src/Capabilities/StartStopController.h @@ -148,10 +148,6 @@ bool StartStopController::sendPauseUnpauseEvent(bool pause, String cause) { template bool StartStopController::handleStartStopController(SinricProRequest &request) { - if (request.action != FSTR_START_STOP_setStartStop || request.action != FSTR_START_STOP_setPauseUnpause) { - return false; - } - T* device = static_cast(this); bool success = false; @@ -162,14 +158,15 @@ bool StartStopController::handleStartStopController(SinricProRequest &request request.response_value[FSTR_START_STOP_start] = start; return success; } - else if (startStopCallbackCallback && request.action == FSTR_START_STOP_setPauseUnpause) { + + if (pauseUnpauseCallback && request.action == FSTR_START_STOP_setPauseUnpause) { bool pause = request.request_value[FSTR_START_STOP_pause]; - success = startStopCallbackCallback(device->deviceId, pause); + success = pauseUnpauseCallback(device->deviceId, pause); request.response_value[FSTR_START_STOP_pause] = pause; return success; } - return success; + return false; } } // SINRICPRO_NAMESPACE From 62540f8d087d5cd49438d6cb0fcb613d471474d1 Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Wed, 5 Mar 2025 00:25:45 +0700 Subject: [PATCH 5/5] chore: version update and fix formatting --- changelog.md | 7 ++----- library.json | 36 +++++++++++++----------------------- library.properties | 2 +- src/SinricProVersion.h | 2 +- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/changelog.md b/changelog.md index e63cbec0..fb09ad30 100644 --- a/changelog.md +++ b/changelog.md @@ -1,11 +1,8 @@ # Changelog -## Version 3.5.1 - Fixed: - - Logging messages. - +## Version 3.5.0 New: - - Support Start/Stop Controller for custom device types + - Support Start/Stop and Open/Close capabilities. ## Version 3.4.1 Fixed: diff --git a/library.json b/library.json index eb8ad433..e09adc5b 100644 --- a/library.json +++ b/library.json @@ -1,48 +1,38 @@ { "name": "SinricPro", - "keywords": "ethernet, sinric, alexa, iot", - "description": "Library for https://sinric.pro - simple way to connect your device to alexa", + "keywords": "sinric, alexa, google home, iot", + "description": "Library for https://sinric.pro - simple way to connect your device to alexa and google home", "repository": { "type": "git", "url": "https://github.com/sinricpro/esp8266-esp32-sdk" }, "authors": [ + { + "name": "SinricPro", + "url": "https://sinric.pro" + }, { "name": "Boris Jaeger", "email": "sivar2311@gmail.com", "maintainer": true } ], - "version": "3.5.1", + "homepage": "https://sinric.pro", + "version": "3.5.0", "frameworks": "arduino", - "platforms": [ - "espressif8266", - "espressif32", - "raspberrypi" - ], + "platforms": ["espressif8266", "espressif32", "raspberrypi"], "dependencies": [ { "name": "ArduinoJson", "version": "^7.0.3", - "platforms": [ - "espressif32", - "espressif8266", - "raspberrypi" - ] + "platforms": ["espressif32", "espressif8266", "raspberrypi"] }, { "name": "WebSockets", "version": "^2.4.0", - "platforms": [ - "espressif32", - "espressif8266", - "raspberrypi" - ] + "platforms": ["espressif32", "espressif8266", "raspberrypi"] } ], - "examples": [ - "examples/*/*.ino", - "examples/*/*/*.ino" - ], + "examples": ["examples/*/*.ino", "examples/*/*/*.ino"], "license": "CC-BY-SA-4.0" -} \ No newline at end of file +} diff --git a/library.properties b/library.properties index d3cff445..6e91728a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SinricPro -version=3.5.1 +version=3.5.0 author=Boris Jaeger maintainer=Boris Jaeger sentence=Library for https://sinric.pro - simple way to connect your device to alexa diff --git a/src/SinricProVersion.h b/src/SinricProVersion.h index 7f6b1d0a..6659c3e8 100644 --- a/src/SinricProVersion.h +++ b/src/SinricProVersion.h @@ -6,7 +6,7 @@ // Version Configuration #define SINRICPRO_VERSION_MAJOR 3 #define SINRICPRO_VERSION_MINOR 5 -#define SINRICPRO_VERSION_REVISION 1 +#define SINRICPRO_VERSION_REVISION 0 #define SINRICPRO_VERSION STR(SINRICPRO_VERSION_MAJOR) "." STR(SINRICPRO_VERSION_MINOR) "." STR(SINRICPRO_VERSION_REVISION) #define SINRICPRO_VERSION_STR "SinricPro (v" SINRICPRO_VERSION ")" #define SINRICPRO_VERISON_INT SINRICPRO_VERSION_MAJOR * 1000000 + SINRICPRO_VERSION_MINOR * 1000 + SINRICPRO_VERSION_REVISION \ No newline at end of file