From 3c0b359764cc8a3376b765a2f58a3e86c3c95501 Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Sun, 23 May 2021 15:33:02 +0200 Subject: [PATCH 01/20] #713 first import --- sources/plugins/PhilipsHue/CMakeLists.txt | 84 ++++++---- .../PhilipsHue/Devices/Interfaces/ILight.h | 20 +++ .../Devices/Interfaces/ILightsService.h | 16 ++ .../Devices/Lights/Models/LCT015.cpp | 91 +++++++++++ .../PhilipsHue/Devices/Lights/Models/LCT015.h | 30 ++++ .../Lights/Service/LightsService.cpp} | 111 +++---------- .../Lights/Service/LightsService.h} | 28 ++-- .../{ => Devices/Utils}/ColorConverter.cpp | 0 .../{ => Devices/Utils}/ColorConverter.h | 6 +- .../Utils}/HueLightsResponseType.cpp | 0 .../Utils}/HueLightsResponseType.h | 0 .../PhilipsHue/Devices/Utils/LightType.cpp | 29 ++++ .../PhilipsHue/Devices/Utils/LightType.h | 29 ++++ .../Entities/HueLightInformations.cpp | 103 +++++++++++- .../Entities/HueLightInformations.h | 5 +- sources/plugins/PhilipsHue/Factory.cpp | 26 ++- sources/plugins/PhilipsHue/Factory.h | 7 +- .../plugins/PhilipsHue/HueBridgeDiscovery.cpp | 2 +- sources/plugins/PhilipsHue/ILightManager.h | 24 --- sources/plugins/PhilipsHue/PhilipsHue.cpp | 151 +++++++++--------- sources/plugins/PhilipsHue/PhilipsHue.h | 10 +- sources/plugins/PhilipsHue/changelog.md | 2 + 22 files changed, 520 insertions(+), 254 deletions(-) create mode 100644 sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h create mode 100644 sources/plugins/PhilipsHue/Devices/Interfaces/ILightsService.h create mode 100644 sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp create mode 100644 sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h rename sources/plugins/PhilipsHue/{LightManager.cpp => Devices/Lights/Service/LightsService.cpp} (89%) rename sources/plugins/PhilipsHue/{LightManager.h => Devices/Lights/Service/LightsService.h} (74%) rename sources/plugins/PhilipsHue/{ => Devices/Utils}/ColorConverter.cpp (100%) rename sources/plugins/PhilipsHue/{ => Devices/Utils}/ColorConverter.h (78%) rename sources/plugins/PhilipsHue/{ => Devices/Utils}/HueLightsResponseType.cpp (100%) rename sources/plugins/PhilipsHue/{ => Devices/Utils}/HueLightsResponseType.h (100%) create mode 100644 sources/plugins/PhilipsHue/Devices/Utils/LightType.cpp create mode 100644 sources/plugins/PhilipsHue/Devices/Utils/LightType.h delete mode 100644 sources/plugins/PhilipsHue/ILightManager.h diff --git a/sources/plugins/PhilipsHue/CMakeLists.txt b/sources/plugins/PhilipsHue/CMakeLists.txt index e140762450..58102c5238 100644 --- a/sources/plugins/PhilipsHue/CMakeLists.txt +++ b/sources/plugins/PhilipsHue/CMakeLists.txt @@ -5,64 +5,85 @@ include("../YadomsPluginsCommon.cmake") ## Place here all the plugin source files ######################################### set(PHILIPS_HUE_PLUGIN_SOURCES - stdafx.h stdafx.cpp - PhilipsHue.h PhilipsHue.cpp - Configuration.h Configuration.cpp - HueBridgeDiscovery.h HueBridgeDiscovery.cpp + HueService.cpp + Factory.cpp + UrlManager.cpp + Entities/HueInformations.cpp + Entities/Rgb.cpp + Entities/Hsv.cpp + Entities/Xy.cpp + Entities/HueLightInformations.cpp + Entities/HueState.cpp + Entities/HueSwUpdate.cpp + Entities/HueCapabilities.cpp + Entities/HueControl.cpp + Entities/HueColorGamut.cpp + Entities/HueCt.cpp + Entities/HueStreaming.cpp + Entities/HueConfig.cpp + Entities/HueStartUp.cpp + stdafx.h + PhilipsHue.h + Configuration.h + HueBridgeDiscovery.h IHueBridgeDiscovery.h HueService.h - HueService.cpp Factory.h - Factory.cpp IHueService.h UrlManager.h - UrlManager.cpp - LightManager.h - LightManager.cpp - ILightManager.h - ColorConverter.h - ColorConverter.cpp Entities/HueInformations.h - Entities/HueInformations.cpp Entities/Rgb.h - Entities/Rgb.cpp Entities/Hsv.h - Entities/Hsv.cpp Entities/Xy.h - Entities/Xy.cpp Entities/HueLightInformations.h - Entities/HueLightInformations.cpp Entities/HueState.h - Entities/HueState.cpp Entities/HueSwUpdate.h - Entities/HueSwUpdate.cpp Entities/HueCapabilities.h - Entities/HueCapabilities.cpp Entities/HueControl.h - Entities/HueControl.cpp Entities/HueColorGamut.h - Entities/HueColorGamut.cpp Entities/HueCt.h - Entities/HueCt.cpp Entities/HueStreaming.h - Entities/HueStreaming.cpp Entities/HueConfig.h - Entities/HueConfig.cpp Entities/HueStartUp.h - Entities/HueStartUp.cpp - HueLightsResponseType.h - HueLightsResponseType.cpp +) + +set(PHILIPS_HUE_PLUGIN_LIGHTS_MODELS_SOURCES + Devices/Lights/Models/LCT015.cpp + Devices/Lights/Models/LCT015.h +) + +set(PHILIPS_HUE_PLUGIN_LIGHTS_SERVICE_SOURCES + Devices/Lights/Service/LightsService.h + Devices/Lights/Service/LightsService.cpp +) + +set(PHILIPS_HUE_PLUGIN_DEVICES_INTERFACES_SOURCES + Devices/Interfaces/ILightsService.h + Devices/Interfaces/ILight.h +) + +set(PHILIPS_HUE_PLUGIN_DEVICES_UTILS_SOURCES + Devices/Utils/HueLightsResponseType.cpp + Devices/Utils/HueLightsResponseType.h + Devices/Utils/ColorConverter.h + Devices/Utils/ColorConverter.cpp + Devices/Utils/LightType.cpp + Devices/Utils/LightType.h ) ######################################### ## Place here all additional groups (solution folder) ######################################### -source_group(sources ./*.*) source_group(sources\\Entities Entities/*.*) +source_group(sources\\Devices\\Lights\\Models FILES ${PHILIPS_HUE_PLUGIN_LIGHTS_MODELS_SOURCES}) +source_group(sources\\Devices\\Lights\\Service FILES ${PHILIPS_HUE_PLUGIN_LIGHTS_SERVICE_SOURCES}) +source_group(sources\\Devices\\Interfaces FILES ${PHILIPS_HUE_PLUGIN_DEVICES_INTERFACES_SOURCES}) +source_group(sources\\Devices\\Utils FILES ${PHILIPS_HUE_PLUGIN_DEVICES_UTILS_SOURCES}) +source_group(sources ./*.*) ######################################### ## Place here all additional include directories @@ -88,7 +109,6 @@ set(PHILIPS_HUE_PLUGIN_LINK ## Always leave these lines to configure plugin correctly ## even if EMPTY_PLUGIN_INCLDIR or EMPTY_PLUGIN_LINK are empty ######################################### -PLUGIN_SOURCES(PhilipsHue ${PHILIPS_HUE_PLUGIN_SOURCES}) +PLUGIN_SOURCES(PhilipsHue ${PHILIPS_HUE_PLUGIN_SOURCES} ${PHILIPS_HUE_PLUGIN_LIGHTS_MODELS_SOURCES} ${PHILIPS_HUE_PLUGIN_LIGHTS_SERVICE_SOURCES} ${PHILIPS_HUE_PLUGIN_DEVICES_INTERFACES_SOURCES} ${PHILIPS_HUE_PLUGIN_DEVICES_UTILS_SOURCES}) PLUGIN_INCLDIR(PhilipsHue ${PHILIPS_HUE_PLUGIN_ADDITIONAL_INC_DIR}) -PLUGIN_LINK(PhilipsHue ${PHILIPS_HUE_PLUGIN_ADDITIONAL_LIB}) - +PLUGIN_LINK(PhilipsHue ${PHILIPS_HUE_PLUGIN_ADDITIONAL_LIB}) \ No newline at end of file diff --git a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h new file mode 100644 index 0000000000..ab16c46fe5 --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h @@ -0,0 +1,20 @@ +#pragma once +#include "../../Entities/HueLightInformations.h" +#include "shared/plugin/yPluginApi/historization/IHistorizable.h" + +class ILight +{ +public: + virtual ~ILight() = default; + + virtual void setLightId(std::string& lightName, std::map& detectedLights) = 0; + + virtual void lightOn() = 0; + + virtual void lightOff() = 0; + + virtual void setLightColorUsingXy(const std::string& hexRgb) = 0; + + virtual std::vector> + getHistorizables() = 0; +}; diff --git a/sources/plugins/PhilipsHue/Devices/Interfaces/ILightsService.h b/sources/plugins/PhilipsHue/Devices/Interfaces/ILightsService.h new file mode 100644 index 0000000000..1137762f1c --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Interfaces/ILightsService.h @@ -0,0 +1,16 @@ +#pragma once +#include "../../Entities/HueLightInformations.h" + +class ILightsService +{ +public: + virtual ~ILightsService() = default; + + virtual std::map getAllLights() = 0; + + virtual CHueLightInformations getLightAttributesAndState(int id) = 0; + + virtual void searchForNewLights() = 0; + + virtual std::map getNewLights() = 0; +}; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp new file mode 100644 index 0000000000..95c06778fa --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp @@ -0,0 +1,91 @@ +#include "LCT015.h" +#include "../../Utils/ColorConverter.h" +#include "shared/http/HttpRestHelpers.h" +#include "shared/Log.h" + +const std::string CLct015::LightState("STATE"); +const std::string CLct015::RgbColor("RgbColor"); + +CLct015::CLct015(boost::shared_ptr& urlManager, int& lightId) + : m_urlManager(urlManager), + m_lightId(lightId), m_switch(boost::make_shared(LightState)), + m_rgb(boost::make_shared( + RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), + m_historizables({m_switch, m_rgb}) +{ +} + +void CLct015::setLightId(std::string& lightName, std::map& detectedLights) +{ + const auto it = std::find_if(std::begin(detectedLights), std::end(detectedLights), + [&lightName](auto&& pair) + { + return pair.second.getName() == lightName; + }); + + if (it == std::end(detectedLights)) + { + YADOMS_LOG(warning) << "Light not found"; + throw std::runtime_error("Light ID is not found"); + } + YADOMS_LOG(information) << "Light ID = " << m_lightId << " is found "; + m_lightId = it->first; +} + +void CLct015::lightOn() +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightId); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("on", true); + setLightState(lightUrl, body); +} + + +void CLct015::lightOff() +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightId); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("on", false); + setLightState(lightUrl, body); +} + +void CLct015::setLightColorUsingXy(const std::string& hexRgb) +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightId); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + auto rgb = CColorConverter::hexToRgb(hexRgb); + const auto xy = CColorConverter::rgbToXy(rgb); + + shared::CDataContainer body; + body.set("on", true); + body.set("xy.0", xy.getX()); + body.set("xy.1", xy.getY()); + + setLightState(lightUrl, body); +} + +std::vector> CLct015::getHistorizables() +{ + return m_historizables; +} + +void CLct015::setLightState(const std::string& lightUrl, shared::CDataContainer& body) +{ + try + { + const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); + } + catch (std::exception& e) + { + const auto message = (boost::format("Fail to send Get http request or interpret answer \"%1%\" : %2%") % lightUrl + % + e.what()).str(); + YADOMS_LOG(error) << "Fail to send Get http request or interpret answer " << lightUrl << " : " << e.what(); + throw; + } +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h new file mode 100644 index 0000000000..cb8378467b --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h @@ -0,0 +1,30 @@ +#pragma once +#include "../../../UrlManager.h" +#include "../../Interfaces/ILight.h" +#include + +class CLct015 : public ILight +{ +public: + + CLct015(boost::shared_ptr& urlManager, int& lightId); + virtual ~CLct015() = default; + + void lightOn() override; + + void lightOff() override; + + void setLightColorUsingXy(const std::string& hexRgb) override; + + std::vector> getHistorizables(); +private : + static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); + void setLightId(std::string& lightName, std::map& detectedLights); + boost::shared_ptr& m_urlManager; + int m_lightId; + static const std::string LightState; + static const std::string RgbColor; + boost::shared_ptr m_switch; + boost::shared_ptr m_rgb; + std::vector> m_historizables; +}; diff --git a/sources/plugins/PhilipsHue/LightManager.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp similarity index 89% rename from sources/plugins/PhilipsHue/LightManager.cpp rename to sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp index b8ee14afe2..d29276e791 100644 --- a/sources/plugins/PhilipsHue/LightManager.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp @@ -1,16 +1,15 @@ -#include "LightManager.h" +#include "LightsService.h" #include "shared/Log.h" #include "shared/http/HttpRestHelpers.h" -#include "ColorConverter.h" -#include "Entities/HueStreaming.h" +#include "../../Utils/ColorConverter.h" +#include "../../../Entities/HueStreaming.h" -CLightManager::CLightManager(boost::shared_ptr& urlManager) - : m_urlManager(urlManager), - m_lightId(0) +CLightsService::CLightsService(boost::shared_ptr& urlManager) + : m_urlManager(urlManager) { } -std::map CLightManager::getAllLights() +std::map CLightsService::getAllLights() { std::map hueLightsInformations; const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kGetAllLights); @@ -135,7 +134,7 @@ std::map CLightManager::getAllLights() return hueLightsInformations; } -CHueLightInformations CLightManager::getLightAttributesAndState(const int id) +CHueLightInformations CLightsService::getLightAttributesAndState(const int id) { CHueLightInformations hueLightAttributesAndState; const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kGetLightAttributesAndState, id); @@ -236,7 +235,7 @@ CHueLightInformations CLightManager::getLightAttributesAndState(const int id) return hueLightAttributesAndState; } -CHueState CLightManager::getHueLightInformationsState(boost::shared_ptr& response) +CHueState CLightsService::getHueLightInformationsState(boost::shared_ptr& response) { CHueState state; if (response->exists(EHueLightResponseType::kStateOn.toString()) && !response @@ -321,7 +320,7 @@ CHueState CLightManager::getHueLightInformationsState(boost::shared_ptr& response) +CHueSwUpdate CLightsService::getHueLightInformationsSwUpdate(boost::shared_ptr& response) { CHueSwUpdate swUpdate; if (response->exists(EHueLightResponseType::kSwUpdateState.toString()) && !response @@ -339,7 +338,7 @@ CHueSwUpdate CLightManager::getHueLightInformationsSwUpdate(boost::shared_ptr& response) +CHueCapabilities CLightsService::getHueLightInformationsCapabilities(boost::shared_ptr& response) { CHueCapabilities capabilities; if (response->exists(EHueLightResponseType::kCapabilitiesCertified.toString()) && !response @@ -404,7 +403,7 @@ CHueCapabilities CLightManager::getHueLightInformationsCapabilities(boost::share return capabilities; } -CHueConfig CLightManager::getHueLightInformationsConfig(boost::shared_ptr& response) +CHueConfig CLightsService::getHueLightInformationsConfig(boost::shared_ptr& response) { CHueConfig config; if (response->exists(EHueLightResponseType::kConfigArchetype.toString()) && !response @@ -445,7 +444,7 @@ CHueConfig CLightManager::getHueLightInformationsConfig(boost::shared_ptr& response) { CHueState state; @@ -562,7 +561,7 @@ CHueState CLightManager::getHueLightInformationsStateById(int& lightId, return state; } -CHueSwUpdate CLightManager::getHueLightInformationsSwUpdateById(int& lightId, +CHueSwUpdate CLightsService::getHueLightInformationsSwUpdateById(int& lightId, boost::shared_ptr& response) { CHueSwUpdate swUpdate; @@ -586,7 +585,7 @@ CHueSwUpdate CLightManager::getHueLightInformationsSwUpdateById(int& lightId, return swUpdate; } -CHueCapabilities CLightManager::getHueLightInformationsCapabilitiesById(int& lightId, +CHueCapabilities CLightsService::getHueLightInformationsCapabilitiesById(int& lightId, boost::shared_ptr& response) { @@ -684,7 +683,7 @@ CHueCapabilities CLightManager::getHueLightInformationsCapabilitiesById(int& lig return capabilities; } -CHueConfig CLightManager::getHueLightInformationsConfigById(int& lightId, +CHueConfig CLightsService::getHueLightInformationsConfigById(int& lightId, boost::shared_ptr& response) { CHueConfig config; @@ -738,23 +737,8 @@ CHueConfig CLightManager::getHueLightInformationsConfigById(int& lightId, return config; } -void CLightManager::setLightState(const std::string& lightUrl, shared::CDataContainer& body) -{ - try - { - const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); - } - catch (std::exception& e) - { - const auto message = (boost::format("Fail to send Get http request or interpret answer \"%1%\" : %2%") % lightUrl - % - e.what()).str(); - YADOMS_LOG(error) << "Fail to send Get http request or interpret answer " << lightUrl << " : " << e.what(); - throw; - } -} -void CLightManager::setNewLights(const boost::system::error_code& errorCode) +void CLightsService::setNewLights(const boost::system::error_code& errorCode) { // boost::asio::error::operation_aborted : Normal behaviour-Invoked when we cancelled the timer if (errorCode && errorCode != boost::asio::error::operation_aborted) @@ -764,61 +748,8 @@ void CLightManager::setNewLights(const boost::system::error_code& errorCode) closeReadingNewLights(); } -void CLightManager::setLightId(std::string& lightName, std::map& detectedLights) -{ - const auto it = std::find_if(std::begin(detectedLights), std::end(detectedLights), - [&lightName](auto&& pair) - { - return pair.second.getName() == lightName; - }); - - if (it == std::end(detectedLights)) - { - YADOMS_LOG(warning) << "Light not found"; - throw std::runtime_error("Light ID is not found"); - } - YADOMS_LOG(information) << "Light ID = " << m_lightId << " is found "; - m_lightId = it->first; -} - -void CLightManager::lightOn() -{ - const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightId); - const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); - - shared::CDataContainer body; - body.set("on", true); - setLightState(lightUrl, body); -} - - -void CLightManager::lightOff() -{ - const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightId); - const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); - - shared::CDataContainer body; - body.set("on", false); - setLightState(lightUrl, body); -} - -void CLightManager::setLightColorUsingXy(const std::string& hexRgb) -{ - const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightId); - const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); - - auto rgb = CColorConverter::hexToRgb(hexRgb); - const auto xy = CColorConverter::rgbToXy(rgb); - - shared::CDataContainer body; - body.set("on", true); - body.set("xy.0", xy.getX()); - body.set("xy.1", xy.getY()); - - setLightState(lightUrl, body); -} -void CLightManager::searchForNewLights() +void CLightsService::searchForNewLights() { const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kGetAllLights); const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); @@ -840,21 +771,21 @@ void CLightManager::searchForNewLights() } } -std::map CLightManager::getNewLights() +std::map CLightsService::getNewLights() { return m_newLights; } -void CLightManager::startReadingNewLights() +void CLightsService::startReadingNewLights() { boost::asio::steady_timer timer(m_ios, boost::asio::chrono::seconds(40)); - timer.async_wait(boost::bind(&CLightManager::setNewLights, this, + timer.async_wait(boost::bind(&CLightsService::setNewLights, this, boost::asio::placeholders::error)); m_ios.run(); } -void CLightManager::closeReadingNewLights() +void CLightsService::closeReadingNewLights() { m_ios.stop(); } diff --git a/sources/plugins/PhilipsHue/LightManager.h b/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.h similarity index 74% rename from sources/plugins/PhilipsHue/LightManager.h rename to sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.h index d81b9f81c9..ca4c44ee9a 100644 --- a/sources/plugins/PhilipsHue/LightManager.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.h @@ -1,26 +1,23 @@ #pragma once -#include "UrlManager.h" -#include "ILightManager.h" -#include "HueLightsResponseType.h" -class CLightManager : public ILightManager +#include "../../Utils/HueLightsResponseType.h" +#include "../../../Entities/HueState.h" +#include "../../../Entities/HueSwUpdate.h" +#include "../../../Entities/HueCapabilities.h" +#include "../../../Entities/HueConfig.h" +#include "../../../UrlManager.h" +#include "../../Interfaces/ILightsService.h" + +class CLightsService : public ILightsService { public: - explicit CLightManager(boost::shared_ptr& urlManager); - virtual ~CLightManager() = default; + explicit CLightsService(boost::shared_ptr& urlManager); + virtual ~CLightsService() = default; std::map getAllLights() override; CHueLightInformations getLightAttributesAndState(int id) override; - void setLightId(std::string& lightName, std::map& detectedLights) override; - - void lightOn() override; - - void lightOff() override; - - void setLightColorUsingXy(const std::string& hexRgb) override; - void searchForNewLights() override; std::map getNewLights() override; @@ -39,14 +36,11 @@ class CLightManager : public ILightManager static CHueConfig getHueLightInformationsConfigById(int& lightId, boost::shared_ptr& response); - static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); - void setNewLights(const boost::system::error_code& errorCode); void startReadingNewLights(); void closeReadingNewLights(); boost::shared_ptr& m_urlManager; - int m_lightId; std::map m_newLights; boost::asio::io_service m_ios; diff --git a/sources/plugins/PhilipsHue/ColorConverter.cpp b/sources/plugins/PhilipsHue/Devices/Utils/ColorConverter.cpp similarity index 100% rename from sources/plugins/PhilipsHue/ColorConverter.cpp rename to sources/plugins/PhilipsHue/Devices/Utils/ColorConverter.cpp diff --git a/sources/plugins/PhilipsHue/ColorConverter.h b/sources/plugins/PhilipsHue/Devices/Utils/ColorConverter.h similarity index 78% rename from sources/plugins/PhilipsHue/ColorConverter.h rename to sources/plugins/PhilipsHue/Devices/Utils/ColorConverter.h index fc5b7db8b9..d23b78644a 100644 --- a/sources/plugins/PhilipsHue/ColorConverter.h +++ b/sources/plugins/PhilipsHue/Devices/Utils/ColorConverter.h @@ -1,8 +1,8 @@ #pragma once #include -#include "Entities/Rgb.h" -#include "Entities/Hsv.h" -#include "Entities/Xy.h" +#include "../../Entities/Rgb.h" +#include "../../Entities/Hsv.h" +#include "../../Entities/Xy.h" #define MIN_F(a, b, c) (fminf(a, fminf(b, c))) #define MAX_F(a, b, c) (fmaxf(a, fmaxf(b, c))) diff --git a/sources/plugins/PhilipsHue/HueLightsResponseType.cpp b/sources/plugins/PhilipsHue/Devices/Utils/HueLightsResponseType.cpp similarity index 100% rename from sources/plugins/PhilipsHue/HueLightsResponseType.cpp rename to sources/plugins/PhilipsHue/Devices/Utils/HueLightsResponseType.cpp diff --git a/sources/plugins/PhilipsHue/HueLightsResponseType.h b/sources/plugins/PhilipsHue/Devices/Utils/HueLightsResponseType.h similarity index 100% rename from sources/plugins/PhilipsHue/HueLightsResponseType.h rename to sources/plugins/PhilipsHue/Devices/Utils/HueLightsResponseType.h diff --git a/sources/plugins/PhilipsHue/Devices/Utils/LightType.cpp b/sources/plugins/PhilipsHue/Devices/Utils/LightType.cpp new file mode 100644 index 0000000000..399b6895e9 --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Utils/LightType.cpp @@ -0,0 +1,29 @@ +#include "LightType.h" + +DECLARE_ENUM_IMPLEMENTATION(ELightType, + ((LCT001)("LCT001")) + ((LCT002)("LCT002")) + ((LCT003)("LCT003")) + ((LCT007)("LCT007")) + ((LLM001)("LLM001")) + ((LCT010)("LCT010")) + ((LCT011)("LCT011")) + ((LCT012)("LCT012")) + ((LCT014)("LCT014")) + ((LCT015)("LCT015")) + ((LCT016)("LCT016")) + ((LLC020)("LLC020")) + ((LST002)("LST002")) + ((LCA003)("LCA003")) + ((LCB001)("LCB001")) + ((LST001)("LST001")) + ((LLC005)("LLC005")) + ((LLC006)("LLC006")) + ((LLC007)("LLC007")) + ((LLC010)("LLC010")) + ((LLC011)("LLC011")) + ((LLC012)("LLC012")) + ((LLC013)("LLC013")) + ((LLC014)("LLC014")) + ((Other)("Other")) +) diff --git a/sources/plugins/PhilipsHue/Devices/Utils/LightType.h b/sources/plugins/PhilipsHue/Devices/Utils/LightType.h new file mode 100644 index 0000000000..e533487cf7 --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Utils/LightType.h @@ -0,0 +1,29 @@ +#pragma once +#include +DECLARE_ENUM_HEADER(ELightType, + ((LCT001)) + ((LCT002)) + ((LCT003)) + ((LCT007)) + ((LLM001)) + ((LCT010)) + ((LCT011)) + ((LCT012)) + ((LCT014)) + ((LCT015)) + ((LCT016)) + ((LLC020)) + ((LST002)) + ((LCA003)) + ((LCB001)) + ((LST001)) + ((LLC005)) + ((LLC006)) + ((LLC007)) + ((LLC010)) + ((LLC011)) + ((LLC012)) + ((LLC013)) + ((LLC014)) + ((Other)) +) diff --git a/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp b/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp index 9bf3662849..3477ba3349 100644 --- a/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp +++ b/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp @@ -20,7 +20,7 @@ const std::string& CHueLightInformations::getName() const return m_name; } -const std::string& CHueLightInformations::getModelId() const +const ELightType& CHueLightInformations::getModelId() const { return m_modelId; } @@ -87,7 +87,106 @@ void CHueLightInformations::setName(const std::string& name) void CHueLightInformations::setModelId(const std::string& modelId) { - m_modelId = modelId; + if (modelId == ELightType::kLCT001.toString()) + { + m_modelId = ELightType::kLCT001; + } + else if (modelId == ELightType::kLCT002.toString()) + { + m_modelId = ELightType::kLCT002; + } + else if (modelId == ELightType::kLCT003.toString()) + { + m_modelId = ELightType::kLCT003; + } + else if (modelId == ELightType::kLCT007.toString()) + { + m_modelId = ELightType::kLCT007; + } + else if (modelId == ELightType::kLLM001.toString()) + { + m_modelId = ELightType::kLLM001; + } + else if (modelId == ELightType::kLCT010.toString()) + { + m_modelId = ELightType::kLCT010; + } + else if (modelId == ELightType::kLCT011.toString()) + { + m_modelId = ELightType::kLCT011; + } + else if (modelId == ELightType::kLCT012.toString()) + { + m_modelId = ELightType::kLCT012; + } + else if (modelId == ELightType::kLCT014.toString()) + { + m_modelId = ELightType::kLCT014; + } + else if (modelId == ELightType::kLCT015.toString()) + { + m_modelId = ELightType::kLCT015; + } + else if (modelId == ELightType::kLCT016.toString()) + { + m_modelId = ELightType::kLCT016; + } + else if (modelId == ELightType::kLLC020.toString()) + { + m_modelId = ELightType::kLLC020; + } + else if (modelId == ELightType::kLST002.toString()) + { + m_modelId = ELightType::kLST002; + } + else if (modelId == ELightType::kLCA003.toString()) + { + m_modelId = ELightType::kLCA003; + } + else if (modelId == ELightType::kLCB001.toString()) + { + m_modelId = ELightType::kLCB001; + } + else if (modelId == ELightType::kLST001.toString()) + { + m_modelId = ELightType::kLST001; + } + else if (modelId == ELightType::kLLC005.toString()) + { + m_modelId = ELightType::kLLC005; + } + else if (modelId == ELightType::kLLC006.toString()) + { + m_modelId = ELightType::kLLC006; + } + else if (modelId == ELightType::kLLC007.toString()) + { + m_modelId = ELightType::kLLC007; + } + else if (modelId == ELightType::kLLC010.toString()) + { + m_modelId = ELightType::kLLC010; + } + else if (modelId == ELightType::kLLC011.toString()) + { + m_modelId = ELightType::kLLC011; + } + else if (modelId == ELightType::kLLC012.toString()) + { + m_modelId = ELightType::kLLC012; + } + else if (modelId == ELightType::kLLC013.toString()) + { + m_modelId = ELightType::kLLC013; + } + else if (modelId == ELightType::kLLC014.toString()) + { + m_modelId = ELightType::kLLC014; + } + else + { + m_modelId = ELightType::kOther; + } } void CHueLightInformations::setManufacturerName(const std::string& manufacturerName) diff --git a/sources/plugins/PhilipsHue/Entities/HueLightInformations.h b/sources/plugins/PhilipsHue/Entities/HueLightInformations.h index c619e8df19..ff7dc82a78 100644 --- a/sources/plugins/PhilipsHue/Entities/HueLightInformations.h +++ b/sources/plugins/PhilipsHue/Entities/HueLightInformations.h @@ -3,6 +3,7 @@ #include "HueSwUpdate.h" #include "HueCapabilities.h" #include "HueConfig.h" +#include "../Devices/Utils/LightType.h" class CHueLightInformations { @@ -16,7 +17,7 @@ class CHueLightInformations const CHueSwUpdate& getSwUpdate() const; const std::string& getType() const; const std::string& getName() const; - const std::string& getModelId() const; + const ELightType& getModelId() const; const std::string& getManufacturerName() const; const std::string& getProductName() const; const CHueCapabilities& getCapabilities() const; @@ -45,7 +46,7 @@ class CHueLightInformations CHueSwUpdate m_swUpdate; std::string m_type; std::string m_name; - std::string m_modelId; + ELightType m_modelId; std::string m_manufacturerName; std::string m_productName; CHueCapabilities m_capabilities; diff --git a/sources/plugins/PhilipsHue/Factory.cpp b/sources/plugins/PhilipsHue/Factory.cpp index 5420f7f9ee..8dbc05c1b5 100644 --- a/sources/plugins/PhilipsHue/Factory.cpp +++ b/sources/plugins/PhilipsHue/Factory.cpp @@ -1,7 +1,10 @@ #include "Factory.h" #include "HueService.h" #include "HueBridgeDiscovery.h" -#include "LightManager.h" +#include "Devices/Interfaces/ILightsService.h" +#include "Devices/Lights/Service//LightsService.h" +#include "Devices/Utils/LightType.h" +#include "Devices/Lights/Models/LCT015.h" boost::shared_ptr CFactory::createHueService(shared::event::CEventHandler& mainEventHandler, int evtKeyStateReceived, @@ -18,12 +21,29 @@ boost::shared_ptr CFactory::createHueBridgeDiscovery(boost: { return boost::make_shared(urlManager); } + boost::shared_ptr CFactory::createHueBridgeDiscovery() { return boost::make_shared(); } -boost::shared_ptr CFactory::createLightManager(boost::shared_ptr& urlManager) +boost::shared_ptr CFactory::createLightsService(boost::shared_ptr& urlManager) +{ + return boost::make_shared(urlManager); +} + +boost::shared_ptr CFactory::createLight(boost::shared_ptr& urlManager, + CHueLightInformations& lightInformations) { - return boost::make_shared(urlManager); + boost::shared_ptr light = nullptr; + int id = 1; + switch (lightInformations.getModelId()) + { + case ELightType::kLCT015Value: + light = boost::make_shared(urlManager, id); + break; + default: + break; + } + return light; } diff --git a/sources/plugins/PhilipsHue/Factory.h b/sources/plugins/PhilipsHue/Factory.h index 321a65c5d2..8d0bdac922 100644 --- a/sources/plugins/PhilipsHue/Factory.h +++ b/sources/plugins/PhilipsHue/Factory.h @@ -3,7 +3,8 @@ #include "shared/event/EventHandler.hpp" #include "UrlManager.h" #include "IHueBridgeDiscovery.h" -#include "ILightManager.h" +#include "Devices/Interfaces/ILightsService.h" +#include "Devices/Interfaces/ILight.h" class CFactory { @@ -18,5 +19,7 @@ class CFactory static boost::shared_ptr createHueBridgeDiscovery(boost::shared_ptr& urlManager); static boost::shared_ptr createHueBridgeDiscovery(); - static boost::shared_ptr createLightManager(boost::shared_ptr& urlManager); + static boost::shared_ptr createLightsService(boost::shared_ptr& urlManager); + static boost::shared_ptr createLight(boost::shared_ptr& urlManager, + CHueLightInformations& lightInformations); }; diff --git a/sources/plugins/PhilipsHue/HueBridgeDiscovery.cpp b/sources/plugins/PhilipsHue/HueBridgeDiscovery.cpp index e965c2a78d..dc59442b78 100644 --- a/sources/plugins/PhilipsHue/HueBridgeDiscovery.cpp +++ b/sources/plugins/PhilipsHue/HueBridgeDiscovery.cpp @@ -16,7 +16,7 @@ CHueBridgeDiscovery::CHueBridgeDiscovery() std::vector CHueBridgeDiscovery::FindBridges() { auto foundBridges = shared::http::ssdp:: - CDiscoverService::discover("service:hue", std::chrono::seconds(30)); + CDiscoverService::discover("service:hue", std::chrono::seconds(60)); if (foundBridges.empty()) { diff --git a/sources/plugins/PhilipsHue/ILightManager.h b/sources/plugins/PhilipsHue/ILightManager.h deleted file mode 100644 index bd2ef2775c..0000000000 --- a/sources/plugins/PhilipsHue/ILightManager.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "Entities/HueLightInformations.h" - -class ILightManager -{ -public: - virtual ~ILightManager() = default; - - virtual std::map getAllLights() = 0; - - virtual CHueLightInformations getLightAttributesAndState(int id) = 0; - - virtual void setLightId(std::string& lightName, std::map& detectedLights) = 0; - - virtual void lightOn() = 0; - - virtual void lightOff() = 0; - - virtual void setLightColorUsingXy(const std::string& hexRgb) = 0; - - virtual void searchForNewLights() = 0; - - virtual std::map getNewLights() = 0; -}; diff --git a/sources/plugins/PhilipsHue/PhilipsHue.cpp b/sources/plugins/PhilipsHue/PhilipsHue.cpp index f47865f499..a9205c09ef 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.cpp +++ b/sources/plugins/PhilipsHue/PhilipsHue.cpp @@ -4,7 +4,7 @@ #include #include "shared/http/ssdp/DiscoverService.h" #include "Factory.h" -#include "ColorConverter.h" +#include "Devices/Utils/ColorConverter.h" IMPLEMENT_PLUGIN(CPhilipsHue) @@ -72,47 +72,47 @@ void CPhilipsHue::doWork(boost::shared_ptr api) YADOMS_LOG(information) << "Command received from Yadoms : " << yApi::IDeviceCommand::toString(command); auto lightName = command->getDevice(); - if (m_configuration.getPairingMode() == kAuto) - { - const auto deviceDetails = m_api->getDeviceDetails(lightName); - const auto bridgeId = std::stoi(deviceDetails->get("bridgeId")); - - m_lightManagers[bridgeId]->setLightId(lightName, m_detectedLightsByBridge[bridgeId]); - if (command->getKeyword() == LightState) - { - if (command->getBody() == "1") - { - m_lightManagers[bridgeId]->lightOn(); - } - else - { - m_lightManagers[bridgeId]->lightOff(); - } - } - else if (command->getKeyword() == RgbColor) - { - m_lightManagers[bridgeId]->setLightColorUsingXy(command->getBody()); - } - } - else - { - m_lightManager->setLightId(lightName, m_detectedLights); - if (command->getKeyword() == LightState) - { - if (command->getBody() == "1") - { - m_lightManager->lightOn(); - } - else - { - m_lightManager->lightOff(); - } - } - else if (command->getKeyword() == RgbColor) - { - m_lightManager->setLightColorUsingXy(command->getBody()); - } - } + //if (m_configuration.getPairingMode() == kAuto) + //{ + const auto deviceDetails = m_api->getDeviceDetails(lightName); + const auto bridgeId = std::stoi(deviceDetails->get("bridgeId")); + // TODO : Handle light ON/OFF + // m_lightManagers[bridgeId]->setLightId(lightName, m_detectedLightsByBridge[bridgeId]); + // if (command->getKeyword() == LightState) + // { + // if (command->getBody() == "1") + // { + // m_lightManagers[bridgeId]->lightOn(); + // } + // else + // { + // m_lightManagers[bridgeId]->lightOff(); + // } + // } + // else if (command->getKeyword() == RgbColor) + // { + // m_lightManagers[bridgeId]->setLightColorUsingXy(command->getBody()); + // } + //} + //else + //{ + // m_lightsService->setLightId(lightName, m_detectedLights); + // if (command->getKeyword() == LightState) + // { + // if (command->getBody() == "1") + // { + // m_lightsService->lightOn(); + // } + // else + // { + // m_lightsService->lightOff(); + // } + // } + // else if (command->getKeyword() == RgbColor) + // { + // m_lightsService->setLightColorUsingXy(command->getBody()); + // } + //} break; } @@ -124,21 +124,23 @@ void CPhilipsHue::doWork(boost::shared_ptr api) { YADOMS_LOG(information) << "key bridge is pressed"; closeReadingBridgeButtonState(); - if (m_configuration.getPairingMode() == kAuto) - { - for (auto i = 0; i < m_HuesInformations.size(); i++) - { - m_lightManagers.push_back(CFactory::createLightManager(m_urlsManager[i])); - m_detectedLightsByBridge.push_back(m_lightManagers[i]->getAllLights()); - declareDeviceByBrdige(); - } - } - else + //if (m_configuration.getPairingMode() == kAuto) + //{ + for (auto i = 0; i < m_HuesInformations.size(); i++) { - m_lightManager = CFactory::createLightManager(m_urlManager); - m_detectedLights = m_lightManager->getAllLights(); - declareDevice(); + m_lightManagers.push_back(CFactory::createLightsService(m_urlsManager[0])); + auto lights = m_lightManagers[i]->getAllLights(); + m_detectedLightsByBridge.push_back(lights); + m_detectedLights.push_back(CFactory::createLight(m_urlsManager[0], lights[i + 1])); + declareDeviceByBrdige(); } + //} + //else + //{ + // m_lightsService = CFactory::createLightManager(m_urlManager); + // m_detectedLights = m_lightsService->getAllLights(); + // declareDevice(); + //} m_api->setPluginState(yApi::historization::EPluginState::kRunning); @@ -168,8 +170,9 @@ void CPhilipsHue::doWork(boost::shared_ptr api) YADOMS_LOG(information) << "search For New Lights command received"; try { - m_lightManager->searchForNewLights(); - m_detectedLights = m_lightManager->getNewLights(); + m_lightsService->searchForNewLights(); + // TODO : + //m_detectedLights = m_lightsService->getNewLights(); } catch (std::exception& exception) { @@ -218,15 +221,16 @@ void CPhilipsHue::init() { try { - m_urlManager = boost::make_shared(m_configuration); - m_hueBridgeDiscovery = CFactory::createHueBridgeDiscovery(m_urlManager); + m_urlsManager.push_back(boost::make_shared(m_configuration)); + + m_hueBridgeDiscovery = CFactory::createHueBridgeDiscovery(m_urlsManager[0]); m_hueService = CFactory::createHueService(m_api->getEventHandler(), kEvtKeyStateReceived, kEvtKeyStateTimeout, - m_urlManager); + m_urlsManager[0]); - m_HueInformations = m_hueBridgeDiscovery->getHueInformations(); + m_HuesInformations.push_back(m_hueBridgeDiscovery->getHueInformations()); m_api->setPluginState(yApi::historization::EPluginState::kCustom, "askToPressBridgeButton"); m_hueService->startReadingBridgeButtonState(); @@ -314,18 +318,19 @@ void CPhilipsHue::closeReadingBridgeButtonState() } } -void CPhilipsHue::declareDevice() -{ - for (auto& detectedLight : m_detectedLights) - { - YADOMS_LOG(information) << "Creating the device :" << detectedLight.second.getName(); - if (!m_api->deviceExists(detectedLight.second.getName())) - m_api->declareDevice(detectedLight.second.getName(), - detectedLight.second.getType(), - detectedLight.second.getModelId(), - m_historizers); - } -} +// TODO: To remove ?? +//void CPhilipsHue::declareDevice() +//{ +// for (auto& detectedLight : m_detectedLights) +// { +// YADOMS_LOG(information) << "Creating the device :" << detectedLight.second.getName(); +// if (!m_api->deviceExists(detectedLight.second.getName())) +// m_api->declareDevice(detectedLight.second.getName(), +// detectedLight.second.getType(), +// detectedLight.second.getModelId(), +// m_historizers); +// } +//} void CPhilipsHue::declareDeviceByBrdige() { diff --git a/sources/plugins/PhilipsHue/PhilipsHue.h b/sources/plugins/PhilipsHue/PhilipsHue.h index 264e3c33fe..0e75e94d5b 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.h +++ b/sources/plugins/PhilipsHue/PhilipsHue.h @@ -3,7 +3,8 @@ #include "Configuration.h" #include "HueBridgeDiscovery.h" #include "HueService.h" -#include "ILightManager.h" +#include "Devices/Interfaces/ILightsService.h" +#include "Devices/Interfaces/ILight.h" // Shortcut to yPluginApi namespace namespace yApi = shared::plugin::yPluginApi; @@ -46,13 +47,12 @@ class CPhilipsHue : public plugin_cpp_api::IPlugin std::vector> m_huesService; boost::shared_ptr m_hueService; std::vector> m_urlsManager; - boost::shared_ptr m_urlManager; boost::shared_ptr m_hueBridgeDiscovery; - boost::shared_ptr m_lightManager; - std::vector> m_lightManagers; + boost::shared_ptr m_lightsService; + std::vector> m_lightManagers; - std::map m_detectedLights; std::vector> m_detectedLightsByBridge; + std::vector< boost::shared_ptr> m_detectedLights; void closeReadingBridgeButtonState(); void declareDevice(); diff --git a/sources/plugins/PhilipsHue/changelog.md b/sources/plugins/PhilipsHue/changelog.md index ac0657d05b..6c53a73154 100644 --- a/sources/plugins/PhilipsHue/changelog.md +++ b/sources/plugins/PhilipsHue/changelog.md @@ -1,2 +1,4 @@ +### 1.1.0 +* Add interfaces by device model #713 ### 1.0.0 * First release From 82e241990a498f54b875b6216ea75c8c4f2374d8 Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Sun, 23 May 2021 22:07:25 +0200 Subject: [PATCH 02/20] #713 cleanup (WIP) --- .../PhilipsHue/Devices/Interfaces/ILight.h | 6 ++ .../Devices/Lights/Models/LCT015.cpp | 23 +++++++- .../PhilipsHue/Devices/Lights/Models/LCT015.h | 12 +++- sources/plugins/PhilipsHue/Factory.cpp | 2 +- sources/plugins/PhilipsHue/PhilipsHue.cpp | 58 +++++++++---------- sources/plugins/PhilipsHue/PhilipsHue.h | 4 +- 6 files changed, 67 insertions(+), 38 deletions(-) diff --git a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h index ab16c46fe5..086bd4b3c5 100644 --- a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h +++ b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h @@ -17,4 +17,10 @@ class ILight virtual std::vector> getHistorizables() = 0; + + virtual std::string getName() = 0; + + virtual std::string getType() = 0; + + virtual std::string getModelId() = 0; }; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp index 95c06778fa..e7796945ed 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp @@ -6,12 +6,13 @@ const std::string CLct015::LightState("STATE"); const std::string CLct015::RgbColor("RgbColor"); -CLct015::CLct015(boost::shared_ptr& urlManager, int& lightId) +CLct015::CLct015(boost::shared_ptr& urlManager, CHueLightInformations& lightInformations, int& lightId) : m_urlManager(urlManager), m_lightId(lightId), m_switch(boost::make_shared(LightState)), m_rgb(boost::make_shared( RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), - m_historizables({m_switch, m_rgb}) + m_historizables({m_switch, m_rgb}), + m_lightInformations(lightInformations) { } @@ -69,7 +70,8 @@ void CLct015::setLightColorUsingXy(const std::string& hexRgb) setLightState(lightUrl, body); } -std::vector> CLct015::getHistorizables() +std::vector> CLct015:: +getHistorizables() { return m_historizables; } @@ -89,3 +91,18 @@ void CLct015::setLightState(const std::string& lightUrl, shared::CDataContainer& throw; } } + +std::string CLct015::getName() +{ + return m_lightInformations.getName(); +} + +std::string CLct015::getType() +{ + return m_lightInformations.getType(); +} + +std::string CLct015::getModelId() +{ + return m_lightInformations.getModelId(); +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h index cb8378467b..67132c076d 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h @@ -7,7 +7,7 @@ class CLct015 : public ILight { public: - CLct015(boost::shared_ptr& urlManager, int& lightId); + CLct015(boost::shared_ptr& urlManager, CHueLightInformations& lightInformations, int& lightId); virtual ~CLct015() = default; void lightOn() override; @@ -16,7 +16,14 @@ class CLct015 : public ILight void setLightColorUsingXy(const std::string& hexRgb) override; - std::vector> getHistorizables(); + std::vector> getHistorizables() override; + + std::string getName() override; + + std::string getType() override; + + std::string getModelId() override; + private : static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); void setLightId(std::string& lightName, std::map& detectedLights); @@ -27,4 +34,5 @@ private : boost::shared_ptr m_switch; boost::shared_ptr m_rgb; std::vector> m_historizables; + CHueLightInformations m_lightInformations; }; diff --git a/sources/plugins/PhilipsHue/Factory.cpp b/sources/plugins/PhilipsHue/Factory.cpp index 8dbc05c1b5..60285bc827 100644 --- a/sources/plugins/PhilipsHue/Factory.cpp +++ b/sources/plugins/PhilipsHue/Factory.cpp @@ -40,7 +40,7 @@ boost::shared_ptr CFactory::createLight(boost::shared_ptr& switch (lightInformations.getModelId()) { case ELightType::kLCT015Value: - light = boost::make_shared(urlManager, id); + light = boost::make_shared(urlManager, lightInformations, id); break; default: break; diff --git a/sources/plugins/PhilipsHue/PhilipsHue.cpp b/sources/plugins/PhilipsHue/PhilipsHue.cpp index a9205c09ef..8ba7b894db 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.cpp +++ b/sources/plugins/PhilipsHue/PhilipsHue.cpp @@ -126,14 +126,17 @@ void CPhilipsHue::doWork(boost::shared_ptr api) closeReadingBridgeButtonState(); //if (m_configuration.getPairingMode() == kAuto) //{ - for (auto i = 0; i < m_HuesInformations.size(); i++) + for (auto i = 0; i < m_bridges.size(); i++) { - m_lightManagers.push_back(CFactory::createLightsService(m_urlsManager[0])); - auto lights = m_lightManagers[i]->getAllLights(); - m_detectedLightsByBridge.push_back(lights); - m_detectedLights.push_back(CFactory::createLight(m_urlsManager[0], lights[i + 1])); - declareDeviceByBrdige(); + m_lightManagers.push_back(CFactory::createLightsService(m_urlsManager[i])); + + for(auto light : m_lightManagers[i]->getAllLights()) + { + m_detectedLights.push_back(CFactory::createLight(m_urlsManager[i], light.second)); + } + } + declareDeviceByBrdige(); //} //else //{ @@ -180,7 +183,8 @@ void CPhilipsHue::doWork(boost::shared_ptr api) extraQuery->sendError(exception.what()); throw; } - declareDevice(); + // TODO : + //declareDevice(); extraQuery->sendSuccess(shared::CDataContainer::make()); } else if (extraQuery->getData()->query() == "searchForBridge") @@ -230,7 +234,7 @@ void CPhilipsHue::init() kEvtKeyStateTimeout, m_urlsManager[0]); - m_HuesInformations.push_back(m_hueBridgeDiscovery->getHueInformations()); + m_bridges.push_back(m_hueBridgeDiscovery->getHueInformations()); m_api->setPluginState(yApi::historization::EPluginState::kCustom, "askToPressBridgeButton"); m_hueService->startReadingBridgeButtonState(); @@ -257,11 +261,8 @@ void CPhilipsHue::fillHuesInformations() try { m_api->setPluginState(yApi::historization::EPluginState::kCustom, "BridgesSearchInProgress"); - auto foundBridges = m_hueBridgeDiscovery->FindBridges(); - for (auto& foundBridge : foundBridges) - { - m_HuesInformations.push_back(foundBridge); - } + m_bridges = m_hueBridgeDiscovery->FindBridges(); + m_api->setPluginState(yApi::historization::EPluginState::kCustom, "BridgesFound"); } catch (const std::exception& exception) @@ -277,9 +278,9 @@ void CPhilipsHue::startReadingBridgeButtonState() { try { - for (auto i = 0; i < m_HuesInformations.size(); i++) + for (auto i = 0; i < m_bridges.size(); i++) { - m_urlsManager.push_back(boost::make_shared(m_HuesInformations[i], m_configuration)); + m_urlsManager.push_back(boost::make_shared(m_bridges[i], m_configuration)); m_huesService.push_back(CFactory::createHueService(m_api->getEventHandler(), kEvtKeyStateReceived, @@ -307,7 +308,7 @@ void CPhilipsHue::closeReadingBridgeButtonState() { if (m_configuration.getPairingMode() == EPairingMode::kAuto) { - for (auto i = 0; i < m_HuesInformations.size(); i++) + for (auto i = 0; i < m_bridges.size(); i++) { m_huesService[i]->closeReadingBridgeButtonState(); } @@ -334,20 +335,17 @@ void CPhilipsHue::closeReadingBridgeButtonState() void CPhilipsHue::declareDeviceByBrdige() { - for (auto i = 0; i < m_detectedLightsByBridge.size(); i++) + for (auto light : m_detectedLights) { - for (auto j = 1; j <= m_detectedLightsByBridge[i].size(); j++) - { - std::map bridgeId; - bridgeId.insert(std::pair("bridgeId", std::to_string(i))); - - YADOMS_LOG(information) << "Creating the device :" << m_detectedLightsByBridge[i].at(j).getName(); - if (!m_api->deviceExists(m_detectedLightsByBridge[i].at(j).getName())) - m_api->declareDevice(m_detectedLightsByBridge[i].at(j).getName(), - m_detectedLightsByBridge[i].at(j).getType(), - m_detectedLightsByBridge[i].at(j).getModelId(), - m_historizers, - shared::CDataContainer::make(bridgeId)); - } + // std::map bridgeId; + // bridgeId.insert(std::pair("bridgeId", std::to_string(i))); + + YADOMS_LOG(information) << "Creating the device :" << light->getName(); + if (!m_api->deviceExists(light->getName())) + m_api->declareDevice(light->getName(), + light->getType(), + light->getModelId(), + light->getHistorizables()); } } + diff --git a/sources/plugins/PhilipsHue/PhilipsHue.h b/sources/plugins/PhilipsHue/PhilipsHue.h index 0e75e94d5b..de97ea895a 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.h +++ b/sources/plugins/PhilipsHue/PhilipsHue.h @@ -42,7 +42,6 @@ class CPhilipsHue : public plugin_cpp_api::IPlugin boost::shared_ptr m_api; static const std::string PhilipsHueBridgeName; - std::vector m_HuesInformations; CHueInformations m_HueInformations; std::vector> m_huesService; boost::shared_ptr m_hueService; @@ -54,8 +53,9 @@ class CPhilipsHue : public plugin_cpp_api::IPlugin std::vector> m_detectedLightsByBridge; std::vector< boost::shared_ptr> m_detectedLights; + std::vector m_bridges; void closeReadingBridgeButtonState(); - void declareDevice(); + //void declareDevice(); void declareDeviceByBrdige(); boost::shared_ptr m_switch; From bc78e40cb22d311f9d0520c40885070681a6fb53 Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Mon, 24 May 2021 19:12:52 +0200 Subject: [PATCH 03/20] make curlpp accepte POST and PUT body --- sources/shared/shared/http/curlppHttpRestRequest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/shared/shared/http/curlppHttpRestRequest.cpp b/sources/shared/shared/http/curlppHttpRestRequest.cpp index c659e939e7..18fa1a4a17 100644 --- a/sources/shared/shared/http/curlppHttpRestRequest.cpp +++ b/sources/shared/shared/http/curlppHttpRestRequest.cpp @@ -60,8 +60,8 @@ namespace shared IHttpRestRequest& CCurlppHttpRestRequest::withBody(const std::string& body) { - if (m_requestType != EType::kPost) - throw std::runtime_error("CCurlppHttpRestRequest : body is only supported for POST requests"); + if (m_requestType != EType::kPost && m_requestType != EType::kPut) + throw std::runtime_error("CCurlppHttpRestRequest : body is only supported for POST and PUT requests"); m_body = body; return *this; } From aeb600992d91fa8dea22df93be3d94e83ec5e029 Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Mon, 24 May 2021 19:13:10 +0200 Subject: [PATCH 04/20] #713 cleanup (WIP) --- .../PhilipsHue/Devices/Interfaces/ILight.h | 4 +- .../Devices/Lights/Models/LCT015.cpp | 38 +++------ .../PhilipsHue/Devices/Lights/Models/LCT015.h | 13 +-- sources/plugins/PhilipsHue/Factory.cpp | 7 +- sources/plugins/PhilipsHue/Factory.h | 2 +- sources/plugins/PhilipsHue/PhilipsHue.cpp | 80 ++++++++++++++----- sources/plugins/PhilipsHue/PhilipsHue.h | 3 +- 7 files changed, 86 insertions(+), 61 deletions(-) diff --git a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h index 086bd4b3c5..c1738e62ea 100644 --- a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h +++ b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h @@ -7,8 +7,6 @@ class ILight public: virtual ~ILight() = default; - virtual void setLightId(std::string& lightName, std::map& detectedLights) = 0; - virtual void lightOn() = 0; virtual void lightOff() = 0; @@ -23,4 +21,6 @@ class ILight virtual std::string getType() = 0; virtual std::string getModelId() = 0; + + virtual int getDeviceId() = 0; }; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp index e7796945ed..e3f6b9a4c0 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp @@ -6,9 +6,9 @@ const std::string CLct015::LightState("STATE"); const std::string CLct015::RgbColor("RgbColor"); -CLct015::CLct015(boost::shared_ptr& urlManager, CHueLightInformations& lightInformations, int& lightId) +CLct015::CLct015(boost::shared_ptr& urlManager, std::pair& lightInformations) : m_urlManager(urlManager), - m_lightId(lightId), m_switch(boost::make_shared(LightState)), + m_switch(boost::make_shared(LightState)), m_rgb(boost::make_shared( RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), m_historizables({m_switch, m_rgb}), @@ -16,26 +16,9 @@ CLct015::CLct015(boost::shared_ptr& urlManager, CHueLightInformatio { } -void CLct015::setLightId(std::string& lightName, std::map& detectedLights) -{ - const auto it = std::find_if(std::begin(detectedLights), std::end(detectedLights), - [&lightName](auto&& pair) - { - return pair.second.getName() == lightName; - }); - - if (it == std::end(detectedLights)) - { - YADOMS_LOG(warning) << "Light not found"; - throw std::runtime_error("Light ID is not found"); - } - YADOMS_LOG(information) << "Light ID = " << m_lightId << " is found "; - m_lightId = it->first; -} - void CLct015::lightOn() { - const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightId); + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); shared::CDataContainer body; @@ -46,7 +29,7 @@ void CLct015::lightOn() void CLct015::lightOff() { - const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightId); + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); shared::CDataContainer body; @@ -56,7 +39,7 @@ void CLct015::lightOff() void CLct015::setLightColorUsingXy(const std::string& hexRgb) { - const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightId); + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); auto rgb = CColorConverter::hexToRgb(hexRgb); @@ -94,15 +77,20 @@ void CLct015::setLightState(const std::string& lightUrl, shared::CDataContainer& std::string CLct015::getName() { - return m_lightInformations.getName(); + return m_lightInformations.second.getName(); } std::string CLct015::getType() { - return m_lightInformations.getType(); + return m_lightInformations.second.getType(); } std::string CLct015::getModelId() { - return m_lightInformations.getModelId(); + return m_lightInformations.second.getModelId(); +} + +int CLct015::getDeviceId() +{ + return m_lightInformations.first; } diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h index 67132c076d..885ae9b557 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h @@ -7,7 +7,7 @@ class CLct015 : public ILight { public: - CLct015(boost::shared_ptr& urlManager, CHueLightInformations& lightInformations, int& lightId); + CLct015(boost::shared_ptr& urlManager, std::pair& lightInformations); virtual ~CLct015() = default; void lightOn() override; @@ -16,7 +16,8 @@ class CLct015 : public ILight void setLightColorUsingXy(const std::string& hexRgb) override; - std::vector> getHistorizables() override; + std::vector> getHistorizables() + override; std::string getName() override; @@ -24,15 +25,15 @@ class CLct015 : public ILight std::string getModelId() override; + int getDeviceId() override; + private : static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); - void setLightId(std::string& lightName, std::map& detectedLights); - boost::shared_ptr& m_urlManager; - int m_lightId; + boost::shared_ptr m_urlManager; static const std::string LightState; static const std::string RgbColor; boost::shared_ptr m_switch; boost::shared_ptr m_rgb; std::vector> m_historizables; - CHueLightInformations m_lightInformations; + std::pair m_lightInformations; }; diff --git a/sources/plugins/PhilipsHue/Factory.cpp b/sources/plugins/PhilipsHue/Factory.cpp index 60285bc827..488c0ae3b6 100644 --- a/sources/plugins/PhilipsHue/Factory.cpp +++ b/sources/plugins/PhilipsHue/Factory.cpp @@ -33,14 +33,13 @@ boost::shared_ptr CFactory::createLightsService(boost::shared_pt } boost::shared_ptr CFactory::createLight(boost::shared_ptr& urlManager, - CHueLightInformations& lightInformations) + std::pair& lightInformations) { boost::shared_ptr light = nullptr; - int id = 1; - switch (lightInformations.getModelId()) + switch (lightInformations.second.getModelId()) { case ELightType::kLCT015Value: - light = boost::make_shared(urlManager, lightInformations, id); + light = boost::make_shared(urlManager, lightInformations); break; default: break; diff --git a/sources/plugins/PhilipsHue/Factory.h b/sources/plugins/PhilipsHue/Factory.h index 8d0bdac922..ec6c703219 100644 --- a/sources/plugins/PhilipsHue/Factory.h +++ b/sources/plugins/PhilipsHue/Factory.h @@ -21,5 +21,5 @@ class CFactory static boost::shared_ptr createHueBridgeDiscovery(); static boost::shared_ptr createLightsService(boost::shared_ptr& urlManager); static boost::shared_ptr createLight(boost::shared_ptr& urlManager, - CHueLightInformations& lightInformations); + std::pair& lightInformations); }; diff --git a/sources/plugins/PhilipsHue/PhilipsHue.cpp b/sources/plugins/PhilipsHue/PhilipsHue.cpp index 8ba7b894db..1bf23e80df 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.cpp +++ b/sources/plugins/PhilipsHue/PhilipsHue.cpp @@ -76,6 +76,24 @@ void CPhilipsHue::doWork(boost::shared_ptr api) //{ const auto deviceDetails = m_api->getDeviceDetails(lightName); const auto bridgeId = std::stoi(deviceDetails->get("bridgeId")); + + const auto lightId = getLightId(lightName); + + if (command->getKeyword() == LightState) + { + if (command->getBody() == "1") + { + m_detectedLights[lightId]->lightOn(); + } + else + { + m_detectedLights[lightId]->lightOff(); + } + } + else if (command->getKeyword() == RgbColor) + { + m_detectedLights[lightId]->setLightColorUsingXy(command->getBody()); + } // TODO : Handle light ON/OFF // m_lightManagers[bridgeId]->setLightId(lightName, m_detectedLightsByBridge[bridgeId]); // if (command->getKeyword() == LightState) @@ -124,26 +142,19 @@ void CPhilipsHue::doWork(boost::shared_ptr api) { YADOMS_LOG(information) << "key bridge is pressed"; closeReadingBridgeButtonState(); - //if (m_configuration.getPairingMode() == kAuto) - //{ + // TODO : Move it to a method for (auto i = 0; i < m_bridges.size(); i++) { m_lightManagers.push_back(CFactory::createLightsService(m_urlsManager[i])); - for(auto light : m_lightManagers[i]->getAllLights()) + for (auto& light : m_lightManagers[i]->getAllLights()) { - m_detectedLights.push_back(CFactory::createLight(m_urlsManager[i], light.second)); + auto lightPair = std::make_pair(light.first, light.second); + auto test = CFactory::createLight(m_urlsManager[i], lightPair); + m_detectedLights.push_back(test); } - } declareDeviceByBrdige(); - //} - //else - //{ - // m_lightsService = CFactory::createLightManager(m_urlManager); - // m_detectedLights = m_lightsService->getAllLights(); - // declareDevice(); - //} m_api->setPluginState(yApi::historization::EPluginState::kRunning); @@ -335,17 +346,42 @@ void CPhilipsHue::closeReadingBridgeButtonState() void CPhilipsHue::declareDeviceByBrdige() { - for (auto light : m_detectedLights) + auto i = 0; + for (auto& bridge : m_bridges) { - // std::map bridgeId; - // bridgeId.insert(std::pair("bridgeId", std::to_string(i))); - - YADOMS_LOG(information) << "Creating the device :" << light->getName(); - if (!m_api->deviceExists(light->getName())) - m_api->declareDevice(light->getName(), - light->getType(), - light->getModelId(), - light->getHistorizables()); + std::map bridgeId; + bridgeId.insert(std::pair("bridgeId", std::to_string(i))); + + for (auto light : m_detectedLights) + { + YADOMS_LOG(information) << "Creating the device :" << light->getName(); + if (!m_api->deviceExists(light->getName())) + { + m_api->declareDevice(light->getName(), + light->getType(), + light->getModelId(), + light->getHistorizables(), + shared::CDataContainer::make(bridgeId)); + } + } + i++; } } +int CPhilipsHue::getLightId(std::string& lightName) +{ + const auto it = std::find_if(std::begin(m_detectedLights), std::end(m_detectedLights), + [&lightName](auto&& pair) + { + return pair->getName() == lightName; + }); + + if (it == std::end(m_detectedLights)) + { + YADOMS_LOG(warning) << "Light not found"; + throw std::runtime_error("Light ID is not found"); + } + YADOMS_LOG(information) << "Light ID = " << it->get()->getDeviceId() << " is found "; + + return it->get()->getDeviceId(); +} diff --git a/sources/plugins/PhilipsHue/PhilipsHue.h b/sources/plugins/PhilipsHue/PhilipsHue.h index de97ea895a..99c111009e 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.h +++ b/sources/plugins/PhilipsHue/PhilipsHue.h @@ -51,7 +51,7 @@ class CPhilipsHue : public plugin_cpp_api::IPlugin std::vector> m_lightManagers; std::vector> m_detectedLightsByBridge; - std::vector< boost::shared_ptr> m_detectedLights; + std::vector> m_detectedLights; std::vector m_bridges; void closeReadingBridgeButtonState(); @@ -64,4 +64,5 @@ class CPhilipsHue : public plugin_cpp_api::IPlugin static const std::string LightState; static const std::string RgbColor; + int getLightId(std::string& lightName); }; From 7dae7d1fbf4277b4da68cdeeb8ca84405ce33fa4 Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Sat, 5 Jun 2021 18:56:11 +0200 Subject: [PATCH 05/20] #713 fix lights index --- sources/plugins/PhilipsHue/PhilipsHue.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/sources/plugins/PhilipsHue/PhilipsHue.cpp b/sources/plugins/PhilipsHue/PhilipsHue.cpp index 1bf23e80df..482270bed0 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.cpp +++ b/sources/plugins/PhilipsHue/PhilipsHue.cpp @@ -4,7 +4,6 @@ #include #include "shared/http/ssdp/DiscoverService.h" #include "Factory.h" -#include "Devices/Utils/ColorConverter.h" IMPLEMENT_PLUGIN(CPhilipsHue) @@ -78,21 +77,21 @@ void CPhilipsHue::doWork(boost::shared_ptr api) const auto bridgeId = std::stoi(deviceDetails->get("bridgeId")); const auto lightId = getLightId(lightName); - + const auto detectedLightId = lightId - 1; if (command->getKeyword() == LightState) { if (command->getBody() == "1") { - m_detectedLights[lightId]->lightOn(); + m_detectedLights[detectedLightId]->lightOn(); } else { - m_detectedLights[lightId]->lightOff(); + m_detectedLights[detectedLightId]->lightOff(); } } else if (command->getKeyword() == RgbColor) { - m_detectedLights[lightId]->setLightColorUsingXy(command->getBody()); + m_detectedLights[detectedLightId]->setLightColorUsingXy(command->getBody()); } // TODO : Handle light ON/OFF // m_lightManagers[bridgeId]->setLightId(lightName, m_detectedLightsByBridge[bridgeId]); @@ -150,6 +149,7 @@ void CPhilipsHue::doWork(boost::shared_ptr api) for (auto& light : m_lightManagers[i]->getAllLights()) { auto lightPair = std::make_pair(light.first, light.second); + // TODO : rename auto test = CFactory::createLight(m_urlsManager[i], lightPair); m_detectedLights.push_back(test); } @@ -346,13 +346,12 @@ void CPhilipsHue::closeReadingBridgeButtonState() void CPhilipsHue::declareDeviceByBrdige() { - auto i = 0; - for (auto& bridge : m_bridges) + for (auto i = 0; i < m_bridges.size(); i++) { std::map bridgeId; bridgeId.insert(std::pair("bridgeId", std::to_string(i))); - for (auto light : m_detectedLights) + for (auto& light : m_detectedLights) { YADOMS_LOG(information) << "Creating the device :" << light->getName(); if (!m_api->deviceExists(light->getName())) @@ -364,7 +363,6 @@ void CPhilipsHue::declareDeviceByBrdige() shared::CDataContainer::make(bridgeId)); } } - i++; } } From 3b73de23bad2c05813cbd740e566ee988d37a20a Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Sat, 5 Jun 2021 19:08:53 +0200 Subject: [PATCH 06/20] #713 some cleanup --- sources/plugins/PhilipsHue/PhilipsHue.cpp | 86 +++++------------------ sources/plugins/PhilipsHue/PhilipsHue.h | 2 +- 2 files changed, 20 insertions(+), 68 deletions(-) diff --git a/sources/plugins/PhilipsHue/PhilipsHue.cpp b/sources/plugins/PhilipsHue/PhilipsHue.cpp index 482270bed0..a033d66777 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.cpp +++ b/sources/plugins/PhilipsHue/PhilipsHue.cpp @@ -71,8 +71,7 @@ void CPhilipsHue::doWork(boost::shared_ptr api) YADOMS_LOG(information) << "Command received from Yadoms : " << yApi::IDeviceCommand::toString(command); auto lightName = command->getDevice(); - //if (m_configuration.getPairingMode() == kAuto) - //{ + const auto deviceDetails = m_api->getDeviceDetails(lightName); const auto bridgeId = std::stoi(deviceDetails->get("bridgeId")); @@ -93,44 +92,7 @@ void CPhilipsHue::doWork(boost::shared_ptr api) { m_detectedLights[detectedLightId]->setLightColorUsingXy(command->getBody()); } - // TODO : Handle light ON/OFF - // m_lightManagers[bridgeId]->setLightId(lightName, m_detectedLightsByBridge[bridgeId]); - // if (command->getKeyword() == LightState) - // { - // if (command->getBody() == "1") - // { - // m_lightManagers[bridgeId]->lightOn(); - // } - // else - // { - // m_lightManagers[bridgeId]->lightOff(); - // } - // } - // else if (command->getKeyword() == RgbColor) - // { - // m_lightManagers[bridgeId]->setLightColorUsingXy(command->getBody()); - // } - //} - //else - //{ - // m_lightsService->setLightId(lightName, m_detectedLights); - // if (command->getKeyword() == LightState) - // { - // if (command->getBody() == "1") - // { - // m_lightsService->lightOn(); - // } - // else - // { - // m_lightsService->lightOff(); - // } - // } - // else if (command->getKeyword() == RgbColor) - // { - // m_lightsService->setLightColorUsingXy(command->getBody()); - // } - //} - + break; } case kCustomEvent: @@ -140,20 +102,9 @@ void CPhilipsHue::doWork(boost::shared_ptr api) case kEvtKeyStateReceived: { YADOMS_LOG(information) << "key bridge is pressed"; - closeReadingBridgeButtonState(); - // TODO : Move it to a method - for (auto i = 0; i < m_bridges.size(); i++) - { - m_lightManagers.push_back(CFactory::createLightsService(m_urlsManager[i])); - for (auto& light : m_lightManagers[i]->getAllLights()) - { - auto lightPair = std::make_pair(light.first, light.second); - // TODO : rename - auto test = CFactory::createLight(m_urlsManager[i], lightPair); - m_detectedLights.push_back(test); - } - } + closeReadingBridgeButtonState(); + declareLights(); declareDeviceByBrdige(); m_api->setPluginState(yApi::historization::EPluginState::kRunning); @@ -330,20 +281,6 @@ void CPhilipsHue::closeReadingBridgeButtonState() } } -// TODO: To remove ?? -//void CPhilipsHue::declareDevice() -//{ -// for (auto& detectedLight : m_detectedLights) -// { -// YADOMS_LOG(information) << "Creating the device :" << detectedLight.second.getName(); -// if (!m_api->deviceExists(detectedLight.second.getName())) -// m_api->declareDevice(detectedLight.second.getName(), -// detectedLight.second.getType(), -// detectedLight.second.getModelId(), -// m_historizers); -// } -//} - void CPhilipsHue::declareDeviceByBrdige() { for (auto i = 0; i < m_bridges.size(); i++) @@ -366,6 +303,21 @@ void CPhilipsHue::declareDeviceByBrdige() } } +void CPhilipsHue::declareLights() +{ + for (auto i = 0; i < m_bridges.size(); i++) + { + m_lightManagers.push_back(CFactory::createLightsService(m_urlsManager[i])); + + for (auto& light : m_lightManagers[i]->getAllLights()) + { + auto lightPair = std::make_pair(light.first, light.second); + auto detectedLight = CFactory::createLight(m_urlsManager[i], lightPair); + m_detectedLights.push_back(detectedLight); + } + } +} + int CPhilipsHue::getLightId(std::string& lightName) { const auto it = std::find_if(std::begin(m_detectedLights), std::end(m_detectedLights), diff --git a/sources/plugins/PhilipsHue/PhilipsHue.h b/sources/plugins/PhilipsHue/PhilipsHue.h index 99c111009e..b8d8265695 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.h +++ b/sources/plugins/PhilipsHue/PhilipsHue.h @@ -55,8 +55,8 @@ class CPhilipsHue : public plugin_cpp_api::IPlugin std::vector m_bridges; void closeReadingBridgeButtonState(); - //void declareDevice(); void declareDeviceByBrdige(); + void declareLights(); boost::shared_ptr m_switch; boost::shared_ptr m_rgb; From e0615ab93841cc2b6c3752b5380f155f449416b6 Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Sat, 5 Jun 2021 19:28:00 +0200 Subject: [PATCH 07/20] #713 declare new devices --- sources/plugins/PhilipsHue/PhilipsHue.cpp | 23 ++++++++++++++++++----- sources/plugins/PhilipsHue/PhilipsHue.h | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sources/plugins/PhilipsHue/PhilipsHue.cpp b/sources/plugins/PhilipsHue/PhilipsHue.cpp index a033d66777..e57a268a7c 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.cpp +++ b/sources/plugins/PhilipsHue/PhilipsHue.cpp @@ -92,7 +92,7 @@ void CPhilipsHue::doWork(boost::shared_ptr api) { m_detectedLights[detectedLightId]->setLightColorUsingXy(command->getBody()); } - + break; } case kCustomEvent: @@ -136,8 +136,7 @@ void CPhilipsHue::doWork(boost::shared_ptr api) try { m_lightsService->searchForNewLights(); - // TODO : - //m_detectedLights = m_lightsService->getNewLights(); + declareNewLights(); } catch (std::exception& exception) { @@ -145,8 +144,7 @@ void CPhilipsHue::doWork(boost::shared_ptr api) extraQuery->sendError(exception.what()); throw; } - // TODO : - //declareDevice(); + declareDeviceByBrdige(); extraQuery->sendSuccess(shared::CDataContainer::make()); } else if (extraQuery->getData()->query() == "searchForBridge") @@ -318,6 +316,21 @@ void CPhilipsHue::declareLights() } } +void CPhilipsHue::declareNewLights() +{ + for (auto i = 0; i < m_bridges.size(); i++) + { + m_lightManagers.push_back(CFactory::createLightsService(m_urlsManager[i])); + + for (auto& light : m_lightsService->getNewLights()) + { + auto lightPair = std::make_pair(light.first, light.second); + auto detectedLight = CFactory::createLight(m_urlsManager[i], lightPair); + m_detectedLights.push_back(detectedLight); + } + } +} + int CPhilipsHue::getLightId(std::string& lightName) { const auto it = std::find_if(std::begin(m_detectedLights), std::end(m_detectedLights), diff --git a/sources/plugins/PhilipsHue/PhilipsHue.h b/sources/plugins/PhilipsHue/PhilipsHue.h index b8d8265695..e625d599d2 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.h +++ b/sources/plugins/PhilipsHue/PhilipsHue.h @@ -57,6 +57,7 @@ class CPhilipsHue : public plugin_cpp_api::IPlugin void closeReadingBridgeButtonState(); void declareDeviceByBrdige(); void declareLights(); + void declareNewLights(); boost::shared_ptr m_switch; boost::shared_ptr m_rgb; From 6c67fd6bb60f7807df5684aa23747cadfe5ce80f Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Sun, 6 Jun 2021 12:26:20 +0200 Subject: [PATCH 08/20] #713 add Gamut and none Gamut Light types --- sources/plugins/PhilipsHue/CMakeLists.txt | 18 +++- .../Lights/Models/{LCT015.cpp => GamutC.cpp} | 26 ++--- .../Lights/Models/{LCT015.h => GamutC.h} | 6 +- .../Devices/Lights/Service/LightsService.cpp | 2 + .../PhilipsHue/Devices/Utils/ColorType.cpp | 15 +++ .../PhilipsHue/Devices/Utils/ColorType.h | 15 +++ .../Devices/Utils/ColorTypeHelper.cpp | 98 +++++++++++++++++++ .../Devices/Utils/ColorTypeHelper.h | 26 +++++ .../Entities/HueLightInformations.cpp | 10 ++ .../Entities/HueLightInformations.h | 4 + sources/plugins/PhilipsHue/Factory.cpp | 27 ++++- 11 files changed, 224 insertions(+), 23 deletions(-) rename sources/plugins/PhilipsHue/Devices/Lights/Models/{LCT015.cpp => GamutC.cpp} (81%) rename sources/plugins/PhilipsHue/Devices/Lights/Models/{LCT015.h => GamutC.h} (89%) create mode 100644 sources/plugins/PhilipsHue/Devices/Utils/ColorType.cpp create mode 100644 sources/plugins/PhilipsHue/Devices/Utils/ColorType.h create mode 100644 sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.cpp create mode 100644 sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.h diff --git a/sources/plugins/PhilipsHue/CMakeLists.txt b/sources/plugins/PhilipsHue/CMakeLists.txt index 58102c5238..427f8dcd08 100644 --- a/sources/plugins/PhilipsHue/CMakeLists.txt +++ b/sources/plugins/PhilipsHue/CMakeLists.txt @@ -52,8 +52,18 @@ set(PHILIPS_HUE_PLUGIN_SOURCES ) set(PHILIPS_HUE_PLUGIN_LIGHTS_MODELS_SOURCES - Devices/Lights/Models/LCT015.cpp - Devices/Lights/Models/LCT015.h + Devices/Lights/Models/GamutC.cpp + Devices/Lights/Models/GamutC.h + Devices/Lights/Models/GamutA.cpp + Devices/Lights/Models/GamutA.h + Devices/Lights/Models/GamutB.cpp + Devices/Lights/Models/GamutB.h + Devices/Lights/Models/GamutOther.cpp + Devices/Lights/Models/GamutOther.h + Devices/Lights/Models/GamutNone.cpp + Devices/Lights/Models/GamutNone.h + + ) set(PHILIPS_HUE_PLUGIN_LIGHTS_SERVICE_SOURCES @@ -73,6 +83,10 @@ set(PHILIPS_HUE_PLUGIN_DEVICES_UTILS_SOURCES Devices/Utils/ColorConverter.cpp Devices/Utils/LightType.cpp Devices/Utils/LightType.h + Devices/Utils/ColorType.h + Devices/Utils/ColorType.cpp + Devices/Utils/ColorTypeHelper.h + Devices/Utils/ColorTypeHelper.cpp ) ######################################### diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp similarity index 81% rename from sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp rename to sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp index e3f6b9a4c0..f2e721605c 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp @@ -1,12 +1,12 @@ -#include "LCT015.h" +#include "GamutC.h" #include "../../Utils/ColorConverter.h" #include "shared/http/HttpRestHelpers.h" #include "shared/Log.h" -const std::string CLct015::LightState("STATE"); -const std::string CLct015::RgbColor("RgbColor"); +const std::string CGamutC::LightState("STATE"); +const std::string CGamutC::RgbColor("RgbColor"); -CLct015::CLct015(boost::shared_ptr& urlManager, std::pair& lightInformations) +CGamutC::CGamutC(boost::shared_ptr& urlManager, std::pair& lightInformations) : m_urlManager(urlManager), m_switch(boost::make_shared(LightState)), m_rgb(boost::make_shared( @@ -16,7 +16,7 @@ CLct015::CLct015(boost::shared_ptr& urlManager, std::pairgetUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); @@ -27,7 +27,7 @@ void CLct015::lightOn() } -void CLct015::lightOff() +void CGamutC::lightOff() { const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); @@ -37,7 +37,7 @@ void CLct015::lightOff() setLightState(lightUrl, body); } -void CLct015::setLightColorUsingXy(const std::string& hexRgb) +void CGamutC::setLightColorUsingXy(const std::string& hexRgb) { const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); @@ -53,13 +53,13 @@ void CLct015::setLightColorUsingXy(const std::string& hexRgb) setLightState(lightUrl, body); } -std::vector> CLct015:: +std::vector> CGamutC:: getHistorizables() { return m_historizables; } -void CLct015::setLightState(const std::string& lightUrl, shared::CDataContainer& body) +void CGamutC::setLightState(const std::string& lightUrl, shared::CDataContainer& body) { try { @@ -75,22 +75,22 @@ void CLct015::setLightState(const std::string& lightUrl, shared::CDataContainer& } } -std::string CLct015::getName() +std::string CGamutC::getName() { return m_lightInformations.second.getName(); } -std::string CLct015::getType() +std::string CGamutC::getType() { return m_lightInformations.second.getType(); } -std::string CLct015::getModelId() +std::string CGamutC::getModelId() { return m_lightInformations.second.getModelId(); } -int CLct015::getDeviceId() +int CGamutC::getDeviceId() { return m_lightInformations.first; } diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h similarity index 89% rename from sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h rename to sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h index 885ae9b557..1a540d94a9 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/LCT015.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h @@ -3,12 +3,12 @@ #include "../../Interfaces/ILight.h" #include -class CLct015 : public ILight +class CGamutC : public ILight { public: - CLct015(boost::shared_ptr& urlManager, std::pair& lightInformations); - virtual ~CLct015() = default; + CGamutC(boost::shared_ptr& urlManager, std::pair& lightInformations); + virtual ~CGamutC() = default; void lightOn() override; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp index d29276e791..67ad5ff244 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp @@ -3,6 +3,7 @@ #include "shared/http/HttpRestHelpers.h" #include "../../Utils/ColorConverter.h" #include "../../../Entities/HueStreaming.h" +#include "../../Utils/ColorTypeHelper.h" CLightsService::CLightsService(boost::shared_ptr& urlManager) : m_urlManager(urlManager) @@ -118,6 +119,7 @@ std::map CLightsService::getAllLights() response->get( std::to_string(lightCounter) + "." + EHueLightResponseType::kProductId.toString())); } + hueLightInformations.setColorType(CColorTypeHelper::getColorType(response)); hueLightsInformations.insert({lightCounter, hueLightInformations}); lightCounter++; diff --git a/sources/plugins/PhilipsHue/Devices/Utils/ColorType.cpp b/sources/plugins/PhilipsHue/Devices/Utils/ColorType.cpp new file mode 100644 index 0000000000..12f4177634 --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Utils/ColorType.cpp @@ -0,0 +1,15 @@ +#include "ColorType.h" + +DECLARE_ENUM_IMPLEMENTATION(EColorType, + ((GAMUT_A)) + ((GAMUT_A_TEMPERATURE)) + ((GAMUT_B)) + ((GAMUT_B_TEMPERATURE)) + ((GAMUT_C)) + ((GAMUT_C_TEMPERATURE)) + ((GAMUT_OTHER)) + ((GAMUT_OTHER_TEMPERATURE)) + ((TEMPERATURE)) + ((UNDEFINED)) + ((NONE)) +) diff --git a/sources/plugins/PhilipsHue/Devices/Utils/ColorType.h b/sources/plugins/PhilipsHue/Devices/Utils/ColorType.h new file mode 100644 index 0000000000..b90f6f150d --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Utils/ColorType.h @@ -0,0 +1,15 @@ +#pragma once +#include +DECLARE_ENUM_HEADER(EColorType, + ((GAMUT_A)) + ((GAMUT_A_TEMPERATURE)) + ((GAMUT_B)) + ((GAMUT_B_TEMPERATURE)) + ((GAMUT_C)) + ((GAMUT_C_TEMPERATURE)) + ((GAMUT_OTHER)) + ((GAMUT_OTHER_TEMPERATURE)) + ((TEMPERATURE)) + ((UNDEFINED)) + ((NONE)) +) diff --git a/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.cpp b/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.cpp new file mode 100644 index 0000000000..9e3aeaa89a --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.cpp @@ -0,0 +1,98 @@ +#include "ColorTypeHelper.h" +#include "HueLightsResponseType.h" + +const std::set CColorTypeHelper::GamutBTypes{"LCT001", "LCT002", "LCT003", "LCT007", "LLM001"}; +const std::set CColorTypeHelper::GamutCTypes{ + "LCT010", "LCT011", "LCT012", "LCT014", "LCT015", "LCT016", "LLC020", "LST002", "LCA003", "LCB001" +}; +const std::set CColorTypeHelper::GamutATypes{ + "LST001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012", "LLC013", "LLC014" +}; + +const std::string CColorTypeHelper::OnOffLight{"on/off light"}; +const std::string CColorTypeHelper::OnOffPluginInUnit{"on/off plug-in unit"}; +const std::string CColorTypeHelper::DimmableLight{"dimmable light"}; +const std::string CColorTypeHelper::DimmablePluginInUnit{"dimmable plug-in unit"}; +const std::string CColorTypeHelper::ColorTemperatureLight{"color temperature light"}; +const std::string CColorTypeHelper::ColorLight{"color light"}; +const std::string CColorTypeHelper::ExtendedColorLight{"extended color light"}; + +EColorType CColorTypeHelper::getColorType(boost::shared_ptr& response) +{ + if (response->exists(EHueLightResponseType::kType.toString()) && !response + -> + isNull(EHueLightResponseType::kType.toString())) + { + const auto type = response->get(EHueLightResponseType::kType.toString()); + if (type == OnOffLight || type == OnOffPluginInUnit) + { + return EColorType::kNONE; + } + if (type == DimmableLight || type == DimmablePluginInUnit) + { + return EColorType::kNONE; + } + if (type == ColorTemperatureLight) + { + return EColorType::kTEMPERATURE; + } + if (type == ColorLight) + { + return getGamutOrLegacyColorType(response, false); + } + if (type == ExtendedColorLight) + { + return getGamutOrLegacyColorType(response, true); + } + } + const auto message = "Could not determine Light type"; + YADOMS_LOG(error) << message; + throw std::runtime_error(message); +} + +EColorType CColorTypeHelper::getGamutOrLegacyColorType(boost::shared_ptr& response, bool hasCt) +{ + // Try to get color Gamut from capabilities + if (response->exists(EHueLightResponseType::kCapabilitiesControlColorGamutType.toString()) && !response + -> + isNull(EHueLightResponseType::kCapabilitiesControlColorGamutType.toString())) + { + const auto gamut = response->get( + EHueLightResponseType::kCapabilitiesControlColorGamutType.toString()); + if (gamut == "A") + { + return hasCt ? EColorType::kGAMUT_A_TEMPERATURE : EColorType::kGAMUT_A; + } + if (gamut == "B") + { + return hasCt ? EColorType::kGAMUT_B_TEMPERATURE : EColorType::kGAMUT_B; + } + if (gamut == "C") + { + return hasCt ? EColorType::kGAMUT_C_TEMPERATURE : EColorType::kGAMUT_C; + } + return hasCt ? EColorType::kGAMUT_OTHER_TEMPERATURE : EColorType::kGAMUT_OTHER; + } + // Old version without capabilities, fall back to hardcoded types + if (response->exists(EHueLightResponseType::kModelId.toString()) && !response + -> + isNull(EHueLightResponseType::kModelId.toString())) + { + const auto modelId = response->get(EHueLightResponseType::kModelId.toString()); + + if (GamutATypes.count(modelId)) + { + return hasCt ? EColorType::kGAMUT_A_TEMPERATURE : EColorType::kGAMUT_A; + } + if (GamutBTypes.count(modelId)) + { + return hasCt ? EColorType::kGAMUT_B_TEMPERATURE : EColorType::kGAMUT_B; + } + if (GamutCTypes.count(modelId)) + { + return hasCt ? EColorType::kGAMUT_C_TEMPERATURE : EColorType::kGAMUT_C; + } + return hasCt ? EColorType::kGAMUT_OTHER_TEMPERATURE : EColorType::kGAMUT_OTHER; + } + return EColorType::kUNDEFINED; +} diff --git a/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.h b/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.h new file mode 100644 index 0000000000..f148af72cd --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.h @@ -0,0 +1,26 @@ +#pragma once +#include "ColorType.h" +#include "shared/DataContainer.h" + +class CColorTypeHelper +{ +public: + + CColorTypeHelper() = default; + virtual ~CColorTypeHelper() = default; + + static EColorType getColorType(boost::shared_ptr& response); + +private: + static EColorType getGamutOrLegacyColorType(boost::shared_ptr& response, bool hasCt); + static const std::set GamutBTypes; + static const std::set GamutCTypes; + static const std::set GamutATypes; + static const std::string OnOffLight; + static const std::string OnOffPluginInUnit; + static const std::string DimmableLight; + static const std::string DimmablePluginInUnit; + static const std::string ColorTemperatureLight; + static const std::string ColorLight; + static const std::string ExtendedColorLight; +}; diff --git a/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp b/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp index 3477ba3349..c74a351164 100644 --- a/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp +++ b/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp @@ -65,6 +65,11 @@ const std::string& CHueLightInformations::getProductId() const return m_productId; } +const EColorType& CHueLightInformations::getColorType() const +{ + return m_colorType; +} + void CHueLightInformations::setState(const CHueState& state) { m_state = state; @@ -228,3 +233,8 @@ void CHueLightInformations::setProductId(const std::string& productId) { m_productId = productId; } + +void CHueLightInformations::setColorType(const EColorType& colorType) +{ + m_colorType = colorType; +} diff --git a/sources/plugins/PhilipsHue/Entities/HueLightInformations.h b/sources/plugins/PhilipsHue/Entities/HueLightInformations.h index ff7dc82a78..d99324ec9a 100644 --- a/sources/plugins/PhilipsHue/Entities/HueLightInformations.h +++ b/sources/plugins/PhilipsHue/Entities/HueLightInformations.h @@ -4,6 +4,7 @@ #include "HueCapabilities.h" #include "HueConfig.h" #include "../Devices/Utils/LightType.h" +#include "../Devices/Utils/ColorType.h" class CHueLightInformations { @@ -26,6 +27,7 @@ class CHueLightInformations const std::string& getSwVersion() const; const std::string& getSwConfigId() const; const std::string& getProductId() const; + const EColorType& getColorType() const; void setState(const CHueState& state); void setSwUpdate(const CHueSwUpdate& swUpdate); @@ -40,6 +42,7 @@ class CHueLightInformations void setSwVersion(const std::string& swVersion); void setSwConfigId(const std::string& swConfigId); void setProductId(const std::string& productId); + void setColorType(const EColorType& colorType); private: CHueState m_state; @@ -55,4 +58,5 @@ class CHueLightInformations std::string m_swVersion; std::string m_swConfigId; std::string m_productId; + EColorType m_colorType; }; diff --git a/sources/plugins/PhilipsHue/Factory.cpp b/sources/plugins/PhilipsHue/Factory.cpp index 488c0ae3b6..5b4b618445 100644 --- a/sources/plugins/PhilipsHue/Factory.cpp +++ b/sources/plugins/PhilipsHue/Factory.cpp @@ -3,8 +3,11 @@ #include "HueBridgeDiscovery.h" #include "Devices/Interfaces/ILightsService.h" #include "Devices/Lights/Service//LightsService.h" -#include "Devices/Utils/LightType.h" -#include "Devices/Lights/Models/LCT015.h" +#include "Devices/Lights/Models/GamutC.h" +#include "Devices/Lights/Models/GamutA.h" +#include "Devices/Lights/Models/GamutB.h" +#include "Devices/Lights/Models/GamutOther.h" +#include "Devices/Lights/Models/GamutNone.h" boost::shared_ptr CFactory::createHueService(shared::event::CEventHandler& mainEventHandler, int evtKeyStateReceived, @@ -36,12 +39,26 @@ boost::shared_ptr CFactory::createLight(boost::shared_ptr& std::pair& lightInformations) { boost::shared_ptr light = nullptr; - switch (lightInformations.second.getModelId()) + switch (lightInformations.second.getColorType()) { - case ELightType::kLCT015Value: - light = boost::make_shared(urlManager, lightInformations); + case EColorType::kGAMUT_AValue: + case EColorType::kGAMUT_A_TEMPERATUREValue: + light = boost::make_shared(urlManager, lightInformations); + break; + case EColorType::kGAMUT_BValue: + case EColorType::kGAMUT_B_TEMPERATUREValue: + light = boost::make_shared(urlManager, lightInformations); + break; + case EColorType::kGAMUT_CValue: + case EColorType::kGAMUT_C_TEMPERATUREValue: + light = boost::make_shared(urlManager, lightInformations); + break; + case EColorType::kGAMUT_OTHERValue: + case EColorType::kGAMUT_OTHER_TEMPERATUREValue: + light = boost::make_shared(urlManager, lightInformations); break; default: + light = boost::make_shared(urlManager, lightInformations); break; } return light; From 853d21b4aecd7459bcb83dc6a2ab277afa54dc3c Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Sun, 6 Jun 2021 12:29:26 +0200 Subject: [PATCH 09/20] #713 add Gamut and none Gamut Light types --- .../Devices/Lights/Models/GamutA.cpp | 96 +++++++++++++++++++ .../PhilipsHue/Devices/Lights/Models/GamutA.h | 39 ++++++++ .../Devices/Lights/Models/GamutB.cpp | 96 +++++++++++++++++++ .../PhilipsHue/Devices/Lights/Models/GamutB.h | 38 ++++++++ .../Devices/Lights/Models/GamutNone.cpp | 94 ++++++++++++++++++ .../Devices/Lights/Models/GamutNone.h | 37 +++++++ .../Devices/Lights/Models/GamutOther.cpp | 96 +++++++++++++++++++ .../Devices/Lights/Models/GamutOther.h | 39 ++++++++ 8 files changed, 535 insertions(+) create mode 100644 sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp create mode 100644 sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h create mode 100644 sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp create mode 100644 sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h create mode 100644 sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp create mode 100644 sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h create mode 100644 sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp create mode 100644 sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp new file mode 100644 index 0000000000..184d07a602 --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp @@ -0,0 +1,96 @@ +#include "GamutA.h" +#include "../../Utils/ColorConverter.h" +#include "shared/http/HttpRestHelpers.h" +#include "shared/Log.h" + +const std::string CGamutA::LightState("STATE"); +const std::string CGamutA::RgbColor("RgbColor"); + +CGamutA::CGamutA(boost::shared_ptr& urlManager, std::pair& lightInformations) + : m_urlManager(urlManager), + m_switch(boost::make_shared(LightState)), + m_rgb(boost::make_shared( + RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), + m_historizables({ m_switch, m_rgb }), + m_lightInformations(lightInformations) +{ +} + +void CGamutA::lightOn() +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("on", true); + setLightState(lightUrl, body); +} + + +void CGamutA::lightOff() +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("on", false); + setLightState(lightUrl, body); +} + +void CGamutA::setLightColorUsingXy(const std::string& hexRgb) +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + auto rgb = CColorConverter::hexToRgb(hexRgb); + const auto xy = CColorConverter::rgbToXy(rgb); + + shared::CDataContainer body; + body.set("on", true); + body.set("xy.0", xy.getX()); + body.set("xy.1", xy.getY()); + + setLightState(lightUrl, body); +} + +std::vector> CGamutA:: +getHistorizables() +{ + return m_historizables; +} + +void CGamutA::setLightState(const std::string& lightUrl, shared::CDataContainer& body) +{ + try + { + const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); + } + catch (std::exception& e) + { + const auto message = (boost::format("Fail to send Get http request or interpret answer \"%1%\" : %2%") % lightUrl + % + e.what()).str(); + YADOMS_LOG(error) << "Fail to send Get http request or interpret answer " << lightUrl << " : " << e.what(); + throw; + } +} + +std::string CGamutA::getName() +{ + return m_lightInformations.second.getName(); +} + +std::string CGamutA::getType() +{ + return m_lightInformations.second.getType(); +} + +std::string CGamutA::getModelId() +{ + return m_lightInformations.second.getModelId(); +} + +int CGamutA::getDeviceId() +{ + return m_lightInformations.first; +} \ No newline at end of file diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h new file mode 100644 index 0000000000..19cdc2a56b --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h @@ -0,0 +1,39 @@ +#pragma once +#include "../../../UrlManager.h" +#include "../../Interfaces/ILight.h" +#include + +class CGamutA : public ILight +{ +public: + + CGamutA(boost::shared_ptr& urlManager, std::pair& lightInformations); + virtual ~CGamutA() = default; + + void lightOn() override; + + void lightOff() override; + + void setLightColorUsingXy(const std::string & hexRgb) override; + + std::vector> getHistorizables() + override; + + std::string getName() override; + + std::string getType() override; + + std::string getModelId() override; + + int getDeviceId() override; + +private: + static void setLightState(const std::string & lightUrl, shared::CDataContainer & body); + boost::shared_ptr m_urlManager; + static const std::string LightState; + static const std::string RgbColor; + boost::shared_ptr m_switch; + boost::shared_ptr m_rgb; + std::vector> m_historizables; + std::pair m_lightInformations; +}; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp new file mode 100644 index 0000000000..bc517573b7 --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp @@ -0,0 +1,96 @@ +#include "GamutB.h" +#include "../../Utils/ColorConverter.h" +#include "shared/http/HttpRestHelpers.h" +#include "shared/Log.h" + +const std::string CGamutB::LightState("STATE"); +const std::string CGamutB::RgbColor("RgbColor"); + +CGamutB::CGamutB(boost::shared_ptr& urlManager, std::pair& lightInformations) + : m_urlManager(urlManager), + m_switch(boost::make_shared(LightState)), + m_rgb(boost::make_shared( + RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), + m_historizables({ m_switch, m_rgb }), + m_lightInformations(lightInformations) +{ +} + +void CGamutB::lightOn() +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("on", true); + setLightState(lightUrl, body); +} + + +void CGamutB::lightOff() +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("on", false); + setLightState(lightUrl, body); +} + +void CGamutB::setLightColorUsingXy(const std::string& hexRgb) +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + auto rgb = CColorConverter::hexToRgb(hexRgb); + const auto xy = CColorConverter::rgbToXy(rgb); + + shared::CDataContainer body; + body.set("on", true); + body.set("xy.0", xy.getX()); + body.set("xy.1", xy.getY()); + + setLightState(lightUrl, body); +} + +std::vector> CGamutB:: +getHistorizables() +{ + return m_historizables; +} + +void CGamutB::setLightState(const std::string& lightUrl, shared::CDataContainer& body) +{ + try + { + const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); + } + catch (std::exception& e) + { + const auto message = (boost::format("Fail to send Get http request or interpret answer \"%1%\" : %2%") % lightUrl + % + e.what()).str(); + YADOMS_LOG(error) << "Fail to send Get http request or interpret answer " << lightUrl << " : " << e.what(); + throw; + } +} + +std::string CGamutB::getName() +{ + return m_lightInformations.second.getName(); +} + +std::string CGamutB::getType() +{ + return m_lightInformations.second.getType(); +} + +std::string CGamutB::getModelId() +{ + return m_lightInformations.second.getModelId(); +} + +int CGamutB::getDeviceId() +{ + return m_lightInformations.first; +} \ No newline at end of file diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h new file mode 100644 index 0000000000..f2c42a1338 --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h @@ -0,0 +1,38 @@ +#pragma once +#include "../../../UrlManager.h" +#include "../../Interfaces/ILight.h" +#include + +class CGamutB : public ILight +{ +public: + CGamutB(boost::shared_ptr& urlManager, std::pair& lightInformations); + virtual ~CGamutB() = default; + + void lightOn() override; + + void lightOff() override; + + void setLightColorUsingXy(const std::string& hexRgb) override; + + std::vector> getHistorizables() + override; + + std::string getName() override; + + std::string getType() override; + + std::string getModelId() override; + + int getDeviceId() override; + +private: + static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); + boost::shared_ptr m_urlManager; + static const std::string LightState; + static const std::string RgbColor; + boost::shared_ptr m_switch; + boost::shared_ptr m_rgb; + std::vector> m_historizables; + std::pair m_lightInformations; +}; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp new file mode 100644 index 0000000000..e051e65270 --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp @@ -0,0 +1,94 @@ +#include "GamutNone.h" + +#include "../../Utils/ColorConverter.h" +#include "shared/http/HttpRestHelpers.h" +#include "shared/Log.h" + +const std::string CGamutNone::LightState("STATE"); + +CGamutNone::CGamutNone(boost::shared_ptr& urlManager, std::pair& lightInformations) + : m_urlManager(urlManager), + m_switch(boost::make_shared(LightState)), + m_historizables({ m_switch}), + m_lightInformations(lightInformations) +{ +} + +void CGamutNone::lightOn() +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("on", true); + setLightState(lightUrl, body); +} + + +void CGamutNone::lightOff() +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("on", false); + setLightState(lightUrl, body); +} + +void CGamutNone::setLightColorUsingXy(const std::string& hexRgb) +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + auto rgb = CColorConverter::hexToRgb(hexRgb); + const auto xy = CColorConverter::rgbToXy(rgb); + + shared::CDataContainer body; + body.set("on", true); + body.set("xy.0", xy.getX()); + body.set("xy.1", xy.getY()); + + setLightState(lightUrl, body); +} + +std::vector> CGamutNone:: +getHistorizables() +{ + return m_historizables; +} + +void CGamutNone::setLightState(const std::string& lightUrl, shared::CDataContainer& body) +{ + try + { + const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); + } + catch (std::exception& e) + { + const auto message = (boost::format("Fail to send Get http request or interpret answer \"%1%\" : %2%") % lightUrl + % + e.what()).str(); + YADOMS_LOG(error) << "Fail to send Get http request or interpret answer " << lightUrl << " : " << e.what(); + throw; + } +} + +std::string CGamutNone::getName() +{ + return m_lightInformations.second.getName(); +} + +std::string CGamutNone::getType() +{ + return m_lightInformations.second.getType(); +} + +std::string CGamutNone::getModelId() +{ + return m_lightInformations.second.getModelId(); +} + +int CGamutNone::getDeviceId() +{ + return m_lightInformations.first; +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h new file mode 100644 index 0000000000..455fc60859 --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h @@ -0,0 +1,37 @@ +#pragma once +#include "../../../UrlManager.h" +#include "../../Interfaces/ILight.h" +#include + +class CGamutNone : public ILight +{ +public: + + CGamutNone(boost::shared_ptr& urlManager, std::pair& lightInformations); + virtual ~CGamutNone() = default; + + void lightOn() override; + + void lightOff() override; + + void setLightColorUsingXy(const std::string& hexRgb) override; + + std::vector> getHistorizables() + override; + + std::string getName() override; + + std::string getType() override; + + std::string getModelId() override; + + int getDeviceId() override; + +private : + static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); + boost::shared_ptr m_urlManager; + static const std::string LightState; + boost::shared_ptr m_switch; + std::vector> m_historizables; + std::pair m_lightInformations; +}; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp new file mode 100644 index 0000000000..38edd6544f --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp @@ -0,0 +1,96 @@ +#include "GamutOther.h" +#include "../../Utils/ColorConverter.h" +#include "shared/http/HttpRestHelpers.h" +#include "shared/Log.h" + +const std::string CGamutOther::LightState("STATE"); +const std::string CGamutOther::RgbColor("RgbColor"); + +CGamutOther::CGamutOther(boost::shared_ptr& urlManager, std::pair& lightInformations) + : m_urlManager(urlManager), + m_switch(boost::make_shared(LightState)), + m_rgb(boost::make_shared( + RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), + m_historizables({ m_switch, m_rgb }), + m_lightInformations(lightInformations) +{ +} + +void CGamutOther::lightOn() +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("on", true); + setLightState(lightUrl, body); +} + + +void CGamutOther::lightOff() +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("on", false); + setLightState(lightUrl, body); +} + +void CGamutOther::setLightColorUsingXy(const std::string& hexRgb) +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kLightState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + auto rgb = CColorConverter::hexToRgb(hexRgb); + const auto xy = CColorConverter::rgbToXy(rgb); + + shared::CDataContainer body; + body.set("on", true); + body.set("xy.0", xy.getX()); + body.set("xy.1", xy.getY()); + + setLightState(lightUrl, body); +} + +std::vector> CGamutOther:: +getHistorizables() +{ + return m_historizables; +} + +void CGamutOther::setLightState(const std::string& lightUrl, shared::CDataContainer& body) +{ + try + { + const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); + } + catch (std::exception& e) + { + const auto message = (boost::format("Fail to send Get http request or interpret answer \"%1%\" : %2%") % lightUrl + % + e.what()).str(); + YADOMS_LOG(error) << "Fail to send Get http request or interpret answer " << lightUrl << " : " << e.what(); + throw; + } +} + +std::string CGamutOther::getName() +{ + return m_lightInformations.second.getName(); +} + +std::string CGamutOther::getType() +{ + return m_lightInformations.second.getType(); +} + +std::string CGamutOther::getModelId() +{ + return m_lightInformations.second.getModelId(); +} + +int CGamutOther::getDeviceId() +{ + return m_lightInformations.first; +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h new file mode 100644 index 0000000000..185b1fc0df --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h @@ -0,0 +1,39 @@ +#pragma once +#include "../../../UrlManager.h" +#include "../../Interfaces/ILight.h" +#include + +class CGamutOther : public ILight +{ +public: + + CGamutOther(boost::shared_ptr& urlManager, std::pair& lightInformations); + virtual ~CGamutOther() = default; + + void lightOn() override; + + void lightOff() override; + + void setLightColorUsingXy(const std::string& hexRgb) override; + + std::vector> getHistorizables() + override; + + std::string getName() override; + + std::string getType() override; + + std::string getModelId() override; + + int getDeviceId() override; + +private: + static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); + boost::shared_ptr m_urlManager; + static const std::string LightState; + static const std::string RgbColor; + boost::shared_ptr m_switch; + boost::shared_ptr m_rgb; + std::vector> m_historizables; + std::pair m_lightInformations; +}; From 91f4145aa1916c0df06b458a96e7cd2d397f5168 Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Sun, 6 Jun 2021 17:28:33 +0200 Subject: [PATCH 10/20] #713 add color control --- sources/plugins/PhilipsHue/CMakeLists.txt | 2 + .../PhilipsHue/Devices/Interfaces/ILight.h | 9 +- .../Devices/Lights/Models/GamutA.cpp | 29 +++-- .../PhilipsHue/Devices/Lights/Models/GamutA.h | 8 +- .../Devices/Lights/Models/GamutB.cpp | 29 +++-- .../PhilipsHue/Devices/Lights/Models/GamutB.h | 8 +- .../Devices/Lights/Models/GamutC.cpp | 17 ++- .../PhilipsHue/Devices/Lights/Models/GamutC.h | 8 +- .../Devices/Lights/Models/GamutNone.cpp | 30 ++++- .../Devices/Lights/Models/GamutNone.h | 8 +- .../Devices/Lights/Models/GamutOther.cpp | 30 +++-- .../Devices/Lights/Models/GamutOther.h | 8 +- .../Devices/Lights/Service/LightsService.cpp | 25 ++-- .../Devices/Utils/ColorTypeHelper.cpp | 109 +++++++++++------- .../Devices/Utils/ColorTypeHelper.h | 14 +-- .../PhilipsHue/Devices/Utils/LightModel.cpp | 29 +++++ .../PhilipsHue/Devices/Utils/LightModel.h | 29 +++++ .../PhilipsHue/Devices/Utils/LightType.cpp | 32 ++--- .../PhilipsHue/Devices/Utils/LightType.h | 32 ++--- .../Entities/HueLightInformations.cpp | 107 ++++++++--------- .../Entities/HueLightInformations.h | 13 ++- 21 files changed, 375 insertions(+), 201 deletions(-) create mode 100644 sources/plugins/PhilipsHue/Devices/Utils/LightModel.cpp create mode 100644 sources/plugins/PhilipsHue/Devices/Utils/LightModel.h diff --git a/sources/plugins/PhilipsHue/CMakeLists.txt b/sources/plugins/PhilipsHue/CMakeLists.txt index 427f8dcd08..544bc9a70a 100644 --- a/sources/plugins/PhilipsHue/CMakeLists.txt +++ b/sources/plugins/PhilipsHue/CMakeLists.txt @@ -81,6 +81,8 @@ set(PHILIPS_HUE_PLUGIN_DEVICES_UTILS_SOURCES Devices/Utils/HueLightsResponseType.h Devices/Utils/ColorConverter.h Devices/Utils/ColorConverter.cpp + Devices/Utils/LightModel.cpp + Devices/Utils/LightModel.h Devices/Utils/LightType.cpp Devices/Utils/LightType.h Devices/Utils/ColorType.h diff --git a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h index c1738e62ea..b164673fe8 100644 --- a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h +++ b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h @@ -18,9 +18,16 @@ class ILight virtual std::string getName() = 0; - virtual std::string getType() = 0; + virtual ELightType getType() = 0; virtual std::string getModelId() = 0; virtual int getDeviceId() = 0; + + virtual bool hasColorControl() = 0; + + virtual bool hasBrightnessControl() = 0; + + virtual bool hasTemperatureControl() = 0; + }; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp index 184d07a602..20635585ba 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp @@ -8,11 +8,11 @@ const std::string CGamutA::RgbColor("RgbColor"); CGamutA::CGamutA(boost::shared_ptr& urlManager, std::pair& lightInformations) : m_urlManager(urlManager), - m_switch(boost::make_shared(LightState)), - m_rgb(boost::make_shared( - RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), - m_historizables({ m_switch, m_rgb }), - m_lightInformations(lightInformations) + m_switch(boost::make_shared(LightState)), + m_rgb(boost::make_shared( + RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), + m_historizables({m_switch, m_rgb}), + m_lightInformations(lightInformations) { } @@ -80,7 +80,7 @@ std::string CGamutA::getName() return m_lightInformations.second.getName(); } -std::string CGamutA::getType() +ELightType CGamutA::getType() { return m_lightInformations.second.getType(); } @@ -93,4 +93,19 @@ std::string CGamutA::getModelId() int CGamutA::getDeviceId() { return m_lightInformations.first; -} \ No newline at end of file +} + +bool CGamutA::hasColorControl() +{ + return true; +} + +bool CGamutA::hasBrightnessControl() +{ + return true; +} + +bool CGamutA::hasTemperatureControl() +{ + return true; +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h index 19cdc2a56b..b4ddefb774 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h @@ -21,12 +21,18 @@ class CGamutA : public ILight std::string getName() override; - std::string getType() override; + ELightType getType() override; std::string getModelId() override; int getDeviceId() override; + bool hasColorControl() override; + + bool hasBrightnessControl() override; + + bool hasTemperatureControl() override; + private: static void setLightState(const std::string & lightUrl, shared::CDataContainer & body); boost::shared_ptr m_urlManager; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp index bc517573b7..840070f34e 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp @@ -8,11 +8,11 @@ const std::string CGamutB::RgbColor("RgbColor"); CGamutB::CGamutB(boost::shared_ptr& urlManager, std::pair& lightInformations) : m_urlManager(urlManager), - m_switch(boost::make_shared(LightState)), - m_rgb(boost::make_shared( - RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), - m_historizables({ m_switch, m_rgb }), - m_lightInformations(lightInformations) + m_switch(boost::make_shared(LightState)), + m_rgb(boost::make_shared( + RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), + m_historizables({m_switch, m_rgb}), + m_lightInformations(lightInformations) { } @@ -80,7 +80,7 @@ std::string CGamutB::getName() return m_lightInformations.second.getName(); } -std::string CGamutB::getType() +ELightType CGamutB::getType() { return m_lightInformations.second.getType(); } @@ -93,4 +93,19 @@ std::string CGamutB::getModelId() int CGamutB::getDeviceId() { return m_lightInformations.first; -} \ No newline at end of file +} + +bool CGamutB::hasColorControl() +{ + return true; +} + +bool CGamutB::hasBrightnessControl() +{ + return true; +} + +bool CGamutB::hasTemperatureControl() +{ + return true; +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h index f2c42a1338..6afb97eb6f 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h @@ -20,12 +20,18 @@ class CGamutB : public ILight std::string getName() override; - std::string getType() override; + ELightType getType() override; std::string getModelId() override; int getDeviceId() override; + bool hasColorControl() override; + + bool hasBrightnessControl() override; + + bool hasTemperatureControl() override; + private: static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); boost::shared_ptr m_urlManager; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp index f2e721605c..fbab1401d8 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp @@ -80,7 +80,7 @@ std::string CGamutC::getName() return m_lightInformations.second.getName(); } -std::string CGamutC::getType() +ELightType CGamutC::getType() { return m_lightInformations.second.getType(); } @@ -94,3 +94,18 @@ int CGamutC::getDeviceId() { return m_lightInformations.first; } + +bool CGamutC::hasColorControl() +{ + return true; +} + +bool CGamutC::hasBrightnessControl() +{ + return true; +} + +bool CGamutC::hasTemperatureControl() +{ + return true; +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h index 1a540d94a9..71b2663a48 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h @@ -21,12 +21,18 @@ class CGamutC : public ILight std::string getName() override; - std::string getType() override; + ELightType getType() override; std::string getModelId() override; int getDeviceId() override; + bool hasColorControl() override; + + bool hasBrightnessControl() override; + + bool hasTemperatureControl() override; + private : static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); boost::shared_ptr m_urlManager; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp index e051e65270..e4bc54d864 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp @@ -6,11 +6,12 @@ const std::string CGamutNone::LightState("STATE"); -CGamutNone::CGamutNone(boost::shared_ptr& urlManager, std::pair& lightInformations) +CGamutNone::CGamutNone(boost::shared_ptr& urlManager, + std::pair& lightInformations) : m_urlManager(urlManager), - m_switch(boost::make_shared(LightState)), - m_historizables({ m_switch}), - m_lightInformations(lightInformations) + m_switch(boost::make_shared(LightState)), + m_historizables({m_switch}), + m_lightInformations(lightInformations) { } @@ -78,7 +79,7 @@ std::string CGamutNone::getName() return m_lightInformations.second.getName(); } -std::string CGamutNone::getType() +ELightType CGamutNone::getType() { return m_lightInformations.second.getType(); } @@ -92,3 +93,22 @@ int CGamutNone::getDeviceId() { return m_lightInformations.first; } + +bool CGamutNone::hasColorControl() +{ + return false; +} + +bool CGamutNone::hasBrightnessControl() +{ + if (getType() == ELightType::kDIMMABLE_LIGHT || getType() == ELightType::kDIMMABLE_PLUGIN_IN_UNIT) + { + return true; + } + return false; +} + +bool CGamutNone::hasTemperatureControl() +{ + return false; +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h index 455fc60859..b10acd8343 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h @@ -21,12 +21,18 @@ class CGamutNone : public ILight std::string getName() override; - std::string getType() override; + ELightType getType() override; std::string getModelId() override; int getDeviceId() override; + bool hasColorControl() override; + + bool hasBrightnessControl() override; + + bool hasTemperatureControl() override; + private : static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); boost::shared_ptr m_urlManager; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp index 38edd6544f..135e2aa23c 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp @@ -6,13 +6,14 @@ const std::string CGamutOther::LightState("STATE"); const std::string CGamutOther::RgbColor("RgbColor"); -CGamutOther::CGamutOther(boost::shared_ptr& urlManager, std::pair& lightInformations) +CGamutOther::CGamutOther(boost::shared_ptr& urlManager, + std::pair& lightInformations) : m_urlManager(urlManager), - m_switch(boost::make_shared(LightState)), - m_rgb(boost::make_shared( - RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), - m_historizables({ m_switch, m_rgb }), - m_lightInformations(lightInformations) + m_switch(boost::make_shared(LightState)), + m_rgb(boost::make_shared( + RgbColor, shared::plugin::yPluginApi::EKeywordAccessMode::kGetSet)), + m_historizables({m_switch, m_rgb}), + m_lightInformations(lightInformations) { } @@ -80,7 +81,7 @@ std::string CGamutOther::getName() return m_lightInformations.second.getName(); } -std::string CGamutOther::getType() +ELightType CGamutOther::getType() { return m_lightInformations.second.getType(); } @@ -94,3 +95,18 @@ int CGamutOther::getDeviceId() { return m_lightInformations.first; } + +bool CGamutOther::hasColorControl() +{ + return true; +} + +bool CGamutOther::hasBrightnessControl() +{ + return true; +} + +bool CGamutOther::hasTemperatureControl() +{ + return true; +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h index 185b1fc0df..122a335824 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h @@ -21,12 +21,18 @@ class CGamutOther : public ILight std::string getName() override; - std::string getType() override; + ELightType getType() override; std::string getModelId() override; int getDeviceId() override; + bool hasColorControl() override; + + bool hasBrightnessControl() override; + + bool hasTemperatureControl() override; + private: static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); boost::shared_ptr m_urlManager; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp index 67ad5ff244..efb01f21be 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Service/LightsService.cpp @@ -32,9 +32,10 @@ std::map CLightsService::getAllLights() -> isNull(std::to_string(lightCounter) + "." + EHueLightResponseType::kType.toString())) { - hueLightInformations.setType( - response->get( - std::to_string(lightCounter) + "." + EHueLightResponseType::kType.toString())); + auto type = response->get( + std::to_string(lightCounter) + "." + EHueLightResponseType::kType.toString()); + hueLightInformations.setType(CColorTypeHelper::getLightType(type)); + hueLightInformations.setColorType(CColorTypeHelper::getColorType(response, type, lightCounter)); } if (response->exists(std::to_string(lightCounter) + "." + EHueLightResponseType::kName.toString()) && !response -> @@ -119,7 +120,7 @@ std::map CLightsService::getAllLights() response->get( std::to_string(lightCounter) + "." + EHueLightResponseType::kProductId.toString())); } - hueLightInformations.setColorType(CColorTypeHelper::getColorType(response)); + hueLightsInformations.insert({lightCounter, hueLightInformations}); lightCounter++; @@ -159,7 +160,8 @@ CHueLightInformations CLightsService::getLightAttributesAndState(const int id) -> isNull(EHueLightResponseType::kType.toString())) { - hueLightAttributesAndState.setType(response->get(EHueLightResponseType::kType.toString())); + auto type = response->get(EHueLightResponseType::kType.toString()); + hueLightAttributesAndState.setType(CColorTypeHelper::getLightType(type)); } if (response->exists(EHueLightResponseType::kName.toString()) && !response -> @@ -340,7 +342,8 @@ CHueSwUpdate CLightsService::getHueLightInformationsSwUpdate(boost::shared_ptr& response) +CHueCapabilities CLightsService::getHueLightInformationsCapabilities( + boost::shared_ptr& response) { CHueCapabilities capabilities; if (response->exists(EHueLightResponseType::kCapabilitiesCertified.toString()) && !response @@ -447,7 +450,7 @@ CHueConfig CLightsService::getHueLightInformationsConfig(boost::shared_ptr& response) + boost::shared_ptr& response) { CHueState state; // Fill State @@ -564,7 +567,7 @@ CHueState CLightsService::getHueLightInformationsStateById(int& lightId, } CHueSwUpdate CLightsService::getHueLightInformationsSwUpdateById(int& lightId, - boost::shared_ptr& response) + boost::shared_ptr& response) { CHueSwUpdate swUpdate; if (response->exists(std::to_string(lightId) + "." + EHueLightResponseType::kSwUpdateState.toString()) && @@ -588,8 +591,8 @@ CHueSwUpdate CLightsService::getHueLightInformationsSwUpdateById(int& lightId, } CHueCapabilities CLightsService::getHueLightInformationsCapabilitiesById(int& lightId, - boost::shared_ptr& - response) + boost::shared_ptr& + response) { CHueCapabilities capabilities; if (response->exists( @@ -686,7 +689,7 @@ CHueCapabilities CLightsService::getHueLightInformationsCapabilitiesById(int& li } CHueConfig CLightsService::getHueLightInformationsConfigById(int& lightId, - boost::shared_ptr& response) + boost::shared_ptr& response) { CHueConfig config; if (response->exists(std::to_string(lightId) + "." + EHueLightResponseType::kConfigArchetype.toString()) diff --git a/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.cpp b/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.cpp index 9e3aeaa89a..aba4564b29 100644 --- a/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.cpp +++ b/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.cpp @@ -9,55 +9,85 @@ const std::set CColorTypeHelper::GamutATypes{ "LST001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012", "LLC013", "LLC014" }; -const std::string CColorTypeHelper::OnOffLight{"on/off light"}; -const std::string CColorTypeHelper::OnOffPluginInUnit{"on/off plug-in unit"}; -const std::string CColorTypeHelper::DimmableLight{"dimmable light"}; -const std::string CColorTypeHelper::DimmablePluginInUnit{"dimmable plug-in unit"}; -const std::string CColorTypeHelper::ColorTemperatureLight{"color temperature light"}; -const std::string CColorTypeHelper::ColorLight{"color light"}; -const std::string CColorTypeHelper::ExtendedColorLight{"extended color light"}; -EColorType CColorTypeHelper::getColorType(boost::shared_ptr& response) +EColorType CColorTypeHelper::getColorType(boost::shared_ptr& response, std::string& type, + int& lightCounter) { - if (response->exists(EHueLightResponseType::kType.toString()) && !response - -> - isNull(EHueLightResponseType::kType.toString())) + boost::algorithm::to_lower(type); + if (type == ELightType::kON_OFF_LIGHT.toString() || type == ELightType::kON_OFF_PLUGIN_IN_UNIT.toString()) { - const auto type = response->get(EHueLightResponseType::kType.toString()); - if (type == OnOffLight || type == OnOffPluginInUnit) - { - return EColorType::kNONE; - } - if (type == DimmableLight || type == DimmablePluginInUnit) - { - return EColorType::kNONE; - } - if (type == ColorTemperatureLight) - { - return EColorType::kTEMPERATURE; - } - if (type == ColorLight) - { - return getGamutOrLegacyColorType(response, false); - } - if (type == ExtendedColorLight) - { - return getGamutOrLegacyColorType(response, true); - } + return EColorType::kNONE; + } + if (type == ELightType::kDIMMABLE_LIGHT.toString() || type == ELightType::kDIMMABLE_PLUGIN_IN_UNIT.toString()) + { + return EColorType::kNONE; + } + if (type == ELightType::kCOLOR_TEMPERATURE_LIGHT.toString()) + { + return EColorType::kTEMPERATURE; + } + if (type == ELightType::kCOLOR_LIGHT.toString()) + { + return getGamutOrLegacyColorType(response, false, lightCounter); + } + if (type == ELightType::kEXTENDED_COLOR_LIGHT.toString()) + { + return getGamutOrLegacyColorType(response, true, lightCounter); + } + + const auto message = "Could not determine Light color type"; + YADOMS_LOG(error) << message; + throw std::runtime_error(message); +} + +ELightType CColorTypeHelper::getLightType(std::string& type) +{ + boost::algorithm::to_lower(type); + if (type == ELightType::kON_OFF_LIGHT.toString()) + { + return ELightType::kON_OFF_LIGHT; + } + if (type == ELightType::kON_OFF_PLUGIN_IN_UNIT.toString()) + { + return ELightType::kON_OFF_PLUGIN_IN_UNIT; + } + if (type == ELightType::kDIMMABLE_LIGHT.toString()) + { + return ELightType::kDIMMABLE_LIGHT; + } + if (type == ELightType::kDIMMABLE_PLUGIN_IN_UNIT.toString()) + { + return ELightType::kDIMMABLE_PLUGIN_IN_UNIT; + } + if (type == ELightType::kCOLOR_TEMPERATURE_LIGHT.toString()) + { + return ELightType::kCOLOR_TEMPERATURE_LIGHT; } + if (type == ELightType::kCOLOR_LIGHT.toString()) + { + return ELightType::kCOLOR_LIGHT; + } + if (type == ELightType::kEXTENDED_COLOR_LIGHT.toString()) + { + return ELightType::kEXTENDED_COLOR_LIGHT; + } + const auto message = "Could not determine Light type"; YADOMS_LOG(error) << message; throw std::runtime_error(message); } -EColorType CColorTypeHelper::getGamutOrLegacyColorType(boost::shared_ptr& response, bool hasCt) +EColorType CColorTypeHelper::getGamutOrLegacyColorType(boost::shared_ptr& response, bool hasCt, + int& lightCounter) { // Try to get color Gamut from capabilities - if (response->exists(EHueLightResponseType::kCapabilitiesControlColorGamutType.toString()) && !response + if (response->exists( + std::to_string(lightCounter) + "." + EHueLightResponseType::kCapabilitiesControlColorGamutType.toString()) && ! + response -> - isNull(EHueLightResponseType::kCapabilitiesControlColorGamutType.toString())) + isNull(std::to_string(lightCounter) + "." + EHueLightResponseType::kCapabilitiesControlColorGamutType.toString())) { - const auto gamut = response->get( + const auto gamut = response->get(std::to_string(lightCounter) + "." + EHueLightResponseType::kCapabilitiesControlColorGamutType.toString()); if (gamut == "A") { @@ -74,11 +104,12 @@ EColorType CColorTypeHelper::getGamutOrLegacyColorType(boost::shared_ptrexists(EHueLightResponseType::kModelId.toString()) && !response + if (response->exists(std::to_string(lightCounter) + "." + EHueLightResponseType::kModelId.toString()) && !response -> - isNull(EHueLightResponseType::kModelId.toString())) + isNull(std::to_string(lightCounter) + "." + EHueLightResponseType::kModelId.toString())) { - const auto modelId = response->get(EHueLightResponseType::kModelId.toString()); + const auto modelId = response->get( + std::to_string(lightCounter) + "." + EHueLightResponseType::kModelId.toString()); if (GamutATypes.count(modelId)) { diff --git a/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.h b/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.h index f148af72cd..c65b9ace8d 100644 --- a/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.h +++ b/sources/plugins/PhilipsHue/Devices/Utils/ColorTypeHelper.h @@ -1,6 +1,7 @@ #pragma once #include "ColorType.h" #include "shared/DataContainer.h" +#include "LightType.h" class CColorTypeHelper { @@ -9,18 +10,13 @@ class CColorTypeHelper CColorTypeHelper() = default; virtual ~CColorTypeHelper() = default; - static EColorType getColorType(boost::shared_ptr& response); + static EColorType getColorType(boost::shared_ptr& response, std::string& type, int& lightCounter); + static ELightType getLightType(std::string& response); private: - static EColorType getGamutOrLegacyColorType(boost::shared_ptr& response, bool hasCt); + static EColorType getGamutOrLegacyColorType(boost::shared_ptr& response, bool hasCt, int& lightCounter); static const std::set GamutBTypes; static const std::set GamutCTypes; static const std::set GamutATypes; - static const std::string OnOffLight; - static const std::string OnOffPluginInUnit; - static const std::string DimmableLight; - static const std::string DimmablePluginInUnit; - static const std::string ColorTemperatureLight; - static const std::string ColorLight; - static const std::string ExtendedColorLight; + }; diff --git a/sources/plugins/PhilipsHue/Devices/Utils/LightModel.cpp b/sources/plugins/PhilipsHue/Devices/Utils/LightModel.cpp new file mode 100644 index 0000000000..081d23af97 --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Utils/LightModel.cpp @@ -0,0 +1,29 @@ +#include "LightModel.h" + +DECLARE_ENUM_IMPLEMENTATION(ELightModel, + ((LCT001)("LCT001")) + ((LCT002)("LCT002")) + ((LCT003)("LCT003")) + ((LCT007)("LCT007")) + ((LLM001)("LLM001")) + ((LCT010)("LCT010")) + ((LCT011)("LCT011")) + ((LCT012)("LCT012")) + ((LCT014)("LCT014")) + ((LCT015)("LCT015")) + ((LCT016)("LCT016")) + ((LLC020)("LLC020")) + ((LST002)("LST002")) + ((LCA003)("LCA003")) + ((LCB001)("LCB001")) + ((LST001)("LST001")) + ((LLC005)("LLC005")) + ((LLC006)("LLC006")) + ((LLC007)("LLC007")) + ((LLC010)("LLC010")) + ((LLC011)("LLC011")) + ((LLC012)("LLC012")) + ((LLC013)("LLC013")) + ((LLC014)("LLC014")) + ((Other)("Other")) +) diff --git a/sources/plugins/PhilipsHue/Devices/Utils/LightModel.h b/sources/plugins/PhilipsHue/Devices/Utils/LightModel.h new file mode 100644 index 0000000000..9f535042dc --- /dev/null +++ b/sources/plugins/PhilipsHue/Devices/Utils/LightModel.h @@ -0,0 +1,29 @@ +#pragma once +#include +DECLARE_ENUM_HEADER(ELightModel, + ((LCT001)) + ((LCT002)) + ((LCT003)) + ((LCT007)) + ((LLM001)) + ((LCT010)) + ((LCT011)) + ((LCT012)) + ((LCT014)) + ((LCT015)) + ((LCT016)) + ((LLC020)) + ((LST002)) + ((LCA003)) + ((LCB001)) + ((LST001)) + ((LLC005)) + ((LLC006)) + ((LLC007)) + ((LLC010)) + ((LLC011)) + ((LLC012)) + ((LLC013)) + ((LLC014)) + ((Other)) +) diff --git a/sources/plugins/PhilipsHue/Devices/Utils/LightType.cpp b/sources/plugins/PhilipsHue/Devices/Utils/LightType.cpp index 399b6895e9..e5ce92c777 100644 --- a/sources/plugins/PhilipsHue/Devices/Utils/LightType.cpp +++ b/sources/plugins/PhilipsHue/Devices/Utils/LightType.cpp @@ -1,29 +1,11 @@ #include "LightType.h" DECLARE_ENUM_IMPLEMENTATION(ELightType, - ((LCT001)("LCT001")) - ((LCT002)("LCT002")) - ((LCT003)("LCT003")) - ((LCT007)("LCT007")) - ((LLM001)("LLM001")) - ((LCT010)("LCT010")) - ((LCT011)("LCT011")) - ((LCT012)("LCT012")) - ((LCT014)("LCT014")) - ((LCT015)("LCT015")) - ((LCT016)("LCT016")) - ((LLC020)("LLC020")) - ((LST002)("LST002")) - ((LCA003)("LCA003")) - ((LCB001)("LCB001")) - ((LST001)("LST001")) - ((LLC005)("LLC005")) - ((LLC006)("LLC006")) - ((LLC007)("LLC007")) - ((LLC010)("LLC010")) - ((LLC011)("LLC011")) - ((LLC012)("LLC012")) - ((LLC013)("LLC013")) - ((LLC014)("LLC014")) - ((Other)("Other")) + ((ON_OFF_LIGHT)("on/off light")) + ((ON_OFF_PLUGIN_IN_UNIT)("on/off plug-in unit")) + ((DIMMABLE_LIGHT)("dimmable light")) + ((DIMMABLE_PLUGIN_IN_UNIT)("dimmable plug-in unit")) + ((COLOR_TEMPERATURE_LIGHT)("color temperature light")) + ((COLOR_LIGHT)("color light")) + ((EXTENDED_COLOR_LIGHT)("extended color light")) ) diff --git a/sources/plugins/PhilipsHue/Devices/Utils/LightType.h b/sources/plugins/PhilipsHue/Devices/Utils/LightType.h index e533487cf7..cef4abeb0c 100644 --- a/sources/plugins/PhilipsHue/Devices/Utils/LightType.h +++ b/sources/plugins/PhilipsHue/Devices/Utils/LightType.h @@ -1,29 +1,11 @@ #pragma once #include DECLARE_ENUM_HEADER(ELightType, - ((LCT001)) - ((LCT002)) - ((LCT003)) - ((LCT007)) - ((LLM001)) - ((LCT010)) - ((LCT011)) - ((LCT012)) - ((LCT014)) - ((LCT015)) - ((LCT016)) - ((LLC020)) - ((LST002)) - ((LCA003)) - ((LCB001)) - ((LST001)) - ((LLC005)) - ((LLC006)) - ((LLC007)) - ((LLC010)) - ((LLC011)) - ((LLC012)) - ((LLC013)) - ((LLC014)) - ((Other)) + ((ON_OFF_LIGHT)) + ((ON_OFF_PLUGIN_IN_UNIT)) + ((DIMMABLE_LIGHT)) + ((DIMMABLE_PLUGIN_IN_UNIT)) + ((COLOR_TEMPERATURE_LIGHT)) + ((COLOR_LIGHT)) + ((EXTENDED_COLOR_LIGHT)) ) diff --git a/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp b/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp index c74a351164..e91bfb690d 100644 --- a/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp +++ b/sources/plugins/PhilipsHue/Entities/HueLightInformations.cpp @@ -10,7 +10,7 @@ const CHueSwUpdate& CHueLightInformations::getSwUpdate() const return m_swUpdate; } -const std::string& CHueLightInformations::getType() const +const ELightType& CHueLightInformations::getType() const { return m_type; } @@ -20,7 +20,7 @@ const std::string& CHueLightInformations::getName() const return m_name; } -const ELightType& CHueLightInformations::getModelId() const +const ELightModel& CHueLightInformations::getModelId() const { return m_modelId; } @@ -70,6 +70,7 @@ const EColorType& CHueLightInformations::getColorType() const return m_colorType; } + void CHueLightInformations::setState(const CHueState& state) { m_state = state; @@ -80,7 +81,7 @@ void CHueLightInformations::setSwUpdate(const CHueSwUpdate& swUpdate) m_swUpdate = swUpdate; } -void CHueLightInformations::setType(const std::string& type) +void CHueLightInformations::setType(const ELightType& type) { m_type = type; } @@ -92,105 +93,105 @@ void CHueLightInformations::setName(const std::string& name) void CHueLightInformations::setModelId(const std::string& modelId) { - if (modelId == ELightType::kLCT001.toString()) + if (modelId == ELightModel::kLCT001.toString()) { - m_modelId = ELightType::kLCT001; + m_modelId = ELightModel::kLCT001; } - else if (modelId == ELightType::kLCT002.toString()) + else if (modelId == ELightModel::kLCT002.toString()) { - m_modelId = ELightType::kLCT002; + m_modelId = ELightModel::kLCT002; } - else if (modelId == ELightType::kLCT003.toString()) + else if (modelId == ELightModel::kLCT003.toString()) { - m_modelId = ELightType::kLCT003; + m_modelId = ELightModel::kLCT003; } - else if (modelId == ELightType::kLCT007.toString()) + else if (modelId == ELightModel::kLCT007.toString()) { - m_modelId = ELightType::kLCT007; + m_modelId = ELightModel::kLCT007; } - else if (modelId == ELightType::kLLM001.toString()) + else if (modelId == ELightModel::kLLM001.toString()) { - m_modelId = ELightType::kLLM001; + m_modelId = ELightModel::kLLM001; } - else if (modelId == ELightType::kLCT010.toString()) + else if (modelId == ELightModel::kLCT010.toString()) { - m_modelId = ELightType::kLCT010; + m_modelId = ELightModel::kLCT010; } - else if (modelId == ELightType::kLCT011.toString()) + else if (modelId == ELightModel::kLCT011.toString()) { - m_modelId = ELightType::kLCT011; + m_modelId = ELightModel::kLCT011; } - else if (modelId == ELightType::kLCT012.toString()) + else if (modelId == ELightModel::kLCT012.toString()) { - m_modelId = ELightType::kLCT012; + m_modelId = ELightModel::kLCT012; } - else if (modelId == ELightType::kLCT014.toString()) + else if (modelId == ELightModel::kLCT014.toString()) { - m_modelId = ELightType::kLCT014; + m_modelId = ELightModel::kLCT014; } - else if (modelId == ELightType::kLCT015.toString()) + else if (modelId == ELightModel::kLCT015.toString()) { - m_modelId = ELightType::kLCT015; + m_modelId = ELightModel::kLCT015; } - else if (modelId == ELightType::kLCT016.toString()) + else if (modelId == ELightModel::kLCT016.toString()) { - m_modelId = ELightType::kLCT016; + m_modelId = ELightModel::kLCT016; } - else if (modelId == ELightType::kLLC020.toString()) + else if (modelId == ELightModel::kLLC020.toString()) { - m_modelId = ELightType::kLLC020; + m_modelId = ELightModel::kLLC020; } - else if (modelId == ELightType::kLST002.toString()) + else if (modelId == ELightModel::kLST002.toString()) { - m_modelId = ELightType::kLST002; + m_modelId = ELightModel::kLST002; } - else if (modelId == ELightType::kLCA003.toString()) + else if (modelId == ELightModel::kLCA003.toString()) { - m_modelId = ELightType::kLCA003; + m_modelId = ELightModel::kLCA003; } - else if (modelId == ELightType::kLCB001.toString()) + else if (modelId == ELightModel::kLCB001.toString()) { - m_modelId = ELightType::kLCB001; + m_modelId = ELightModel::kLCB001; } - else if (modelId == ELightType::kLST001.toString()) + else if (modelId == ELightModel::kLST001.toString()) { - m_modelId = ELightType::kLST001; + m_modelId = ELightModel::kLST001; } - else if (modelId == ELightType::kLLC005.toString()) + else if (modelId == ELightModel::kLLC005.toString()) { - m_modelId = ELightType::kLLC005; + m_modelId = ELightModel::kLLC005; } - else if (modelId == ELightType::kLLC006.toString()) + else if (modelId == ELightModel::kLLC006.toString()) { - m_modelId = ELightType::kLLC006; + m_modelId = ELightModel::kLLC006; } - else if (modelId == ELightType::kLLC007.toString()) + else if (modelId == ELightModel::kLLC007.toString()) { - m_modelId = ELightType::kLLC007; + m_modelId = ELightModel::kLLC007; } - else if (modelId == ELightType::kLLC010.toString()) + else if (modelId == ELightModel::kLLC010.toString()) { - m_modelId = ELightType::kLLC010; + m_modelId = ELightModel::kLLC010; } - else if (modelId == ELightType::kLLC011.toString()) + else if (modelId == ELightModel::kLLC011.toString()) { - m_modelId = ELightType::kLLC011; + m_modelId = ELightModel::kLLC011; } - else if (modelId == ELightType::kLLC012.toString()) + else if (modelId == ELightModel::kLLC012.toString()) { - m_modelId = ELightType::kLLC012; + m_modelId = ELightModel::kLLC012; } - else if (modelId == ELightType::kLLC013.toString()) + else if (modelId == ELightModel::kLLC013.toString()) { - m_modelId = ELightType::kLLC013; + m_modelId = ELightModel::kLLC013; } - else if (modelId == ELightType::kLLC014.toString()) + else if (modelId == ELightModel::kLLC014.toString()) { - m_modelId = ELightType::kLLC014; + m_modelId = ELightModel::kLLC014; } else { - m_modelId = ELightType::kOther; + m_modelId = ELightModel::kOther; } } @@ -237,4 +238,4 @@ void CHueLightInformations::setProductId(const std::string& productId) void CHueLightInformations::setColorType(const EColorType& colorType) { m_colorType = colorType; -} +} \ No newline at end of file diff --git a/sources/plugins/PhilipsHue/Entities/HueLightInformations.h b/sources/plugins/PhilipsHue/Entities/HueLightInformations.h index d99324ec9a..c1e6784b6f 100644 --- a/sources/plugins/PhilipsHue/Entities/HueLightInformations.h +++ b/sources/plugins/PhilipsHue/Entities/HueLightInformations.h @@ -3,8 +3,9 @@ #include "HueSwUpdate.h" #include "HueCapabilities.h" #include "HueConfig.h" -#include "../Devices/Utils/LightType.h" +#include "../Devices/Utils/LightModel.h" #include "../Devices/Utils/ColorType.h" +#include "../Devices/Utils/LightType.h" class CHueLightInformations { @@ -16,9 +17,9 @@ class CHueLightInformations const CHueState& getState() const; const CHueSwUpdate& getSwUpdate() const; - const std::string& getType() const; + const ELightType& getType() const; const std::string& getName() const; - const ELightType& getModelId() const; + const ELightModel& getModelId() const; const std::string& getManufacturerName() const; const std::string& getProductName() const; const CHueCapabilities& getCapabilities() const; @@ -31,7 +32,7 @@ class CHueLightInformations void setState(const CHueState& state); void setSwUpdate(const CHueSwUpdate& swUpdate); - void setType(const std::string& type); + void setType(const ELightType& type); void setName(const std::string& name); void setModelId(const std::string& modelId); void setManufacturerName(const std::string& manufacturerName); @@ -47,9 +48,9 @@ class CHueLightInformations private: CHueState m_state; CHueSwUpdate m_swUpdate; - std::string m_type; + ELightType m_type; std::string m_name; - ELightType m_modelId; + ELightModel m_modelId; std::string m_manufacturerName; std::string m_productName; CHueCapabilities m_capabilities; From 0228f18f53cfffbf1f9a4ba200ab609bde17b00b Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Sun, 6 Jun 2021 19:55:29 +0200 Subject: [PATCH 11/20] #734 Historize light state when detecting/ truning on/off a light --- .../PhilipsHue/Devices/Interfaces/ILight.h | 2 ++ .../PhilipsHue/Devices/Lights/Models/GamutA.cpp | 5 +++++ .../PhilipsHue/Devices/Lights/Models/GamutA.h | 2 ++ .../PhilipsHue/Devices/Lights/Models/GamutB.cpp | 5 +++++ .../PhilipsHue/Devices/Lights/Models/GamutB.h | 2 ++ .../PhilipsHue/Devices/Lights/Models/GamutC.cpp | 5 +++++ .../PhilipsHue/Devices/Lights/Models/GamutC.h | 2 ++ .../Devices/Lights/Models/GamutNone.cpp | 5 +++++ .../Devices/Lights/Models/GamutNone.h | 2 ++ .../Devices/Lights/Models/GamutOther.cpp | 5 +++++ .../Devices/Lights/Models/GamutOther.h | 2 ++ sources/plugins/PhilipsHue/PhilipsHue.cpp | 17 ++++++++++++++--- sources/plugins/PhilipsHue/PhilipsHue.h | 4 ++++ 13 files changed, 55 insertions(+), 3 deletions(-) diff --git a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h index b164673fe8..3d50cba74d 100644 --- a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h +++ b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h @@ -20,6 +20,8 @@ class ILight virtual ELightType getType() = 0; + virtual bool getState() = 0; + virtual std::string getModelId() = 0; virtual int getDeviceId() = 0; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp index 20635585ba..5dc61c67a9 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp @@ -90,6 +90,11 @@ std::string CGamutA::getModelId() return m_lightInformations.second.getModelId(); } +bool CGamutA::getState() +{ + return m_lightInformations.second.getState().isOn(); +} + int CGamutA::getDeviceId() { return m_lightInformations.first; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h index b4ddefb774..b82e5fbc67 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h @@ -25,6 +25,8 @@ class CGamutA : public ILight std::string getModelId() override; + bool getState() override; + int getDeviceId() override; bool hasColorControl() override; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp index 840070f34e..57579121d4 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp @@ -90,6 +90,11 @@ std::string CGamutB::getModelId() return m_lightInformations.second.getModelId(); } +bool CGamutB::getState() +{ + return m_lightInformations.second.getState().isOn(); +} + int CGamutB::getDeviceId() { return m_lightInformations.first; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h index 6afb97eb6f..6ba596fda6 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h @@ -24,6 +24,8 @@ class CGamutB : public ILight std::string getModelId() override; + bool getState() override; + int getDeviceId() override; bool hasColorControl() override; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp index fbab1401d8..e1b0f357cc 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp @@ -90,6 +90,11 @@ std::string CGamutC::getModelId() return m_lightInformations.second.getModelId(); } +bool CGamutC::getState() +{ + return m_lightInformations.second.getState().isOn(); +} + int CGamutC::getDeviceId() { return m_lightInformations.first; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h index 71b2663a48..6bf149dab5 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h @@ -25,6 +25,8 @@ class CGamutC : public ILight std::string getModelId() override; + bool getState() override; + int getDeviceId() override; bool hasColorControl() override; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp index e4bc54d864..d2824838ef 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp @@ -89,6 +89,11 @@ std::string CGamutNone::getModelId() return m_lightInformations.second.getModelId(); } +bool CGamutNone::getState() +{ + return m_lightInformations.second.getState().isOn(); +} + int CGamutNone::getDeviceId() { return m_lightInformations.first; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h index b10acd8343..0677a7328d 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h @@ -25,6 +25,8 @@ class CGamutNone : public ILight std::string getModelId() override; + bool getState() override; + int getDeviceId() override; bool hasColorControl() override; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp index 135e2aa23c..6db17701b2 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp @@ -91,6 +91,11 @@ std::string CGamutOther::getModelId() return m_lightInformations.second.getModelId(); } +bool CGamutOther::getState() +{ + return m_lightInformations.second.getState().isOn(); +} + int CGamutOther::getDeviceId() { return m_lightInformations.first; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h index 122a335824..4d801fdc72 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h @@ -25,6 +25,8 @@ class CGamutOther : public ILight std::string getModelId() override; + bool getState() override; + int getDeviceId() override; bool hasColorControl() override; diff --git a/sources/plugins/PhilipsHue/PhilipsHue.cpp b/sources/plugins/PhilipsHue/PhilipsHue.cpp index e57a268a7c..1ecb396ab7 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.cpp +++ b/sources/plugins/PhilipsHue/PhilipsHue.cpp @@ -82,10 +82,12 @@ void CPhilipsHue::doWork(boost::shared_ptr api) if (command->getBody() == "1") { m_detectedLights[detectedLightId]->lightOn(); + historizeLightState(lightName, true); } else { m_detectedLights[detectedLightId]->lightOff(); + historizeLightState(lightName, false); } } else if (command->getKeyword() == RgbColor) @@ -281,6 +283,7 @@ void CPhilipsHue::closeReadingBridgeButtonState() void CPhilipsHue::declareDeviceByBrdige() { + auto keywordsToHistorize = m_historizers; for (auto i = 0; i < m_bridges.size(); i++) { std::map bridgeId; @@ -288,14 +291,16 @@ void CPhilipsHue::declareDeviceByBrdige() for (auto& light : m_detectedLights) { - YADOMS_LOG(information) << "Creating the device :" << light->getName(); - if (!m_api->deviceExists(light->getName())) + auto lightName = light->getName(); + YADOMS_LOG(information) << "Creating the device :" << lightName; + if (!m_api->deviceExists(lightName)) { - m_api->declareDevice(light->getName(), + m_api->declareDevice(lightName, light->getType(), light->getModelId(), light->getHistorizables(), shared::CDataContainer::make(bridgeId)); + historizeLightState(lightName, light->getState()); } } } @@ -348,3 +353,9 @@ int CPhilipsHue::getLightId(std::string& lightName) return it->get()->getDeviceId(); } + +void CPhilipsHue::historizeLightState(std::string& lightName, bool state) +{ + m_switch->set(state); + m_api->historizeData(lightName, m_switch); +} diff --git a/sources/plugins/PhilipsHue/PhilipsHue.h b/sources/plugins/PhilipsHue/PhilipsHue.h index e625d599d2..a35f25f4b1 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.h +++ b/sources/plugins/PhilipsHue/PhilipsHue.h @@ -66,4 +66,8 @@ class CPhilipsHue : public plugin_cpp_api::IPlugin static const std::string RgbColor; int getLightId(std::string& lightName); + + void historizeLightState(std::string& lightName, bool state); + + }; From 12aef261a6f7f8f06f3685aeafc9b276508efd4c Mon Sep 17 00:00:00 2001 From: Oussama DAHMAZ Date: Sun, 6 Jun 2021 19:57:02 +0200 Subject: [PATCH 12/20] #734 update changelog --- sources/plugins/PhilipsHue/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sources/plugins/PhilipsHue/changelog.md b/sources/plugins/PhilipsHue/changelog.md index 6c53a73154..6ef1048f49 100644 --- a/sources/plugins/PhilipsHue/changelog.md +++ b/sources/plugins/PhilipsHue/changelog.md @@ -1,4 +1,5 @@ ### 1.1.0 +* Historize light state when detecting / turning on/off a light #734 * Add interfaces by device model #713 ### 1.0.0 * First release From 4eecfe3f80735f586a5d4a37434a2bcbbdfc8cfc Mon Sep 17 00:00:00 2001 From: oussama Dahmaz Date: Mon, 13 Sep 2021 10:15:32 +0200 Subject: [PATCH 13/20] #712 : Change friendly hue light name (#739) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * #712 : Change friendly hue light name * Try to fix build Co-authored-by: Sébastien Gallou --- sources/cmake/mac.cmake | 3 +- sources/external-libs/curl/CMakeLists.txt | 2 +- sources/external-libs/curlpp/CMakeLists.txt | 6 ++-- .../PhilipsHue/Devices/Interfaces/ILight.h | 1 + .../Devices/Lights/Models/GamutA.cpp | 22 ++++++++++++ .../PhilipsHue/Devices/Lights/Models/GamutA.h | 2 ++ .../Devices/Lights/Models/GamutB.cpp | 22 ++++++++++++ .../PhilipsHue/Devices/Lights/Models/GamutB.h | 2 ++ .../Devices/Lights/Models/GamutC.cpp | 22 ++++++++++++ .../PhilipsHue/Devices/Lights/Models/GamutC.h | 2 ++ .../Devices/Lights/Models/GamutNone.cpp | 22 ++++++++++++ .../Devices/Lights/Models/GamutNone.h | 2 ++ .../Devices/Lights/Models/GamutOther.cpp | 22 ++++++++++++ .../Devices/Lights/Models/GamutOther.h | 2 ++ sources/plugins/PhilipsHue/PhilipsHue.cpp | 34 ++++++++++++++++++- sources/plugins/PhilipsHue/changelog.md | 2 ++ sources/plugins/PhilipsHue/locales/en.json | 12 +++++++ sources/plugins/PhilipsHue/locales/fr.json | 14 +++++++- sources/plugins/PhilipsHue/package.in.json | 3 ++ 19 files changed, 190 insertions(+), 7 deletions(-) diff --git a/sources/cmake/mac.cmake b/sources/cmake/mac.cmake index 31166f02b1..c6eb79b695 100644 --- a/sources/cmake/mac.cmake +++ b/sources/cmake/mac.cmake @@ -13,9 +13,10 @@ include(CMakeFindFrameworks) cmake_find_frameworks(IOKit) cmake_find_frameworks(CoreFoundation) cmake_find_frameworks(Carbon) +cmake_find_frameworks(SystemConfiguration) if (IOKit_FRAMEWORKS) - set(IOKIT_LIBRARY "-framework IOKit -framework CoreFoundation -framework CoreServices" CACHE FILEPATH "IOKit framework" FORCE) + set(IOKIT_LIBRARY "-framework IOKit -framework CoreFoundation -framework CoreServices -framework SystemConfiguration" CACHE FILEPATH "IOKit framework" FORCE) set(IOKIT_FOUND 1) endif (IOKit_FRAMEWORKS) diff --git a/sources/external-libs/curl/CMakeLists.txt b/sources/external-libs/curl/CMakeLists.txt index f162277d45..ed487d8380 100644 --- a/sources/external-libs/curl/CMakeLists.txt +++ b/sources/external-libs/curl/CMakeLists.txt @@ -89,7 +89,7 @@ if(CMAKE_TOOLCHAIN_FILE) endif(CMAKE_TOOLCHAIN_FILE) ExternalProject_Add(curl_build - URL https://curl.se/download/curl-7.76.1.zip + URL https://curl.se/download/curl-7.78.0.zip PATCH_COMMAND ${CURL_PATHCMD} PREFIX ${CURL_ROOT} CMAKE_ARGS ${CURL_BUILD_ARGS} diff --git a/sources/external-libs/curlpp/CMakeLists.txt b/sources/external-libs/curlpp/CMakeLists.txt index 4a0a88d624..239d15c865 100644 --- a/sources/external-libs/curlpp/CMakeLists.txt +++ b/sources/external-libs/curlpp/CMakeLists.txt @@ -48,7 +48,7 @@ message("CURLPP : cross compilation (toolchain:${CMAKE_TOOLCHAIN_FILE}, with ${C list(APPEND CURLPP_BUILD_ARGS "-DCC_RPI_GXX=${CC_RPI_GXX}") endif() - #append all potentials dependecnies that exteranl project may need (openssl mostly) + #append all potentials dependencies that external project may need (openssl mostly) if(OPENSSL_ROOT) list(APPEND CURLPP_BUILD_ARGS "-DOPENSSL_ROOT_DIR=${OPENSSL_ROOT}") endif() @@ -62,7 +62,7 @@ message("CURLPP : cross compilation (toolchain:${CMAKE_TOOLCHAIN_FILE}, with ${C list(APPEND CURLPP_BUILD_ARGS "-DPython2_ROOT=${Python2_ROOT}") endif() if(Python3_ROOT) - list(APPEND CURLPP_BUILD_ARGS "-DPython2_ROOT=${Python3_ROOT}") + list(APPEND CURLPP_BUILD_ARGS "-DPython3_ROOT=${Python3_ROOT}") endif() list(APPEND CURLPP_BUILD_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") @@ -73,7 +73,7 @@ endif(CMAKE_TOOLCHAIN_FILE) ExternalProject_Add (curlpp_build DEPENDS curl_build GIT_REPOSITORY https://github.com/jpbarrette/curlpp.git - GIT_TAG 02e4a60e7d541bbfd11bf21bbb76bd584863b5df + GIT_TAG a67c73dde2c5d50b3dd3f898b8c185c23de827f3 GIT_SHALLOW ON GIT_CONFIG advice.detachedHead=false PATCH_COMMAND ${CURLPP_PATHCMD} diff --git a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h index 3d50cba74d..b287a1af18 100644 --- a/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h +++ b/sources/plugins/PhilipsHue/Devices/Interfaces/ILight.h @@ -32,4 +32,5 @@ class ILight virtual bool hasTemperatureControl() = 0; + virtual void rename(std::string& newLightName) = 0; }; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp index 5dc61c67a9..9a7b9b2c33 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.cpp @@ -114,3 +114,25 @@ bool CGamutA::hasTemperatureControl() { return true; } + +void CGamutA::rename(std::string& newLightName) +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kGetLightAttributesAndState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("name", newLightName); + + try + { + const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); + } + catch (std::exception& e) + { + const auto message = (boost::format("Fail to send Put http request or interpret answer \"%1%\" : %2%") % lightUrl + % + e.what()).str(); + YADOMS_LOG(error) << "Fail to send Put http request or interpret answer " << lightUrl << " : " << e.what(); + throw; + } +} \ No newline at end of file diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h index b82e5fbc67..fc0d6bc13e 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutA.h @@ -35,6 +35,8 @@ class CGamutA : public ILight bool hasTemperatureControl() override; + void rename(std::string& newLightName) override; + private: static void setLightState(const std::string & lightUrl, shared::CDataContainer & body); boost::shared_ptr m_urlManager; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp index 57579121d4..55d8f5d885 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.cpp @@ -114,3 +114,25 @@ bool CGamutB::hasTemperatureControl() { return true; } + +void CGamutB::rename(std::string& newLightName) +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kGetLightAttributesAndState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("name", newLightName); + + try + { + const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); + } + catch (std::exception& e) + { + const auto message = (boost::format("Fail to send Put http request or interpret answer \"%1%\" : %2%") % lightUrl + % + e.what()).str(); + YADOMS_LOG(error) << "Fail to send Put http request or interpret answer " << lightUrl << " : " << e.what(); + throw; + } +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h index 6ba596fda6..8f5c9a1865 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutB.h @@ -34,6 +34,8 @@ class CGamutB : public ILight bool hasTemperatureControl() override; + void rename(std::string& newLightName) override; + private: static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); boost::shared_ptr m_urlManager; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp index e1b0f357cc..5190813193 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.cpp @@ -114,3 +114,25 @@ bool CGamutC::hasTemperatureControl() { return true; } + +void CGamutC::rename(std::string& newLightName) +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kGetLightAttributesAndState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("name", newLightName); + + try + { + const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); + } + catch (std::exception& e) + { + const auto message = (boost::format("Fail to send Put http request or interpret answer \"%1%\" : %2%") % lightUrl + % + e.what()).str(); + YADOMS_LOG(error) << "Fail to send Put http request or interpret answer " << lightUrl << " : " << e.what(); + throw; + } +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h index 6bf149dab5..795f5b0f9c 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutC.h @@ -35,6 +35,8 @@ class CGamutC : public ILight bool hasTemperatureControl() override; + void rename(std::string& newLightName) override; + private : static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); boost::shared_ptr m_urlManager; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp index d2824838ef..1495b73f17 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.cpp @@ -117,3 +117,25 @@ bool CGamutNone::hasTemperatureControl() { return false; } + +void CGamutNone::rename(std::string& newLightName) +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kGetLightAttributesAndState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("name", newLightName); + + try + { + const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); + } + catch (std::exception& e) + { + const auto message = (boost::format("Fail to send Put http request or interpret answer \"%1%\" : %2%") % lightUrl + % + e.what()).str(); + YADOMS_LOG(error) << "Fail to send Put http request or interpret answer " << lightUrl << " : " << e.what(); + throw; + } +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h index 0677a7328d..d019b8f585 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutNone.h @@ -35,6 +35,8 @@ class CGamutNone : public ILight bool hasTemperatureControl() override; + void rename(std::string& newLightName) override; + private : static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); boost::shared_ptr m_urlManager; diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp index 6db17701b2..acc7143dd8 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.cpp @@ -115,3 +115,25 @@ bool CGamutOther::hasTemperatureControl() { return true; } + +void CGamutOther::rename(std::string& newLightName) +{ + const auto urlPatternPath = m_urlManager->getUrlPatternPath(CUrlManager::kGetLightAttributesAndState, m_lightInformations.first); + const auto lightUrl = m_urlManager->getPatternUrl(urlPatternPath); + + shared::CDataContainer body; + body.set("name", newLightName); + + try + { + const auto response = shared::http::CHttpRestHelpers::sendJsonPutRequest(lightUrl, body.serialize()); + } + catch (std::exception& e) + { + const auto message = (boost::format("Fail to send Put http request or interpret answer \"%1%\" : %2%") % lightUrl + % + e.what()).str(); + YADOMS_LOG(error) << "Fail to send Put http request or interpret answer " << lightUrl << " : " << e.what(); + throw; + } +} diff --git a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h index 4d801fdc72..31555db4e6 100644 --- a/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h +++ b/sources/plugins/PhilipsHue/Devices/Lights/Models/GamutOther.h @@ -35,6 +35,8 @@ class CGamutOther : public ILight bool hasTemperatureControl() override; + void rename(std::string& newLightName) override; + private: static void setLightState(const std::string& lightUrl, shared::CDataContainer& body); boost::shared_ptr m_urlManager; diff --git a/sources/plugins/PhilipsHue/PhilipsHue.cpp b/sources/plugins/PhilipsHue/PhilipsHue.cpp index 1ecb396ab7..ef2d4cbec5 100644 --- a/sources/plugins/PhilipsHue/PhilipsHue.cpp +++ b/sources/plugins/PhilipsHue/PhilipsHue.cpp @@ -156,6 +156,38 @@ void CPhilipsHue::doWork(boost::shared_ptr api) } break; } + case yApi::IYPluginApi::kGetDeviceConfigurationSchemaRequest: + { + + auto body = shared::CDataContainer::make(); + shared::CDataContainer options; + options.set("type", "string"); + options.set("i18nKey", "Hue"); + body->set("HueNewLightNameToBridge", options); + + auto deviceConfigurationSchemaRequest = m_api + ->getEventHandler().getEventData>(); + + deviceConfigurationSchemaRequest->sendSuccess(body); + break; + } + case yApi::IYPluginApi::kSetDeviceConfiguration: + { + auto deviceConfiguration = api->getEventHandler().getEventData>(); + auto config = deviceConfiguration->configuration(); + YADOMS_LOG(debug) << "Configuration = " << config->serialize(); + auto newLightName = config->get("HueNewLightNameToBridge"); + + if(!newLightName.empty()) + { + auto lightName = deviceConfiguration->name(); + const auto lightId = getLightId(lightName); + m_detectedLights[lightId]->rename(newLightName); + } + break; + } default: { YADOMS_LOG(error) << "Unknown or unsupported message id " << m_api->getEventHandler().getEventId(); @@ -296,7 +328,7 @@ void CPhilipsHue::declareDeviceByBrdige() if (!m_api->deviceExists(lightName)) { m_api->declareDevice(lightName, - light->getType(), + "HueLight", light->getModelId(), light->getHistorizables(), shared::CDataContainer::make(bridgeId)); diff --git a/sources/plugins/PhilipsHue/changelog.md b/sources/plugins/PhilipsHue/changelog.md index 6ef1048f49..de8341ad69 100644 --- a/sources/plugins/PhilipsHue/changelog.md +++ b/sources/plugins/PhilipsHue/changelog.md @@ -1,3 +1,5 @@ +### 1.1.1 +* [712](https://github.com/Yadoms/yadoms/issues/712) : Change friendly hue light name ### 1.1.0 * Historize light state when detecting / turning on/off a light #734 * Add interfaces by device model #713 diff --git a/sources/plugins/PhilipsHue/locales/en.json b/sources/plugins/PhilipsHue/locales/en.json index 317fee12b2..cbf1cbab34 100644 --- a/sources/plugins/PhilipsHue/locales/en.json +++ b/sources/plugins/PhilipsHue/locales/en.json @@ -41,5 +41,17 @@ "searchForBridge": { "name": "Search for Philips Hue bridge" } + }, + "deviceConfiguration": { + "dynamicConfigurationSchema": { + "schemas": { + "HueLight": { + "Hue": { + "name": "Hue Name", + "description": "Change hue name on bridge" + } + } + } + } } } \ No newline at end of file diff --git a/sources/plugins/PhilipsHue/locales/fr.json b/sources/plugins/PhilipsHue/locales/fr.json index 10955f2693..47e24beb4d 100644 --- a/sources/plugins/PhilipsHue/locales/fr.json +++ b/sources/plugins/PhilipsHue/locales/fr.json @@ -41,5 +41,17 @@ "searchForBridge": { "name": "Rechercher Philips Hue bridge" } + }, + "deviceConfiguration": { + "dynamicConfigurationSchema": { + "schemas": { + "HueLight": { + "Hue": { + "name": "Le nom du hue", + "description": "Changer le nom du hue au niveau du pont hue" + } + } + } + } } -} +} \ No newline at end of file diff --git a/sources/plugins/PhilipsHue/package.in.json b/sources/plugins/PhilipsHue/package.in.json index b23cc62f35..2fa8bcccc7 100644 --- a/sources/plugins/PhilipsHue/package.in.json +++ b/sources/plugins/PhilipsHue/package.in.json @@ -41,5 +41,8 @@ "searchForBridge": { "iconClass": "fa fa-spinner fa-spin" } + }, + "deviceConfiguration": { + "dynamicConfigurationSchema": "true" } } \ No newline at end of file From 3438ac01b646116baa57c882dafa2f2c41be89be Mon Sep 17 00:00:00 2001 From: sgallou Date: Wed, 22 Sep 2021 08:27:46 +0200 Subject: [PATCH 14/20] Fix external projects build # Conflicts: # sources/external-libs/curlpp/CMakeLists.txt # sources/external-libs/oatpp-websocket/CMakeLists.txt # sources/external-libs/oatpp/CMakeLists.txt --- sources/external-libs/curlpp/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/sources/external-libs/curlpp/CMakeLists.txt b/sources/external-libs/curlpp/CMakeLists.txt index 239d15c865..517437c04b 100644 --- a/sources/external-libs/curlpp/CMakeLists.txt +++ b/sources/external-libs/curlpp/CMakeLists.txt @@ -74,7 +74,6 @@ ExternalProject_Add (curlpp_build DEPENDS curl_build GIT_REPOSITORY https://github.com/jpbarrette/curlpp.git GIT_TAG a67c73dde2c5d50b3dd3f898b8c185c23de827f3 - GIT_SHALLOW ON GIT_CONFIG advice.detachedHead=false PATCH_COMMAND ${CURLPP_PATHCMD} PREFIX ${CURLPP_ROOT} From d7c1063f96149dcbde2821f99bd8b6ff90369ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gallou?= Date: Wed, 9 Mar 2022 11:52:35 +0100 Subject: [PATCH 15/20] Update EnOcean plugin (report some changes from RestApiv2 branch) --- sources/plugins/EnOcean/EnOcean.cpp | 120 +++++++++--------- sources/plugins/EnOcean/EnOcean.h | 43 ++++--- .../EnOcean/message/MessageHelpers.cpp | 8 +- .../plugins/EnOcean/message/MessageHelpers.h | 2 +- ...UTE_GigaConceptReversedReceivedMessage.cpp | 10 +- .../UTE_GigaConceptReversedReceivedMessage.h | 10 +- .../EnOcean/message/UTE_ReceivedMessage.cpp | 6 - .../EnOcean/message/UTE_ReceivedMessage.h | 12 +- .../hardCoded/Profile_D2_01_Common.cpp | 13 +- 9 files changed, 105 insertions(+), 119 deletions(-) diff --git a/sources/plugins/EnOcean/EnOcean.cpp b/sources/plugins/EnOcean/EnOcean.cpp index 5917cc7024..8eabd5fa36 100644 --- a/sources/plugins/EnOcean/EnOcean.cpp +++ b/sources/plugins/EnOcean/EnOcean.cpp @@ -8,6 +8,7 @@ #include "4BSTeachinVariant2.h" #include "profiles/bitsetHelpers.hpp" #include +#include #include "ProfileHelper.h" #include "message/CommonCommandSendMessage.h" #include "message/UTE_AnswerSendMessage.h" @@ -131,7 +132,8 @@ void CEnOcean::doWork(boost::shared_ptr api) case kEvtPortConnection: { - const auto notification = m_api->getEventHandler().getEventData>(); + const auto notification = m_api->getEventHandler().getEventData>(); if (notification && notification->isConnected()) processConnectionEvent(); @@ -214,7 +216,7 @@ void CEnOcean::doWork(boost::shared_ptr api) void CEnOcean::loadAllDevices() { - auto devices = m_api->getAllDevices(); + const auto devices = m_api->getAllDevices(); for (const auto& deviceId : devices) { try @@ -291,8 +293,8 @@ boost::shared_ptr CEnOcean::createDevice(const std::string& deviceId, const CProfileHelper& profileHelper) const { auto device = CRorgs::createRorg(profileHelper.rorg())->createFunc(profileHelper.func())->createType(profileHelper.type(), - deviceId, - m_api); + deviceId, + m_api); return device; } @@ -314,7 +316,7 @@ std::string CEnOcean::generateModel(const std::string& model, return generatedModel; } -void CEnOcean::processDeviceCommand(const boost::shared_ptr command) +void CEnOcean::processDeviceCommand(const boost::shared_ptr& command) { if (!m_port) { @@ -381,7 +383,7 @@ void CEnOcean::protocolErrorProcess() boost::posix_time::seconds(10)); } -void CEnOcean::processUnConnectionEvent(boost::shared_ptr notification) +void CEnOcean::processUnConnectionEvent(const boost::shared_ptr& notification) { YADOMS_LOG(information) << "EnOcean connection was lost"; if (notification) @@ -452,11 +454,11 @@ void CEnOcean::processDeviceConfiguration(const std::string& deviceId, } } -void CEnOcean::processDataReceived(boost::shared_ptr message) +void CEnOcean::processDataReceived(const boost::shared_ptr& message) { try { - switch (message->header().packetType()) + switch (message->header().packetType()) // NOLINT(clang-diagnostic-switch-enum) { case message::RADIO_ERP1: processRadioErp1(message); @@ -489,7 +491,7 @@ void CEnOcean::addSignalPower(std::vectordeclareKeyword(deviceId, m_signalPowerKeyword); m_signalPowerKeyword->set(signalPower); - keywords.push_back(m_signalPowerKeyword); + keywords.emplace_back(m_signalPowerKeyword); } int CEnOcean::dbmToSignalPower(int dBm) @@ -514,7 +516,7 @@ int CEnOcean::dbmToSignalPower(int dBm) void CEnOcean::processRadioErp1(boost::shared_ptr esp3Packet) { - message::CRadioErp1ReceivedMessage erp1Message(esp3Packet); + message::CRadioErp1ReceivedMessage erp1Message(std::move(esp3Packet)); if (erp1Message.rorg() == CRorgs::kUTE_Telegram) { @@ -558,7 +560,7 @@ void CEnOcean::declareDeviceWithoutProfile(const std::string& deviceId) const std::vector>()); } -void CEnOcean::processResponse(boost::shared_ptr) +void CEnOcean::processResponse(const boost::shared_ptr&) { YADOMS_LOG(error) << "Unexpected response received"; } @@ -583,7 +585,9 @@ void CEnOcean::processDongleVersionResponse(message::CResponseReceivedMessage::E YADOMS_LOG(information) << dongleVersionResponse.fullVersion(); } -void CEnOcean::processEepTeachInMessage(boost::dynamic_bitset<> erp1UserData, boost::shared_ptr rorg, std::string deviceId) +void CEnOcean::processEepTeachInMessage(const boost::dynamic_bitset<>& erp1UserData, + const boost::shared_ptr& rorg, + const std::string& deviceId) { if (rorg->id() != CRorgs::k4BS_Telegram) throw std::domain_error("Teach-in telegram is only supported for 4BS telegram for now. Please report to Yadoms-team."); @@ -633,8 +637,8 @@ void CEnOcean::processEepTeachInMessage(boost::dynamic_bitset<> erp1UserData, bo } } -void CEnOcean::processNoEepTeachInMessage(boost::shared_ptr rorg, - std::string deviceId) +void CEnOcean::processNoEepTeachInMessage(const boost::shared_ptr& rorg, + const std::string& deviceId) { // Special case for the 1BS RORG : only one func and type exist, so profile can be known if (rorg->id() == CRorgs::k1BS_Telegram) @@ -703,10 +707,10 @@ void CEnOcean::processNoEepTeachInMessage(boost::shared_ptr rorg, declareDeviceWithoutProfile(deviceId); } -void CEnOcean::processDataTelegram(message::CRadioErp1ReceivedMessage erp1Message, - boost::dynamic_bitset<> erp1UserData, - const boost::dynamic_bitset<> erp1Status, - std::string deviceId) +void CEnOcean::processDataTelegram(const message::CRadioErp1ReceivedMessage& erp1Message, + const boost::dynamic_bitset<>& erp1UserData, + const boost::dynamic_bitset<>& erp1Status, + const std::string& deviceId) { if (m_devices.find(deviceId) == m_devices.end()) { @@ -755,7 +759,7 @@ void CEnOcean::processDataTelegram(message::CRadioErp1ReceivedMessage erp1Messag m_api->historizeData(deviceId, keywordsToHistorize); } -void CEnOcean::processEvent(boost::shared_ptr esp3Packet) +void CEnOcean::processEvent(const boost::shared_ptr& esp3Packet) { if (esp3Packet->header().dataLength() < 1) throw CProtocolException((boost::format("RadioERP1 message : wrong data size (%1%, < 1)") % esp3Packet->header().dataLength()).str()); @@ -783,10 +787,10 @@ void CEnOcean::processUTE(message::CRadioErp1ReceivedMessage& erp1Message) ? boost::make_shared(erp1Message) : boost::make_shared(erp1Message); - switch (uteMessage->teachInRequest()) + switch (uteMessage->teachInRequest()) // NOLINT(clang-diagnostic-switch-enum) { - case message::CUTE_ReceivedMessage::kTeachInRequest: - case message::CUTE_ReceivedMessage::kNotSpecified: + case message::CUTE_ReceivedMessage::ETeachInRequest::kTeachInRequest: + case message::CUTE_ReceivedMessage::ETeachInRequest::kNotSpecified: { if (uteMessage->command() != message::CUTE_ReceivedMessage::kTeachInQuery) { @@ -837,7 +841,7 @@ void CEnOcean::processUTE(message::CRadioErp1ReceivedMessage& erp1Message) break; } - case message::CUTE_ReceivedMessage::kTeachInDeletionRequest: + case message::CUTE_ReceivedMessage::ETeachInRequest::kTeachInDeletionRequest: { removeDevice(uteMessage->senderId()); @@ -849,14 +853,15 @@ void CEnOcean::processUTE(message::CRadioErp1ReceivedMessage& erp1Message) } default: { - YADOMS_LOG(information) << "UTE message : teach-in request type " << uteMessage->teachInRequest() << " not supported, message ignored"; + YADOMS_LOG(information) << "UTE message : teach-in request type " << static_cast(uteMessage->teachInRequest()) << + " not supported, message ignored"; break; } } } bool CEnOcean::sendUTEAnswer(message::CUTE_AnswerSendMessage::EResponse response, - boost::shared_ptr uteMessage, + const boost::shared_ptr& uteMessage, bool isReversed, const std::string& deviceId) { @@ -865,15 +870,15 @@ bool CEnOcean::sendUTEAnswer(message::CUTE_AnswerSendMessage::EResponse response const auto sendMessage = isReversed ? boost::make_shared(m_senderId, - deviceId, - static_cast(0), - uteMessage->bidirectionalCommunication(), - response, - uteMessage->channelNumber(), - uteMessage->manufacturerId(), - uteMessage->type(), - uteMessage->func(), - uteMessage->rorg()) + deviceId, + static_cast(0), + uteMessage->bidirectionalCommunication(), + response, + uteMessage->channelNumber(), + uteMessage->manufacturerId(), + uteMessage->type(), + uteMessage->func(), + uteMessage->rorg()) : boost::make_shared(m_senderId, deviceId, static_cast(0), @@ -887,14 +892,14 @@ bool CEnOcean::sendUTEAnswer(message::CUTE_AnswerSendMessage::EResponse response message::CResponseReceivedMessage::EReturnCode returnCode; if (!m_messageHandler->send(*sendMessage, - [](boost::shared_ptr esp3Packet) - { - return esp3Packet->header().packetType() == message::RESPONSE; - }, + [](const boost::shared_ptr& esp3Packet) + { + return esp3Packet->header().packetType() == message::RESPONSE; + }, [&](boost::shared_ptr esp3Packet) - { - returnCode = message::CResponseReceivedMessage(esp3Packet).returnCode(); - })) + { + returnCode = message::CResponseReceivedMessage(std::move(esp3Packet)).returnCode(); + })) throw CProtocolException("Unable to send UTE response, timeout waiting acknowledge"); if (returnCode != message::CResponseReceivedMessage::RET_OK) @@ -966,17 +971,17 @@ void CEnOcean::requestDongleVersion() boost::shared_ptr answer; if (!m_messageHandler->send(sendMessage, - [](boost::shared_ptr esp3Packet) - { - if (esp3Packet->header().packetType() == message::RESPONSE) - return true; - YADOMS_LOG(warning) << "Unexpected message received : wrong packet type : " << esp3Packet->header().packetType(); - return false; - }, + [](const boost::shared_ptr& esp3Packet) + { + if (esp3Packet->header().packetType() == message::RESPONSE) + return true; + YADOMS_LOG(warning) << "Unexpected message received : wrong packet type : " << esp3Packet->header().packetType(); + return false; + }, [&](boost::shared_ptr esp3Packet) - { - answer = esp3Packet; - })) + { + answer = std::move(esp3Packet); + })) throw CProtocolException("Unable to get Dongle Version, timeout waiting answer"); if (answer->header().dataLength() != message::RESPONSE_DONGLE_VERSION_SIZE) @@ -988,14 +993,13 @@ void CEnOcean::requestDongleVersion() message::CDongleVersionResponseReceivedMessage(response)); } -void CEnOcean::startManualPairing(boost::shared_ptr api, +void CEnOcean::startManualPairing(const boost::shared_ptr& api, boost::shared_ptr extraQuery) { - if (m_pairingHelper->startStopPairing(extraQuery)) + if (m_pairingHelper->startStopPairing(std::move(extraQuery))) m_progressPairingTimer = api->getEventHandler().createTimer(kProgressPairingTimer, - shared::event::CEventTimer::kOneShot, - boost::posix_time::seconds(m_pairingHelper->getPairingPeriodTimeSeconds())); - else - if (m_progressPairingTimer) - m_progressPairingTimer.reset(); + shared::event::CEventTimer::kOneShot, + boost::posix_time::seconds(m_pairingHelper->getPairingPeriodTimeSeconds())); + else if (m_progressPairingTimer) + m_progressPairingTimer.reset(); } diff --git a/sources/plugins/EnOcean/EnOcean.h b/sources/plugins/EnOcean/EnOcean.h index 2617f91b50..6d8771d1c7 100644 --- a/sources/plugins/EnOcean/EnOcean.h +++ b/sources/plugins/EnOcean/EnOcean.h @@ -11,6 +11,7 @@ #include "IMessageHandler.h" #include #include "message/UTE_AnswerSendMessage.h" +#include "profiles/IRorg.h" // Shortcut to yPluginApi namespace @@ -19,11 +20,11 @@ namespace yApi = shared::plugin::yPluginApi; //-------------------------------------------------------------- /// \brief This plugin supports EnOcean //-------------------------------------------------------------- -class CEnOcean : public plugin_cpp_api::IPlugin +class CEnOcean final : public plugin_cpp_api::IPlugin { public: CEnOcean(); - virtual ~CEnOcean() = default; + ~CEnOcean() override = default; // IPlugin implementation void doWork(boost::shared_ptr api) override; @@ -40,13 +41,13 @@ class CEnOcean : public plugin_cpp_api::IPlugin /// \note Useful in case of first run of a new plugin version //-------------------------------------------------------------- void createNewKeywords(const std::string& deviceName, - const boost::shared_ptr& loadedDevice) const; + const boost::shared_ptr& loadedDevice) const; //-------------------------------------------------------------- /// \brief Process a command received from Yadoms /// \param [in] command The received command //-------------------------------------------------------------- - void processDeviceCommand(boost::shared_ptr command); + void processDeviceCommand(const boost::shared_ptr& command); //-------------------------------------------------------------- /// \brief Called when dongle becomes connected @@ -57,7 +58,9 @@ class CEnOcean : public plugin_cpp_api::IPlugin /// \brief Called when dongle becomes unconnected /// \param[in] notification The connection notification //-------------------------------------------------------------- - void processUnConnectionEvent(boost::shared_ptr notification = boost::shared_ptr()); + void processUnConnectionEvent( + const boost::shared_ptr& notification = boost::shared_ptr< + shared::communication::CAsyncPortConnectionNotification>()); //-------------------------------------------------------------- /// \brief Called when device was removed @@ -77,11 +80,11 @@ class CEnOcean : public plugin_cpp_api::IPlugin /// \brief Called when the data are received from the UPS /// \param [in] message Message received //-------------------------------------------------------------- - void processDataReceived(boost::shared_ptr message); + void processDataReceived(const boost::shared_ptr& message); //-------------------------------------------------------------- /// \brief Add signal power to historizable keyword list - /// \param [in/out] keywords Keyword list + /// \param [in,out] keywords Keyword list /// \param [in] deviceId Device ID /// \param [in] signalPower The current signal strength value (%) //-------------------------------------------------------------- @@ -101,22 +104,22 @@ class CEnOcean : public plugin_cpp_api::IPlugin /// \param [in] esp3Packet Message received //-------------------------------------------------------------- void processRadioErp1(boost::shared_ptr esp3Packet); - static void processResponse(boost::shared_ptr esp3Packet); + static void processResponse(const boost::shared_ptr& esp3Packet); void processDongleVersionResponse(message::CResponseReceivedMessage::EReturnCode returnCode, const message::CDongleVersionResponseReceivedMessage& dongleVersionResponse); - void processEepTeachInMessage(boost::dynamic_bitset<> erp1UserData, - boost::shared_ptr rorg, - std::string deviceId); - void processNoEepTeachInMessage(boost::shared_ptr rorg, - std::string deviceId); - void processDataTelegram(message::CRadioErp1ReceivedMessage erp1Message, - boost::dynamic_bitset<> erp1UserData, - const boost::dynamic_bitset<> erp1Status, - std::string deviceId); - static void processEvent(boost::shared_ptr esp3Packet); + void processEepTeachInMessage(const boost::dynamic_bitset<>& erp1UserData, + const boost::shared_ptr& rorg, + const std::string& deviceId); + void processNoEepTeachInMessage(const boost::shared_ptr& rorg, + const std::string& deviceId); + void processDataTelegram(const message::CRadioErp1ReceivedMessage& erp1Message, + const boost::dynamic_bitset<>& erp1UserData, + const boost::dynamic_bitset<>& erp1Status, + const std::string& deviceId); + static void processEvent(const boost::shared_ptr& esp3Packet); void processUTE(message::CRadioErp1ReceivedMessage& erp1Message); bool sendUTEAnswer(message::CUTE_AnswerSendMessage::EResponse response, - boost::shared_ptr uteMessage, + const boost::shared_ptr& uteMessage, bool isReversed, const std::string& deviceId); @@ -199,7 +202,7 @@ class CEnOcean : public plugin_cpp_api::IPlugin /// \param [in] api Plugin execution context (Yadoms API) /// \param [in] extraQuery Extra query //-------------------------------------------------------------- - void startManualPairing(boost::shared_ptr api, + void startManualPairing(const boost::shared_ptr& api, boost::shared_ptr extraQuery); private: diff --git a/sources/plugins/EnOcean/message/MessageHelpers.cpp b/sources/plugins/EnOcean/message/MessageHelpers.cpp index b631a2ac42..f5aa3c4bd5 100644 --- a/sources/plugins/EnOcean/message/MessageHelpers.cpp +++ b/sources/plugins/EnOcean/message/MessageHelpers.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" #include "MessageHelpers.h" + +#include #include "RadioErp1SendMessage.h" #include "profiles/bitsetHelpers.hpp" #include "ResponseReceivedMessage.h" @@ -7,7 +9,7 @@ namespace message { void CMessageHelpers::sendMessage(CRorgs::ERorgIds rorgId, - boost::shared_ptr messageHandler, + const boost::shared_ptr& messageHandler, const std::string& senderId, const std::string& targetId, const boost::dynamic_bitset<>& userData, @@ -22,13 +24,13 @@ namespace message boost::shared_ptr answer; if (!messageHandler->send(command, - [](boost::shared_ptr esp3Packet) + [](const boost::shared_ptr& esp3Packet) { return esp3Packet->header().packetType() == RESPONSE; }, [&](boost::shared_ptr esp3Packet) { - answer = esp3Packet; + answer = std::move(esp3Packet); })) throw std::runtime_error( (boost::format("Fail to send message to %1% : no answer to \"%2%\"") % targetId % messageName).str()); diff --git a/sources/plugins/EnOcean/message/MessageHelpers.h b/sources/plugins/EnOcean/message/MessageHelpers.h index 263ab4eb52..f40985f9f3 100644 --- a/sources/plugins/EnOcean/message/MessageHelpers.h +++ b/sources/plugins/EnOcean/message/MessageHelpers.h @@ -14,7 +14,7 @@ namespace message virtual ~CMessageHelpers() = default; static void sendMessage(CRorgs::ERorgIds rorgId, - boost::shared_ptr messageHandler, + const boost::shared_ptr& messageHandler, const std::string& senderId, const std::string& targetId, const boost::dynamic_bitset<>& userData, diff --git a/sources/plugins/EnOcean/message/UTE_GigaConceptReversedReceivedMessage.cpp b/sources/plugins/EnOcean/message/UTE_GigaConceptReversedReceivedMessage.cpp index 3667c559e5..5b094fdee9 100644 --- a/sources/plugins/EnOcean/message/UTE_GigaConceptReversedReceivedMessage.cpp +++ b/sources/plugins/EnOcean/message/UTE_GigaConceptReversedReceivedMessage.cpp @@ -4,10 +4,10 @@ namespace message { - bool CUTE_GigaConceptReversedReceivedMessage::isCGigaConceptReversedUteMessage(const message::CRadioErp1ReceivedMessage& message) + bool CUTE_GigaConceptReversedReceivedMessage::isCGigaConceptReversedUteMessage(const CRadioErp1ReceivedMessage& message) { // Try to recognize if userData is in revert order, only for device known as bugged. - auto userData = message.userData(); + const auto userData = message.userData(); if (userData.size() == 7 && userData[0] == 0xD2 // Profile - Rorg && userData[1] == 0x01 // Profile - Func @@ -21,15 +21,11 @@ namespace message return false; } - CUTE_GigaConceptReversedReceivedMessage::CUTE_GigaConceptReversedReceivedMessage(const message::CRadioErp1ReceivedMessage& message) + CUTE_GigaConceptReversedReceivedMessage::CUTE_GigaConceptReversedReceivedMessage(const CRadioErp1ReceivedMessage& message) : CUTE_ReceivedMessage(message) { } - CUTE_GigaConceptReversedReceivedMessage::~CUTE_GigaConceptReversedReceivedMessage() - { - } - bool CUTE_GigaConceptReversedReceivedMessage::bidirectionalCommunication() const { return (m_erp1.userData()[6] & 0x80) ? true : false; diff --git a/sources/plugins/EnOcean/message/UTE_GigaConceptReversedReceivedMessage.h b/sources/plugins/EnOcean/message/UTE_GigaConceptReversedReceivedMessage.h index fdc7d68747..89b5b13499 100644 --- a/sources/plugins/EnOcean/message/UTE_GigaConceptReversedReceivedMessage.h +++ b/sources/plugins/EnOcean/message/UTE_GigaConceptReversedReceivedMessage.h @@ -11,7 +11,7 @@ namespace message /// This device send the userData (and only this part of the message) in reversed byte order. /// If we recognize this message, we have to reorder bytes //-------------------------------------------------------------- - class CUTE_GigaConceptReversedReceivedMessage : public CUTE_ReceivedMessage + class CUTE_GigaConceptReversedReceivedMessage final : public CUTE_ReceivedMessage { public: static bool isCGigaConceptReversedUteMessage(const message::CRadioErp1ReceivedMessage& message); @@ -21,11 +21,7 @@ namespace message /// \param[in] message The ERP1 radio message //-------------------------------------------------------------- explicit CUTE_GigaConceptReversedReceivedMessage(const message::CRadioErp1ReceivedMessage& message); - - //-------------------------------------------------------------- - /// \brief Destructor - //-------------------------------------------------------------- - virtual ~CUTE_GigaConceptReversedReceivedMessage(); + ~CUTE_GigaConceptReversedReceivedMessage() override = default; bool bidirectionalCommunication() const override; bool teachInResponseExpected() const override; @@ -38,5 +34,3 @@ namespace message unsigned char rorg() const override; }; } // namespace message - - diff --git a/sources/plugins/EnOcean/message/UTE_ReceivedMessage.cpp b/sources/plugins/EnOcean/message/UTE_ReceivedMessage.cpp index 96443246ef..ce8d2c46f0 100644 --- a/sources/plugins/EnOcean/message/UTE_ReceivedMessage.cpp +++ b/sources/plugins/EnOcean/message/UTE_ReceivedMessage.cpp @@ -9,10 +9,6 @@ namespace message { } - CUTE_ReceivedMessage::~CUTE_ReceivedMessage() - { - } - bool CUTE_ReceivedMessage::bidirectionalCommunication() const { return (m_erp1.userData()[0] & 0x80) ? true : false; @@ -63,5 +59,3 @@ namespace message return m_erp1.senderId(); } } // namespace message - - diff --git a/sources/plugins/EnOcean/message/UTE_ReceivedMessage.h b/sources/plugins/EnOcean/message/UTE_ReceivedMessage.h index 1d3fe6f692..acedea1e51 100644 --- a/sources/plugins/EnOcean/message/UTE_ReceivedMessage.h +++ b/sources/plugins/EnOcean/message/UTE_ReceivedMessage.h @@ -12,7 +12,7 @@ namespace message class CUTE_ReceivedMessage { public: - enum ETeachInRequest + enum class ETeachInRequest { kTeachInRequest = 0, kTeachInDeletionRequest, @@ -30,11 +30,7 @@ namespace message /// \param[in] message The ERP1 radio message //-------------------------------------------------------------- explicit CUTE_ReceivedMessage(const CRadioErp1ReceivedMessage& message); - - //-------------------------------------------------------------- - /// \brief Destructor - //-------------------------------------------------------------- - virtual ~CUTE_ReceivedMessage(); + virtual ~CUTE_ReceivedMessage() = default; virtual bool bidirectionalCommunication() const; virtual bool teachInResponseExpected() const; @@ -47,9 +43,7 @@ namespace message virtual unsigned char rorg() const; virtual std::string senderId() const; - protected: + protected: const CRadioErp1ReceivedMessage& m_erp1; }; } // namespace message - - diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_01_Common.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_01_Common.cpp index 8d62f9e576..967e64f4fa 100644 --- a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_01_Common.cpp +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_01_Common.cpp @@ -197,8 +197,7 @@ std::vector> CProfil return historizers; } -std::vector> CProfile_D2_01_Common:: -extractActuatorStatusResponse2Channels( +std::vector> CProfile_D2_01_Common::extractActuatorStatusResponse2Channels( unsigned char rorg, const boost::dynamic_bitset<>& data, boost::shared_ptr channel1, @@ -343,7 +342,7 @@ std::vector> CProfil const auto unit = static_cast(bitset_extract(data, 8, 3)); const auto rawValue = bitset_extract(data, 16, 32); - switch (ioChannel) // NOLINT(hicpp-multiway-paths-covered) + switch (ioChannel) // NOLINT(hicpp-multiway-paths-covered) { case 0: // Output channel { @@ -368,7 +367,7 @@ std::vector> CProfil historizers.emplace_back(loadPower); } break; - default: // NOLINT(clang-diagnostic-covered-switch-default) + default: // NOLINT(clang-diagnostic-covered-switch-default) YADOMS_LOG(warning) << "ActuatorMeasurementResponse : received unsupported channel value " << ioChannel; break; } @@ -475,7 +474,7 @@ std::vector> CProfil pilotWire->set(specificHistorizers::EPilotWire::kComfort3); historizers.emplace_back(pilotWire); break; - default: // NOLINT(clang-diagnostic-covered-switch-default) + default: // NOLINT(clang-diagnostic-covered-switch-default) YADOMS_LOG(warning) << "ActuatorPilotWireModeResponse : received unsupported pilotWireMode value " << static_cast(pilotWireMode); break; } @@ -526,7 +525,7 @@ void CProfile_D2_01_Common::sendMessage(boost::shared_ptr messa Poco::Int64 CProfile_D2_01_Common::extractEnergyWh(E_D2_01_MeasurementUnit unit, unsigned int rawValue) { - switch (unit) // NOLINT(clang-diagnostic-switch-enum) + switch (unit) // NOLINT(clang-diagnostic-switch-enum) { case E_D2_01_MeasurementUnit::kEnergyWs: return static_cast(rawValue) * 3600; @@ -544,7 +543,7 @@ Poco::Int64 CProfile_D2_01_Common::extractEnergyWh(E_D2_01_MeasurementUnit unit, double CProfile_D2_01_Common::extractPowerValueW(E_D2_01_MeasurementUnit unit, unsigned int rawValue) { - switch (unit) // NOLINT(clang-diagnostic-switch-enum) + switch (unit) // NOLINT(clang-diagnostic-switch-enum) { case E_D2_01_MeasurementUnit::kPowerW: return rawValue; From b0e69fe47be4535ec862bdf9537175945de387de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gallou?= Date: Wed, 9 Mar 2022 11:52:58 +0100 Subject: [PATCH 16/20] Update build (report some changes from RestApiv2 branch) --- sources/external-libs/curl/CMakeLists.txt | 6 +++--- sources/external-libs/curlpp/CMakeLists.txt | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sources/external-libs/curl/CMakeLists.txt b/sources/external-libs/curl/CMakeLists.txt index 79d892b34d..fdb193d4e7 100644 --- a/sources/external-libs/curl/CMakeLists.txt +++ b/sources/external-libs/curl/CMakeLists.txt @@ -89,13 +89,13 @@ if(CMAKE_TOOLCHAIN_FILE) endif(CMAKE_TOOLCHAIN_FILE) ExternalProject_Add(curl_build - URL https://curl.se/download/curl-7.76.1.zip - URL_HASH SHA256=35dd8ddb0d89596bd117b62a84328b0a36a932311f8df147b760f990f40b1b70 + GIT_REPOSITORY https://github.com/curl/curl.git + GIT_TAG curl-7_80_0 + GIT_CONFIG advice.detachedHead=false PATCH_COMMAND ${CURL_PATHCMD} PREFIX ${CURL_ROOT} CMAKE_ARGS ${CURL_BUILD_ARGS} INSTALL_COMMAND "" - BUILD_ALWAYS OFF ) SET_PROPERTY(TARGET curl_build PROPERTY FOLDER "External Libs") diff --git a/sources/external-libs/curlpp/CMakeLists.txt b/sources/external-libs/curlpp/CMakeLists.txt index 517437c04b..2f880ad95c 100644 --- a/sources/external-libs/curlpp/CMakeLists.txt +++ b/sources/external-libs/curlpp/CMakeLists.txt @@ -73,13 +73,12 @@ endif(CMAKE_TOOLCHAIN_FILE) ExternalProject_Add (curlpp_build DEPENDS curl_build GIT_REPOSITORY https://github.com/jpbarrette/curlpp.git - GIT_TAG a67c73dde2c5d50b3dd3f898b8c185c23de827f3 + GIT_TAG e94744a17a872fb7c53d4c266689e21aa813b88f GIT_CONFIG advice.detachedHead=false PATCH_COMMAND ${CURLPP_PATHCMD} PREFIX ${CURLPP_ROOT} CMAKE_ARGS ${CURLPP_BUILD_ARGS} INSTALL_COMMAND "" - BUILD_ALWAYS OFF ) SET_PROPERTY(TARGET curlpp_build PROPERTY FOLDER "External Libs") From e96d739f4b3f759435123fb0c459ab97cb1b0ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gallou?= Date: Thu, 10 Mar 2022 09:30:18 +0100 Subject: [PATCH 17/20] Add D2_04_08 profile support --- sources/plugins/EnOcean/CMakeLists.txt | 3 + sources/plugins/EnOcean/changelog.md | 25 ++-- .../profiles/hardCoded/Profile_D2_04_08.cpp | 114 ++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_08.h | 47 ++++++++ .../EnOcean/specificHistorizers/Analog.h | 4 +- .../specificHistorizers/BlindLockingMode.h | 4 +- .../ConcentrationGramPerMeterCube.h | 4 +- .../specificHistorizers/ConcentrationPpm.h | 4 +- .../CountPerSecondRadioActivity.h | 4 +- .../DataToDisplayToScreen.h | 4 +- .../EnOcean/specificHistorizers/DayOfWeek.h | 4 +- .../DimmerModeHistorizer.h | 4 +- .../EnOcean/specificHistorizers/Fan4Speeds.h | 4 +- .../EnOcean/specificHistorizers/Fan6Speeds.h | 4 +- .../specificHistorizers/MassRadioActivity.h | 4 +- .../MechanicalHandleMovement.h | 4 +- .../specificHistorizers/PilotWireHistorizer.h | 4 +- .../EnOcean/specificHistorizers/SetPoint.h | 4 +- .../SieverPerSecondRadioActivity.h | 4 +- .../SpecialHeatingStates.h | 4 +- .../VolatileOrganicCompound.h | 4 +- .../VolumicRadioActivity.h | 4 +- 22 files changed, 214 insertions(+), 47 deletions(-) create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.h diff --git a/sources/plugins/EnOcean/CMakeLists.txt b/sources/plugins/EnOcean/CMakeLists.txt index 3069169222..58e48c1b2e 100644 --- a/sources/plugins/EnOcean/CMakeLists.txt +++ b/sources/plugins/EnOcean/CMakeLists.txt @@ -357,6 +357,9 @@ set(ENOCEAN_SOURCES ${ENOCEAN_SOURCES} profiles/hardCoded/Profile_D2_03_0A.cpp profiles/hardCoded/Profile_D2_03_0A.h + + profiles/hardCoded/Profile_D2_04_08.cpp + profiles/hardCoded/Profile_D2_04_08.h profiles/hardCoded/Profile_D2_05_Common.cpp profiles/hardCoded/Profile_D2_05_Common.h diff --git a/sources/plugins/EnOcean/changelog.md b/sources/plugins/EnOcean/changelog.md index 300c8fe87e..542a7af09d 100644 --- a/sources/plugins/EnOcean/changelog.md +++ b/sources/plugins/EnOcean/changelog.md @@ -1,22 +1,25 @@ +### 2.1.0 +* Add D2_04_08 profile support + ### 2.0.5 -* D2_01_0F, D2_01_12 profiles : fix configuration +* D2_01_0F, D2_01_12 profiles : fix configuration ### 2.0.4 -* A5_07_03 profile : change motion detection (event) to occupancy (switch) keyword +* A5_07_03 profile : change motion detection (event) to occupancy (switch) keyword ### 2.0.3 * Fix A5-09-05 profile management -* Fix D2-01-XX profiles with pilot wire management -* Fix A5_07_XX profiles management -* Fix A5_10_XX profiles management -* Fix A5_07_03 profile declaration (Illumination keyword was missing) - +* Fix D2-01-XX profiles with pilot wire management +* Fix A5_07_XX profiles management +* Fix A5_10_XX profiles management +* Fix A5_07_03 profile declaration (Illumination keyword was missing) + ### 2.0.2 -* Fix crash when random dialog failed (case of bad powered dongle) - +* Fix crash when random dialog failed (case of bad powered dongle) + ### 2.0.1 -* Fix power measurment lost when doing reset load energy for D2-01-0x profiles - +* Fix power measurment lost when doing reset load energy for D2-01-0x profiles + ### 2.0.0 * Update profiles definition to [v2.6.8](http://tools.enocean-alliance.org/EEPViewer/), add these profiles : * D2-01-15 diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.cpp new file mode 100644 index 0000000000..7183bdde37 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.cpp @@ -0,0 +1,114 @@ +#include "stdafx.h" +#include "Profile_D2_04_08.h" + +#include +#include "../bitsetHelpers.hpp" +#include "profiles/eep.h" + + +CProfile_D2_04_08::CProfile_D2_04_08(std::string deviceId, + boost::shared_ptr api) + : m_deviceId(std::move(deviceId)), + m_temperature(boost::make_shared("Temperature", + yApi::EKeywordAccessMode::kGet)), + m_humidity(boost::make_shared("Humidity", + yApi::EKeywordAccessMode::kGet)), + m_co2(boost::make_shared("Concentration(ppm)", + yApi::EKeywordAccessMode::kGet)), + m_day(boost::make_shared("Day", + yApi::EKeywordAccessMode::kGet)), + m_battery(boost::make_shared("Battery", + yApi::EKeywordAccessMode::kGet)), + m_historizers({ + m_temperature, m_humidity, m_co2, m_day, m_battery + }) +{ +} + +const std::string& CProfile_D2_04_08::profile() const +{ + static const std::string Profile("D2-04-08"); + return Profile; +} + +const std::string& CProfile_D2_04_08::title() const +{ + static const std::string Title(R"(CO2, Humidity, Temperature, Day/Night and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_08::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_08::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_08::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_temperature->set(static_cast(bitset_extract(data, 16, 8)) * 51.0 / 255.0); + + m_humidity->set(static_cast(bitset_extract(data, 8, 8)) * 100.0 / 200.0); + + m_co2->set(static_cast(bitset_extract(data, 0, 8)) * 2000.0 / 255.0); + + m_day->set(bitset_extract(status, 24, 1) ? false : true); + + switch (bitset_extract(data, 25, 3)) + { + case 0: + m_battery->set(100); + break; + case 1: + m_battery->set(87); + break; + case 2: + m_battery->set(75); + break; + case 3: + m_battery->set(62); + break; + case 4: + m_battery->set(50); + break; + case 5: + m_battery->set(37); + break; + case 6: + m_battery->set(25); + break; + case 7: + m_battery->set(12); + break; + default: + YADOMS_LOG(error) << "Unsupported message received for profile " << profile() << + " : Battery=" << bitset_extract(data, 25, 3); + return std::vector>(); + } + + return m_historizers; +} + +void CProfile_D2_04_08::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_08::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.h new file mode 100644 index 0000000000..96b64c9665 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.h @@ -0,0 +1,47 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "specificHistorizers/ConcentrationPpm.h" + + +class CProfile_D2_04_08 : public IType +{ +public: + CProfile_D2_04_08(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_08() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states(unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& + status, + const std::string& senderId, + boost::shared_ptr + messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + const std::string m_deviceId; + + boost::shared_ptr m_temperature; + boost::shared_ptr m_humidity; + boost::shared_ptr m_co2; + boost::shared_ptr m_day; + boost::shared_ptr m_battery; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/specificHistorizers/Analog.h b/sources/plugins/EnOcean/specificHistorizers/Analog.h index 160fd4128d..4ea0d9b280 100644 --- a/sources/plugins/EnOcean/specificHistorizers/Analog.h +++ b/sources/plugins/EnOcean/specificHistorizers/Analog.h @@ -5,13 +5,13 @@ namespace yApi = shared::plugin::yPluginApi; namespace specificHistorizers { - class CAnalog : public yApi::historization::CSingleHistorizableData + class CAnalog final : public yApi::historization::CSingleHistorizableData { public: explicit CAnalog(const std::string& keywordName, unsigned int min, unsigned int max, yApi::EKeywordAccessMode accessMode = yApi::EKeywordAccessMode::kGetSet); - virtual ~CAnalog() = default; + ~CAnalog() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/BlindLockingMode.h b/sources/plugins/EnOcean/specificHistorizers/BlindLockingMode.h index 094f4277a3..0768bc61a9 100644 --- a/sources/plugins/EnOcean/specificHistorizers/BlindLockingMode.h +++ b/sources/plugins/EnOcean/specificHistorizers/BlindLockingMode.h @@ -13,10 +13,10 @@ namespace specificHistorizers ((Deblockage)(7)) ) ; - class CBlindLockingMode : public yApi::historization::CSingleHistorizableData + class CBlindLockingMode final : public yApi::historization::CSingleHistorizableData { public: explicit CBlindLockingMode(const std::string& keywordName); - virtual ~CBlindLockingMode() = default; + ~CBlindLockingMode() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/ConcentrationGramPerMeterCube.h b/sources/plugins/EnOcean/specificHistorizers/ConcentrationGramPerMeterCube.h index a0e7b0c4a2..f00354c7c7 100644 --- a/sources/plugins/EnOcean/specificHistorizers/ConcentrationGramPerMeterCube.h +++ b/sources/plugins/EnOcean/specificHistorizers/ConcentrationGramPerMeterCube.h @@ -5,10 +5,10 @@ namespace yApi = shared::plugin::yPluginApi; namespace specificHistorizers { - class CConcentrationGramPerMeterCube : public yApi::historization::CSingleHistorizableData + class CConcentrationGramPerMeterCube final : public yApi::historization::CSingleHistorizableData { public: explicit CConcentrationGramPerMeterCube(const std::string& keywordName); - virtual ~CConcentrationGramPerMeterCube() = default; + ~CConcentrationGramPerMeterCube() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/ConcentrationPpm.h b/sources/plugins/EnOcean/specificHistorizers/ConcentrationPpm.h index 7891dded0b..0a00e3c3f9 100644 --- a/sources/plugins/EnOcean/specificHistorizers/ConcentrationPpm.h +++ b/sources/plugins/EnOcean/specificHistorizers/ConcentrationPpm.h @@ -5,11 +5,11 @@ namespace yApi = shared::plugin::yPluginApi; namespace specificHistorizers { - class CConcentrationPpm : public yApi::historization::CSingleHistorizableData + class CConcentrationPpm final : public yApi::historization::CSingleHistorizableData { public: explicit CConcentrationPpm(const std::string& keywordName, yApi::EKeywordAccessMode accessMode = yApi::EKeywordAccessMode::kGet); - virtual ~CConcentrationPpm() = default; + ~CConcentrationPpm() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/CountPerSecondRadioActivity.h b/sources/plugins/EnOcean/specificHistorizers/CountPerSecondRadioActivity.h index 82adea2e84..c98e06feff 100644 --- a/sources/plugins/EnOcean/specificHistorizers/CountPerSecondRadioActivity.h +++ b/sources/plugins/EnOcean/specificHistorizers/CountPerSecondRadioActivity.h @@ -5,10 +5,10 @@ namespace yApi = shared::plugin::yPluginApi; namespace specificHistorizers { - class CCountPerSecondRadioActivity : public yApi::historization::CSingleHistorizableData + class CCountPerSecondRadioActivity final : public yApi::historization::CSingleHistorizableData { public: explicit CCountPerSecondRadioActivity(const std::string& keywordName); - virtual ~CCountPerSecondRadioActivity() = default; + ~CCountPerSecondRadioActivity() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/DataToDisplayToScreen.h b/sources/plugins/EnOcean/specificHistorizers/DataToDisplayToScreen.h index 3f493ce8d6..d07bf41361 100644 --- a/sources/plugins/EnOcean/specificHistorizers/DataToDisplayToScreen.h +++ b/sources/plugins/EnOcean/specificHistorizers/DataToDisplayToScreen.h @@ -21,10 +21,10 @@ namespace specificHistorizers ((RelativeHumidity)(11)) ) ; - class CDataToDisplayToScreen : public yApi::historization::CSingleHistorizableData + class CDataToDisplayToScreen final : public yApi::historization::CSingleHistorizableData { public: explicit CDataToDisplayToScreen(const std::string& keywordName); - virtual ~CDataToDisplayToScreen() = default; + ~CDataToDisplayToScreen() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/DayOfWeek.h b/sources/plugins/EnOcean/specificHistorizers/DayOfWeek.h index 8939d22bf0..ad33129cc0 100644 --- a/sources/plugins/EnOcean/specificHistorizers/DayOfWeek.h +++ b/sources/plugins/EnOcean/specificHistorizers/DayOfWeek.h @@ -16,10 +16,10 @@ namespace specificHistorizers ((Sunday)(7)) ) ; - class CDayOfWeek : public yApi::historization::CSingleHistorizableData + class CDayOfWeek final : public yApi::historization::CSingleHistorizableData { public: explicit CDayOfWeek(const std::string& keywordName); - virtual ~CDayOfWeek() = default; + ~CDayOfWeek() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/DimmerModeHistorizer.h b/sources/plugins/EnOcean/specificHistorizers/DimmerModeHistorizer.h index 8699877af4..7d15996171 100644 --- a/sources/plugins/EnOcean/specificHistorizers/DimmerModeHistorizer.h +++ b/sources/plugins/EnOcean/specificHistorizers/DimmerModeHistorizer.h @@ -14,10 +14,10 @@ namespace specificHistorizers ((StopDimming)(4)) ) ; - class CDimmerModeHistorizer : public yApi::historization::CSingleHistorizableData + class CDimmerModeHistorizer final : public yApi::historization::CSingleHistorizableData { public: explicit CDimmerModeHistorizer(const std::string& keywordName); - virtual ~CDimmerModeHistorizer() = default; + ~CDimmerModeHistorizer() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/Fan4Speeds.h b/sources/plugins/EnOcean/specificHistorizers/Fan4Speeds.h index 7206b855f7..3172a07f6d 100644 --- a/sources/plugins/EnOcean/specificHistorizers/Fan4Speeds.h +++ b/sources/plugins/EnOcean/specificHistorizers/Fan4Speeds.h @@ -14,11 +14,11 @@ namespace specificHistorizers ((Speed3)(4)) ) ; - class CFan4Speeds : public yApi::historization::CSingleHistorizableData + class CFan4Speeds final : public yApi::historization::CSingleHistorizableData { public: explicit CFan4Speeds(const std::string& keywordName, yApi::EKeywordAccessMode accessMode = yApi::EKeywordAccessMode::kGetSet); - virtual ~CFan4Speeds() = default; + ~CFan4Speeds() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/Fan6Speeds.h b/sources/plugins/EnOcean/specificHistorizers/Fan6Speeds.h index 2a15499e4b..2f66a34e58 100644 --- a/sources/plugins/EnOcean/specificHistorizers/Fan6Speeds.h +++ b/sources/plugins/EnOcean/specificHistorizers/Fan6Speeds.h @@ -17,10 +17,10 @@ namespace specificHistorizers ((Speed5)(7)) ) ; - class CFan6Speeds : public yApi::historization::CSingleHistorizableData + class CFan6Speeds final : public yApi::historization::CSingleHistorizableData { public: explicit CFan6Speeds(const std::string& keywordName); - virtual ~CFan6Speeds() = default; + ~CFan6Speeds() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/MassRadioActivity.h b/sources/plugins/EnOcean/specificHistorizers/MassRadioActivity.h index ad15651f69..ff3ebfdb73 100644 --- a/sources/plugins/EnOcean/specificHistorizers/MassRadioActivity.h +++ b/sources/plugins/EnOcean/specificHistorizers/MassRadioActivity.h @@ -5,10 +5,10 @@ namespace yApi = shared::plugin::yPluginApi; namespace specificHistorizers { - class CMassRadioActivity : public yApi::historization::CSingleHistorizableData + class CMassRadioActivity final : public yApi::historization::CSingleHistorizableData { public: explicit CMassRadioActivity(const std::string& keywordName); - virtual ~CMassRadioActivity() = default; + ~CMassRadioActivity() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/MechanicalHandleMovement.h b/sources/plugins/EnOcean/specificHistorizers/MechanicalHandleMovement.h index e5c4d56556..c42b7469aa 100644 --- a/sources/plugins/EnOcean/specificHistorizers/MechanicalHandleMovement.h +++ b/sources/plugins/EnOcean/specificHistorizers/MechanicalHandleMovement.h @@ -12,11 +12,11 @@ namespace specificHistorizers ((ToHorizontal)(2)) ) ; - class CMechanicalHandleMovement : public yApi::historization::CSingleHistorizableData< + class CMechanicalHandleMovement final : public yApi::historization::CSingleHistorizableData< EMechanicalHandleMovement> { public: explicit CMechanicalHandleMovement(const std::string& keywordName); - virtual ~CMechanicalHandleMovement() = default; + ~CMechanicalHandleMovement() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/PilotWireHistorizer.h b/sources/plugins/EnOcean/specificHistorizers/PilotWireHistorizer.h index df029027d6..90756e1cce 100644 --- a/sources/plugins/EnOcean/specificHistorizers/PilotWireHistorizer.h +++ b/sources/plugins/EnOcean/specificHistorizers/PilotWireHistorizer.h @@ -15,11 +15,11 @@ namespace specificHistorizers ((AntiFreeze)(5)) ) ; - class CPilotWireHistorizer : public yApi::historization::CSingleHistorizableData + class CPilotWireHistorizer final : public yApi::historization::CSingleHistorizableData { public: explicit CPilotWireHistorizer(const std::string& keywordName); - virtual ~CPilotWireHistorizer() = default; + ~CPilotWireHistorizer() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/SetPoint.h b/sources/plugins/EnOcean/specificHistorizers/SetPoint.h index 343a06ebdd..548dfb46bd 100644 --- a/sources/plugins/EnOcean/specificHistorizers/SetPoint.h +++ b/sources/plugins/EnOcean/specificHistorizers/SetPoint.h @@ -5,11 +5,11 @@ namespace yApi = shared::plugin::yPluginApi; namespace specificHistorizers { - class CSetPoint : public yApi::historization::CSingleHistorizableData + class CSetPoint final : public yApi::historization::CSingleHistorizableData { public: explicit CSetPoint(const std::string& keywordName, const yApi::EKeywordAccessMode& accessMode = yApi::EKeywordAccessMode::kGetSet); - virtual ~CSetPoint() = default; + ~CSetPoint() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/SieverPerSecondRadioActivity.h b/sources/plugins/EnOcean/specificHistorizers/SieverPerSecondRadioActivity.h index 7cb670ebef..30bc9d4bb2 100644 --- a/sources/plugins/EnOcean/specificHistorizers/SieverPerSecondRadioActivity.h +++ b/sources/plugins/EnOcean/specificHistorizers/SieverPerSecondRadioActivity.h @@ -5,10 +5,10 @@ namespace yApi = shared::plugin::yPluginApi; namespace specificHistorizers { - class CSieverPerSecondRadioActivity : public yApi::historization::CSingleHistorizableData + class CSieverPerSecondRadioActivity final : public yApi::historization::CSingleHistorizableData { public: explicit CSieverPerSecondRadioActivity(const std::string& keywordName); - virtual ~CSieverPerSecondRadioActivity() = default; + ~CSieverPerSecondRadioActivity() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/SpecialHeatingStates.h b/sources/plugins/EnOcean/specificHistorizers/SpecialHeatingStates.h index 779764fb20..9f1000c79e 100644 --- a/sources/plugins/EnOcean/specificHistorizers/SpecialHeatingStates.h +++ b/sources/plugins/EnOcean/specificHistorizers/SpecialHeatingStates.h @@ -12,10 +12,10 @@ namespace specificHistorizers ((AutomaticControl)(2)) ) ; - class CSpecialHeatingStates : public yApi::historization::CSingleHistorizableData + class CSpecialHeatingStates final : public yApi::historization::CSingleHistorizableData { public: explicit CSpecialHeatingStates(const std::string& keywordName); - virtual ~CSpecialHeatingStates() = default; + ~CSpecialHeatingStates() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/VolatileOrganicCompound.h b/sources/plugins/EnOcean/specificHistorizers/VolatileOrganicCompound.h index b3aa77489f..9ad8d3f8db 100644 --- a/sources/plugins/EnOcean/specificHistorizers/VolatileOrganicCompound.h +++ b/sources/plugins/EnOcean/specificHistorizers/VolatileOrganicCompound.h @@ -45,11 +45,11 @@ namespace specificHistorizers ((kOzone)(255)) ) ; - class CVolatileOrganicCompound : public yApi::historization::CSingleHistorizableData< + class CVolatileOrganicCompound final : public yApi::historization::CSingleHistorizableData< EVolatileOrganicCompound> { public: explicit CVolatileOrganicCompound(const std::string& keywordName); - virtual ~CVolatileOrganicCompound() = default; + ~CVolatileOrganicCompound() override = default; }; } // namespace specificHistorizers diff --git a/sources/plugins/EnOcean/specificHistorizers/VolumicRadioActivity.h b/sources/plugins/EnOcean/specificHistorizers/VolumicRadioActivity.h index 7c8c9af10f..a65ee380c3 100644 --- a/sources/plugins/EnOcean/specificHistorizers/VolumicRadioActivity.h +++ b/sources/plugins/EnOcean/specificHistorizers/VolumicRadioActivity.h @@ -5,10 +5,10 @@ namespace yApi = shared::plugin::yPluginApi; namespace specificHistorizers { - class CVolumicRadioActivity : public yApi::historization::CSingleHistorizableData + class CVolumicRadioActivity final : public yApi::historization::CSingleHistorizableData { public: explicit CVolumicRadioActivity(const std::string& keywordName); - virtual ~CVolumicRadioActivity() = default; + ~CVolumicRadioActivity() override = default; }; } // namespace specificHistorizers From 40fa9f56f86683300ace806f166ff38f019c7e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gallou?= Date: Thu, 10 Mar 2022 10:34:14 +0100 Subject: [PATCH 18/20] Try to fix build --- .github/workflows/generate_binaries.yml | 2 +- .github/workflows/unit_tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/generate_binaries.yml b/.github/workflows/generate_binaries.yml index be48ead889..2587ffbe92 100644 --- a/.github/workflows/generate_binaries.yml +++ b/.github/workflows/generate_binaries.yml @@ -178,7 +178,7 @@ jobs: Windows: name : Generate for Windows - runs-on: windows-latest + runs-on: windows-2019 steps: - name: Checkout code uses: actions/checkout@v2 diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 345c1350be..0d691d34eb 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -69,7 +69,7 @@ jobs: Windows: name : Run Unit tests for Windows - runs-on: windows-latest + runs-on: windows-2019 steps: - name: Checkout code uses: actions/checkout@v2 From f3f9dea889455985fcef4b61c3f2089c627b202c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gallou?= Date: Thu, 10 Mar 2022 14:09:20 +0100 Subject: [PATCH 19/20] Add D2_04_XX profiles support --- sources/plugins/EnOcean/CMakeLists.txt | 32 +++++++++ sources/plugins/EnOcean/changelog.md | 2 +- .../profiles/hardCoded/Profile_D2_04_00.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_00.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_01.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_01.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_02.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_02.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_03.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_03.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_04.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_04.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_05.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_05.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_06.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_06.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_07.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_07.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_08.cpp | 57 ++-------------- .../profiles/hardCoded/Profile_D2_04_08.h | 25 +++---- .../profiles/hardCoded/Profile_D2_04_09.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_09.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_10.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_10.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_1A.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_1A.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_1B.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_1B.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_1C.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_1C.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_1D.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_1D.h | 40 ++++++++++++ .../profiles/hardCoded/Profile_D2_04_1E.cpp | 65 +++++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_1E.h | 40 ++++++++++++ .../hardCoded/Profile_D2_04_Common.cpp | 61 +++++++++++++++++ .../profiles/hardCoded/Profile_D2_04_Common.h | 26 ++++++++ 36 files changed, 1708 insertions(+), 70 deletions(-) create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_00.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_00.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_01.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_01.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_02.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_02.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_03.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_03.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_04.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_04.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_05.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_05.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_06.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_06.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_07.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_07.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_09.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_09.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_10.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_10.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1A.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1A.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1B.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1B.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1C.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1C.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1D.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1D.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1E.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1E.h create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_Common.cpp create mode 100644 sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_Common.h diff --git a/sources/plugins/EnOcean/CMakeLists.txt b/sources/plugins/EnOcean/CMakeLists.txt index 58e48c1b2e..0b461361b3 100644 --- a/sources/plugins/EnOcean/CMakeLists.txt +++ b/sources/plugins/EnOcean/CMakeLists.txt @@ -358,8 +358,40 @@ set(ENOCEAN_SOURCES ${ENOCEAN_SOURCES} profiles/hardCoded/Profile_D2_03_0A.cpp profiles/hardCoded/Profile_D2_03_0A.h + profiles/hardCoded/Profile_D2_04_Common.cpp + profiles/hardCoded/Profile_D2_04_Common.h + profiles/hardCoded/Profile_D2_04_00.cpp + profiles/hardCoded/Profile_D2_04_00.h + profiles/hardCoded/Profile_D2_04_01.cpp + profiles/hardCoded/Profile_D2_04_01.h + profiles/hardCoded/Profile_D2_04_02.cpp + profiles/hardCoded/Profile_D2_04_02.h + profiles/hardCoded/Profile_D2_04_03.cpp + profiles/hardCoded/Profile_D2_04_03.h + profiles/hardCoded/Profile_D2_04_04.cpp + profiles/hardCoded/Profile_D2_04_04.h + profiles/hardCoded/Profile_D2_04_05.cpp + profiles/hardCoded/Profile_D2_04_05.h + profiles/hardCoded/Profile_D2_04_06.cpp + profiles/hardCoded/Profile_D2_04_06.h + profiles/hardCoded/Profile_D2_04_07.cpp + profiles/hardCoded/Profile_D2_04_07.h profiles/hardCoded/Profile_D2_04_08.cpp profiles/hardCoded/Profile_D2_04_08.h + profiles/hardCoded/Profile_D2_04_09.cpp + profiles/hardCoded/Profile_D2_04_09.h + profiles/hardCoded/Profile_D2_04_10.cpp + profiles/hardCoded/Profile_D2_04_10.h + profiles/hardCoded/Profile_D2_04_1A.cpp + profiles/hardCoded/Profile_D2_04_1A.h + profiles/hardCoded/Profile_D2_04_1B.cpp + profiles/hardCoded/Profile_D2_04_1B.h + profiles/hardCoded/Profile_D2_04_1C.cpp + profiles/hardCoded/Profile_D2_04_1C.h + profiles/hardCoded/Profile_D2_04_1D.cpp + profiles/hardCoded/Profile_D2_04_1D.h + profiles/hardCoded/Profile_D2_04_1E.cpp + profiles/hardCoded/Profile_D2_04_1E.h profiles/hardCoded/Profile_D2_05_Common.cpp profiles/hardCoded/Profile_D2_05_Common.h diff --git a/sources/plugins/EnOcean/changelog.md b/sources/plugins/EnOcean/changelog.md index 542a7af09d..573968f518 100644 --- a/sources/plugins/EnOcean/changelog.md +++ b/sources/plugins/EnOcean/changelog.md @@ -1,5 +1,5 @@ ### 2.1.0 -* Add D2_04_08 profile support +* Add D2_04_XX profiles support ### 2.0.5 * D2_01_0F, D2_01_12 profiles : fix configuration diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_00.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_00.cpp new file mode 100644 index 0000000000..e6bc0eca2b --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_00.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_00.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_00::CProfile_D2_04_00(std::string deviceId, + boost::shared_ptr api) + : m_common(2000.0), + m_historizers({ + m_common.m_temperature, m_common.m_humidity, m_common.m_co2, m_common.m_day, m_common.m_battery + }) +{ +} + +const std::string& CProfile_D2_04_00::profile() const +{ + static const std::string Profile("D2-04-00"); + return Profile; +} + +const std::string& CProfile_D2_04_00::title() const +{ + static const std::string Title(R"(CO2, Humidity, Temperature, Day/Night and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_00::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_00::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_00::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_00::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_00::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_00.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_00.h new file mode 100644 index 0000000000..a68dab5dd9 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_00.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_00 : public IType +{ +public: + CProfile_D2_04_00(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_00() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_01.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_01.cpp new file mode 100644 index 0000000000..b46bca4113 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_01.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_01.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_01::CProfile_D2_04_01(std::string deviceId, + boost::shared_ptr api) + : m_common(2000.0), + m_historizers({ + m_common.m_humidity, m_common.m_co2, m_common.m_day, m_common.m_battery + }) +{ +} + +const std::string& CProfile_D2_04_01::profile() const +{ + static const std::string Profile("D2-04-01"); + return Profile; +} + +const std::string& CProfile_D2_04_01::title() const +{ + static const std::string Title(R"(CO2, Humidity, Day/Night and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_01::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_01::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_01::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_01::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_01::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_01.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_01.h new file mode 100644 index 0000000000..6c5b08ab18 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_01.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_01 : public IType +{ +public: + CProfile_D2_04_01(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_01() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_02.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_02.cpp new file mode 100644 index 0000000000..bac50400fc --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_02.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_02.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_02::CProfile_D2_04_02(std::string deviceId, + boost::shared_ptr api) + : m_common(2000.0), + m_historizers({ + m_common.m_temperature, m_common.m_co2, m_common.m_day, m_common.m_battery + }) +{ +} + +const std::string& CProfile_D2_04_02::profile() const +{ + static const std::string Profile("D2-04-02"); + return Profile; +} + +const std::string& CProfile_D2_04_02::title() const +{ + static const std::string Title(R"(CO2, Temperature, Day/Night and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_02::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_02::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_02::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_02::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_02::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_02.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_02.h new file mode 100644 index 0000000000..23491a1adb --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_02.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_02 : public IType +{ +public: + CProfile_D2_04_02(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_02() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_03.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_03.cpp new file mode 100644 index 0000000000..1a6f518863 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_03.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_03.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_03::CProfile_D2_04_03(std::string deviceId, + boost::shared_ptr api) + : m_common(2000.0), + m_historizers({ + m_common.m_temperature, m_common.m_humidity, m_common.m_co2, m_common.m_battery + }) +{ +} + +const std::string& CProfile_D2_04_03::profile() const +{ + static const std::string Profile("D2-04-03"); + return Profile; +} + +const std::string& CProfile_D2_04_03::title() const +{ + static const std::string Title(R"(CO2, Humidity, Temperature and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_03::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_03::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_03::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_03::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_03::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_03.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_03.h new file mode 100644 index 0000000000..f9040b67c0 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_03.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_03 : public IType +{ +public: + CProfile_D2_04_03(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_03() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_04.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_04.cpp new file mode 100644 index 0000000000..bac818b785 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_04.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_04.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_04::CProfile_D2_04_04(std::string deviceId, + boost::shared_ptr api) + : m_common(2000.0), + m_historizers({ + m_common.m_temperature, m_common.m_co2 + }) +{ +} + +const std::string& CProfile_D2_04_04::profile() const +{ + static const std::string Profile("D2-04-04"); + return Profile; +} + +const std::string& CProfile_D2_04_04::title() const +{ + static const std::string Title(R"(CO2 and Temperature)"); + return Title; +} + +std::vector> CProfile_D2_04_04::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_04::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_04::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_04::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_04::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_04.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_04.h new file mode 100644 index 0000000000..4f1b3c30f0 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_04.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_04 : public IType +{ +public: + CProfile_D2_04_04(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_04() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_05.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_05.cpp new file mode 100644 index 0000000000..a2e2e2d5ff --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_05.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_05.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_05::CProfile_D2_04_05(std::string deviceId, + boost::shared_ptr api) + : m_common(2000.0), + m_historizers({ + m_common.m_temperature, m_common.m_co2, m_common.m_day + }) +{ +} + +const std::string& CProfile_D2_04_05::profile() const +{ + static const std::string Profile("D2-04-05"); + return Profile; +} + +const std::string& CProfile_D2_04_05::title() const +{ + static const std::string Title(R"(CO2, Temperature and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_05::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_05::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_05::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_05::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_05::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_05.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_05.h new file mode 100644 index 0000000000..749c6f7d13 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_05.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_05 : public IType +{ +public: + CProfile_D2_04_05(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_05() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_06.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_06.cpp new file mode 100644 index 0000000000..3c0cd50d14 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_06.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_06.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_06::CProfile_D2_04_06(std::string deviceId, + boost::shared_ptr api) + : m_common(2000.0), + m_historizers({ + m_common.m_co2, m_common.m_day + }) +{ +} + +const std::string& CProfile_D2_04_06::profile() const +{ + static const std::string Profile("D2-04-06"); + return Profile; +} + +const std::string& CProfile_D2_04_06::title() const +{ + static const std::string Title(R"(CO2 and Day/Night)"); + return Title; +} + +std::vector> CProfile_D2_04_06::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_06::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_06::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_06::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_06::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_06.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_06.h new file mode 100644 index 0000000000..a536115c84 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_06.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_06 : public IType +{ +public: + CProfile_D2_04_06(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_06() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_07.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_07.cpp new file mode 100644 index 0000000000..9b1f7860b0 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_07.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_07.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_07::CProfile_D2_04_07(std::string deviceId, + boost::shared_ptr api) + : m_common(2000.0), + m_historizers({ + m_common.m_co2, m_common.m_day, m_common.m_battery + }) +{ +} + +const std::string& CProfile_D2_04_07::profile() const +{ + static const std::string Profile("D2-04-07"); + return Profile; +} + +const std::string& CProfile_D2_04_07::title() const +{ + static const std::string Title(R"(CO2, Day/Night and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_07::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_07::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_07::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_07::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_07::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_07.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_07.h new file mode 100644 index 0000000000..e4d7907483 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_07.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_07 : public IType +{ +public: + CProfile_D2_04_07(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_07() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.cpp index 7183bdde37..da783f92c6 100644 --- a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.cpp +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.cpp @@ -1,26 +1,14 @@ #include "stdafx.h" #include "Profile_D2_04_08.h" -#include -#include "../bitsetHelpers.hpp" #include "profiles/eep.h" CProfile_D2_04_08::CProfile_D2_04_08(std::string deviceId, boost::shared_ptr api) - : m_deviceId(std::move(deviceId)), - m_temperature(boost::make_shared("Temperature", - yApi::EKeywordAccessMode::kGet)), - m_humidity(boost::make_shared("Humidity", - yApi::EKeywordAccessMode::kGet)), - m_co2(boost::make_shared("Concentration(ppm)", - yApi::EKeywordAccessMode::kGet)), - m_day(boost::make_shared("Day", - yApi::EKeywordAccessMode::kGet)), - m_battery(boost::make_shared("Battery", - yApi::EKeywordAccessMode::kGet)), + : m_common(5000.0), m_historizers({ - m_temperature, m_humidity, m_co2, m_day, m_battery + m_common.m_temperature, m_common.m_humidity, m_common.m_co2, m_common.m_day, m_common.m_battery }) { } @@ -55,45 +43,8 @@ std::vector> CProfil const std::string& senderId, boost::shared_ptr messageHandler) const { - m_temperature->set(static_cast(bitset_extract(data, 16, 8)) * 51.0 / 255.0); - - m_humidity->set(static_cast(bitset_extract(data, 8, 8)) * 100.0 / 200.0); - - m_co2->set(static_cast(bitset_extract(data, 0, 8)) * 2000.0 / 255.0); - - m_day->set(bitset_extract(status, 24, 1) ? false : true); - - switch (bitset_extract(data, 25, 3)) - { - case 0: - m_battery->set(100); - break; - case 1: - m_battery->set(87); - break; - case 2: - m_battery->set(75); - break; - case 3: - m_battery->set(62); - break; - case 4: - m_battery->set(50); - break; - case 5: - m_battery->set(37); - break; - case 6: - m_battery->set(25); - break; - case 7: - m_battery->set(12); - break; - default: - YADOMS_LOG(error) << "Unsupported message received for profile " << profile() << - " : Battery=" << bitset_extract(data, 25, 3); - return std::vector>(); - } + m_common.states(data, + status); return m_historizers; } diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.h index 96b64c9665..dd217d83ed 100644 --- a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.h +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_08.h @@ -3,7 +3,7 @@ #include "../../IMessageHandler.h" #include -#include "specificHistorizers/ConcentrationPpm.h" +#include "Profile_D2_04_Common.h" class CProfile_D2_04_08 : public IType @@ -19,13 +19,12 @@ class CProfile_D2_04_08 : public IType std::vector> allHistorizers() const override; void readInitialState(const std::string& senderId, boost::shared_ptr messageHandler) const override; - std::vector> states(unsigned char rorg, - const boost::dynamic_bitset<>& data, - const boost::dynamic_bitset<>& - status, - const std::string& senderId, - boost::shared_ptr - messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; void sendCommand(const std::string& keyword, const std::string& commandBody, const std::string& senderId, @@ -35,13 +34,7 @@ class CProfile_D2_04_08 : public IType boost::shared_ptr messageHandler) const override; // [END] IType implementation -private: - const std::string m_deviceId; - - boost::shared_ptr m_temperature; - boost::shared_ptr m_humidity; - boost::shared_ptr m_co2; - boost::shared_ptr m_day; - boost::shared_ptr m_battery; +private: + CProfile_D2_04_Common m_common; std::vector> m_historizers; }; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_09.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_09.cpp new file mode 100644 index 0000000000..0991b55f93 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_09.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_09.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_09::CProfile_D2_04_09(std::string deviceId, + boost::shared_ptr api) + : m_common(5000.0), + m_historizers({ + m_common.m_humidity, m_common.m_co2, m_common.m_day, m_common.m_battery + }) +{ +} + +const std::string& CProfile_D2_04_09::profile() const +{ + static const std::string Profile("D2-04-09"); + return Profile; +} + +const std::string& CProfile_D2_04_09::title() const +{ + static const std::string Title(R"(CO2, Humidity, Day/Night and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_09::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_09::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_09::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_09::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_09::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_09.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_09.h new file mode 100644 index 0000000000..4c0a250fbd --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_09.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_09 : public IType +{ +public: + CProfile_D2_04_09(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_09() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_10.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_10.cpp new file mode 100644 index 0000000000..5e9f8fa4cc --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_10.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_10.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_10::CProfile_D2_04_10(std::string deviceId, + boost::shared_ptr api) + : m_common(5000.0), + m_historizers({ + m_common.m_temperature, m_common.m_co2, m_common.m_day, m_common.m_battery + }) +{ +} + +const std::string& CProfile_D2_04_10::profile() const +{ + static const std::string Profile("D2-04-10"); + return Profile; +} + +const std::string& CProfile_D2_04_10::title() const +{ + static const std::string Title(R"(CO2, Humidity, Day/Night and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_10::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_10::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_10::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_10::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_10::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_10.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_10.h new file mode 100644 index 0000000000..153268a92b --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_10.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_10 : public IType +{ +public: + CProfile_D2_04_10(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_10() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1A.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1A.cpp new file mode 100644 index 0000000000..3dc34cfc7b --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1A.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_1A.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_1A::CProfile_D2_04_1A(std::string deviceId, + boost::shared_ptr api) + : m_common(5000.0), + m_historizers({ + m_common.m_temperature, m_common.m_co2, m_common.m_battery + }) +{ +} + +const std::string& CProfile_D2_04_1A::profile() const +{ + static const std::string Profile("D2-04-1A"); + return Profile; +} + +const std::string& CProfile_D2_04_1A::title() const +{ + static const std::string Title(R"(CO2, Temperature and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_1A::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_1A::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_1A::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_1A::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_1A::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1A.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1A.h new file mode 100644 index 0000000000..fb53842d06 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1A.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_1A : public IType +{ +public: + CProfile_D2_04_1A(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_1A() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1B.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1B.cpp new file mode 100644 index 0000000000..ac1101cabe --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1B.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_1B.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_1B::CProfile_D2_04_1B(std::string deviceId, + boost::shared_ptr api) + : m_common(5000.0), + m_historizers({ + m_common.m_temperature, m_common.m_co2 + }) +{ +} + +const std::string& CProfile_D2_04_1B::profile() const +{ + static const std::string Profile("D2-04-1B"); + return Profile; +} + +const std::string& CProfile_D2_04_1B::title() const +{ + static const std::string Title(R"(CO2 and Temperature)"); + return Title; +} + +std::vector> CProfile_D2_04_1B::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_1B::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_1B::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_1B::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_1B::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1B.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1B.h new file mode 100644 index 0000000000..90b8d37675 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1B.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_1B : public IType +{ +public: + CProfile_D2_04_1B(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_1B() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1C.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1C.cpp new file mode 100644 index 0000000000..da1afee565 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1C.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_1C.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_1C::CProfile_D2_04_1C(std::string deviceId, + boost::shared_ptr api) + : m_common(5000.0), + m_historizers({ + m_common.m_temperature, m_common.m_co2, m_common.m_day + }) +{ +} + +const std::string& CProfile_D2_04_1C::profile() const +{ + static const std::string Profile("D2-04-1C"); + return Profile; +} + +const std::string& CProfile_D2_04_1C::title() const +{ + static const std::string Title(R"(CO2, Temperature and Day/Night)"); + return Title; +} + +std::vector> CProfile_D2_04_1C::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_1C::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_1C::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_1C::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_1C::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1C.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1C.h new file mode 100644 index 0000000000..bb10f4a47b --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1C.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_1C : public IType +{ +public: + CProfile_D2_04_1C(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_1C() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1D.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1D.cpp new file mode 100644 index 0000000000..e60a2c160b --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1D.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_1D.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_1D::CProfile_D2_04_1D(std::string deviceId, + boost::shared_ptr api) + : m_common(5000.0), + m_historizers({ + m_common.m_co2, m_common.m_day + }) +{ +} + +const std::string& CProfile_D2_04_1D::profile() const +{ + static const std::string Profile("D2-04-1D"); + return Profile; +} + +const std::string& CProfile_D2_04_1D::title() const +{ + static const std::string Title(R"(CO2 and Day/Night)"); + return Title; +} + +std::vector> CProfile_D2_04_1D::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_1D::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_1D::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_1D::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_1D::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1D.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1D.h new file mode 100644 index 0000000000..dd109182e8 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1D.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_1D : public IType +{ +public: + CProfile_D2_04_1D(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_1D() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1E.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1E.cpp new file mode 100644 index 0000000000..49e91c7c7e --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1E.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "Profile_D2_04_1E.h" + +#include "profiles/eep.h" + + +CProfile_D2_04_1E::CProfile_D2_04_1E(std::string deviceId, + boost::shared_ptr api) + : m_common(5000.0), + m_historizers({ + m_common.m_co2, m_common.m_day, m_common.m_battery + }) +{ +} + +const std::string& CProfile_D2_04_1E::profile() const +{ + static const std::string Profile("D2-04-1E"); + return Profile; +} + +const std::string& CProfile_D2_04_1E::title() const +{ + static const std::string Title(R"(CO2, Day/Night and Autonomy)"); + return Title; +} + +std::vector> CProfile_D2_04_1E::allHistorizers() const +{ + return m_historizers; +} + +void CProfile_D2_04_1E::readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Read-only device +} + +std::vector> CProfile_D2_04_1E::states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + m_common.states(data, + status); + + return m_historizers; +} + +void CProfile_D2_04_1E::sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + throw std::logic_error("device supports no command sending"); +} + +void CProfile_D2_04_1E::sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const +{ + // Device supports no configuration +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1E.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1E.h new file mode 100644 index 0000000000..aa1609c1b8 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_1E.h @@ -0,0 +1,40 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "Profile_D2_04_Common.h" + + +class CProfile_D2_04_1E : public IType +{ +public: + CProfile_D2_04_1E(std::string deviceId, + boost::shared_ptr api); + ~CProfile_D2_04_1E() override = default; + + // IType implementation + const std::string& profile() const override; + const std::string& title() const override; + std::vector> allHistorizers() const override; + void readInitialState(const std::string& senderId, + boost::shared_ptr messageHandler) const override; + std::vector> states( + unsigned char rorg, + const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendCommand(const std::string& keyword, + const std::string& commandBody, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + void sendConfiguration(const shared::CDataContainer& deviceConfiguration, + const std::string& senderId, + boost::shared_ptr messageHandler) const override; + // [END] IType implementation + +private: + CProfile_D2_04_Common m_common; + std::vector> m_historizers; +}; diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_Common.cpp b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_Common.cpp new file mode 100644 index 0000000000..525a1ef759 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_Common.cpp @@ -0,0 +1,61 @@ +#include "stdafx.h" +#include "Profile_D2_04_Common.h" + +#include "../bitsetHelpers.hpp" +#include "profiles/eep.h" + + +CProfile_D2_04_Common::CProfile_D2_04_Common(double co2SensorRange) + : m_temperature(boost::make_shared("Temperature", + yApi::EKeywordAccessMode::kGet)), + m_humidity(boost::make_shared("Humidity", + yApi::EKeywordAccessMode::kGet)), + m_co2(boost::make_shared("Concentration(ppm)", + yApi::EKeywordAccessMode::kGet)), + m_day(boost::make_shared("Day", + yApi::EKeywordAccessMode::kGet)), + m_battery(boost::make_shared("Battery", + yApi::EKeywordAccessMode::kGet)), + m_co2SensorRange(co2SensorRange) +{ +} + +void CProfile_D2_04_Common::states(const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status) const +{ + m_temperature->set(static_cast(bitset_extract(data, 16, 8)) * 51.0 / 255.0); + + m_humidity->set(static_cast(bitset_extract(data, 8, 8)) * 100.0 / 200.0); + + m_co2->set(static_cast(bitset_extract(data, 0, 8)) * m_co2SensorRange / 255.0); + + m_day->set(bitset_extract(status, 24, 1) ? false : true); + + switch (bitset_extract(data, 25, 3)) + { + case 0: + m_battery->set(100); + break; + case 1: + m_battery->set(87); + break; + case 2: + m_battery->set(75); + break; + case 3: + m_battery->set(62); + break; + case 4: + m_battery->set(50); + break; + case 5: + m_battery->set(37); + break; + case 6: + m_battery->set(25); + break; + default: + m_battery->set(0); + break; + } +} diff --git a/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_Common.h b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_Common.h new file mode 100644 index 0000000000..8fe4bb6000 --- /dev/null +++ b/sources/plugins/EnOcean/profiles/hardCoded/Profile_D2_04_Common.h @@ -0,0 +1,26 @@ +#pragma once +#include "../IType.h" +#include "../../IMessageHandler.h" +#include + +#include "specificHistorizers/ConcentrationPpm.h" + + +class CProfile_D2_04_Common +{ +public: + CProfile_D2_04_Common(double co2SensorRange); + virtual ~CProfile_D2_04_Common() = default; + + void states(const boost::dynamic_bitset<>& data, + const boost::dynamic_bitset<>& status) const; + + boost::shared_ptr m_temperature; + boost::shared_ptr m_humidity; + boost::shared_ptr m_co2; + boost::shared_ptr m_day; + boost::shared_ptr m_battery; + +private: + const double m_co2SensorRange; +}; From ff2c818c6388283f03956244c7e53cf7d2d2f478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gallou?= Date: Fri, 11 Mar 2022 08:06:08 +0100 Subject: [PATCH 20/20] Update changelog --- sources/server/changelog.md | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/sources/server/changelog.md b/sources/server/changelog.md index c4e18c5b85..6550a79784 100644 --- a/sources/server/changelog.md +++ b/sources/server/changelog.md @@ -1,31 +1,14 @@ -### 2.5.1-beta.5 +### 2.5.1 #### Yadoms * Fix #741 : SQL request syntax with PostgreSQL +* Fix #738 : Fix merging devices -### 2.5.1-beta.4 - -#### Yadoms +#### Plugins and widgets * Fix HTTP SCREEN plugin for TFT screens (see local changelog) - -### 2.5.1-beta.3 - -#### Yadoms -* Fix EnOcean plugin profile (see local changelog) - - -### 2.5.1-beta.2 - -#### Yadoms * Fix some profiles management for EnOcean plugin (see local changelog) -### 2.5.1-beta.1 - -#### Yadoms -* Fix #738 : Fix merging devices - - ### 2.5.0 #### Yadoms