diff --git a/hueplusplus/CMakeLists.txt b/hueplusplus/CMakeLists.txt index f4b003d..608e2ad 100755 --- a/hueplusplus/CMakeLists.txt +++ b/hueplusplus/CMakeLists.txt @@ -5,6 +5,7 @@ set(hueplusplus_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ExtendedColorTemperatureStrategy.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Hue.cpp ${CMAKE_CURRENT_SOURCE_DIR}/HueCommandAPI.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/HueDeviceTypes.cpp ${CMAKE_CURRENT_SOURCE_DIR}/HueException.cpp ${CMAKE_CURRENT_SOURCE_DIR}/HueLight.cpp ${CMAKE_CURRENT_SOURCE_DIR}/SimpleBrightnessStrategy.cpp diff --git a/hueplusplus/Hue.cpp b/hueplusplus/Hue.cpp index fdaabad..d088f4e 100644 --- a/hueplusplus/Hue.cpp +++ b/hueplusplus/Hue.cpp @@ -31,6 +31,7 @@ #include #include +#include "include/HueDeviceTypes.h" #include "include/ExtendedColorHueStrategy.h" #include "include/ExtendedColorTemperatureStrategy.h" #include "include/HueExceptionMacro.h" @@ -237,58 +238,11 @@ HueLight& Hue::getLight(int id) // std::cout << state["lights"][std::to_string(id)] << std::endl; std::string type = state["lights"][std::to_string(id)]["modelid"].get(); // std::cout << type << std::endl; - if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001") - { - // HueExtendedColorLight Gamut B - HueLight light = HueLight( - id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy); - light.colorType = ColorType::GAMUT_B; - lights.emplace(id, light); - return lights.find(id)->second; - } - else if (type == "LCT010" || type == "LCT011" || type == "LCT012" || type == "LCT014" || type == "LCT015" - || type == "LCT016" || type == "LLC020" || type == "LST002") - { - // HueExtendedColorLight Gamut C - HueLight light = HueLight( - id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy); - light.colorType = ColorType::GAMUT_C; - lights.emplace(id, light); - return lights.find(id)->second; - } - else if (type == "LST001" || type == "LLC005" || type == "LLC006" || type == "LLC007" || type == "LLC010" - || type == "LLC011" || type == "LLC012" || type == "LLC013" || type == "LLC014") - { - // HueColorLight Gamut A - HueLight light = HueLight(id, commands, simpleBrightnessStrategy, nullptr, simpleColorHueStrategy); - light.colorType = ColorType::GAMUT_A; - lights.emplace(id, light); - return lights.find(id)->second; - } - else if (type == "LWB004" || type == "LWB006" || type == "LWB007" || type == "LWB010" || type == "LWB014" - || type == "LDF001" || type == "LDF002" || type == "LDD001" || type == "LDD002" || type == "MWM001") - { - // HueDimmableLight No Color Type - HueLight light = HueLight(id, commands, simpleBrightnessStrategy, nullptr, nullptr); - light.colorType = ColorType::NONE; - lights.emplace(id, light); - return lights.find(id)->second; - } - else if (type == "LLM010" || type == "LLM011" || type == "LLM012" || type == "LTW001" || type == "LTW004" - || type == "LTW010" || type == "LTW011" || type == "LTW012" || type == "LTW013" || type == "LTW014" - || type == "LTW015" || type == "LTP001" || type == "LTP002" || type == "LTP003" || type == "LTP004" - || type == "LTP005" || type == "LTD003" || type == "LTF001" || type == "LTF002" || type == "LTC001" - || type == "LTC002" || type == "LTC003" || type == "LTC004" || type == "LTC011" || type == "LTC012" - || type == "LTD001" || type == "LTD002" || type == "LFF001" || type == "LTT001" || type == "LDT001") - { - // HueTemperatureLight - HueLight light = HueLight(id, commands, simpleBrightnessStrategy, simpleColorTemperatureStrategy, nullptr); - light.colorType = ColorType::TEMPERATURE; - lights.emplace(id, light); - return lights.find(id)->second; - } - std::cerr << "Could not determine HueLight type:" << type << "!\n"; - throw HueException(CURRENT_FILE_INFO, "Could not determine HueLight type!"); + auto light = MakeHueLight()(type, id, commands, simpleBrightnessStrategy, + extendedColorTemperatureStrategy, simpleColorTemperatureStrategy, extendedColorHueStrategy, + simpleColorHueStrategy); + lights.emplace(id, light); + return lights.find(id)->second; } bool Hue::removeLight(int id) diff --git a/hueplusplus/HueDeviceTypes.cpp b/hueplusplus/HueDeviceTypes.cpp new file mode 100644 index 0000000..1c3b13a --- /dev/null +++ b/hueplusplus/HueDeviceTypes.cpp @@ -0,0 +1,122 @@ +/** + \file HueDeviceTypes.cpp + Copyright Notice\n + Copyright (C) 2017 Jan Rogall - developer\n + Copyright (C) 2017 Moritz Wirger - developer\n + + This file is part of hueplusplus. + + hueplusplus is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + hueplusplus is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with hueplusplus. If not, see . +**/ + +#include + +#include "include/HueDeviceTypes.h" +#include "include/HueExceptionMacro.h" + +const std::set getGamutBTypes() +{ + static const std::set c_EXTENDEDCOLORLIGHT_GAMUTB_TYPES = { + "LCT001", "LCT002", "LCT003", "LCT007", "LLM001" + }; + return c_EXTENDEDCOLORLIGHT_GAMUTB_TYPES; +}; + + +const std::set getGamutCTypes() +{ + static const std::set c_EXTENDEDCOLORLIGHT_GAMUTC_TYPES = { + "LCT010", "LCT011", "LCT012", "LCT014", + "LCT015", "LCT016", "LLC020", "LST002" + }; + return c_EXTENDEDCOLORLIGHT_GAMUTC_TYPES; +} + +const std::set getGamutATypes() +{ + static const std::set c_EXTENDEDCOLORLIGHT_GAMUTA_TYPES = { + "LST001", "LLC005" , "LLC006", "LLC007", + "LLC010", "LLC011", "LLC012", "LLC013", + "LLC014" + }; + return c_EXTENDEDCOLORLIGHT_GAMUTA_TYPES; +} + +const std::set getNoColorTypes() +{ + static const std::set c_DIMMABLELIGHT_NO_COLOR_TYPES = { + "LWB004", "LWB006", "LWB007", "LWB010", + "LWB014", "LDF001", "LDF002", "LDD001", + "LDD002", "MWM001" + }; + return c_DIMMABLELIGHT_NO_COLOR_TYPES; +} + +const std::set getTemperatureLightTypes() +{ + static const std::set c_TEMPERATURELIGHT_TYPES = { + "LLM010", "LLM011", "LLM012", "LTW001", "LTW004", + "LTW010", "LTW011", "LTW012", "LTW013", "LTW014", + "LTW015", "LTP001", "LTP002", "LTP003", "LTP004", + "LTP005", "LTD003", "LTF001", "LTF002", "LTC001", + "LTC002", "LTC003", "LTC004", "LTC011", "LTC012", + "LTD001", "LTD002", "LFF001", "LTT001", "LDT001" + }; + return c_TEMPERATURELIGHT_TYPES; +} + +auto MakeHueLight::operator()(std::string type, int id, HueCommandAPI commands, + std::shared_ptr simpleBrightnessStrategy, + std::shared_ptr extendedColorTemperatureStrategy, + std::shared_ptr simpleColorTemperatureStrategy, + std::shared_ptr extendedColorHueStrategy, + std::shared_ptr simpleColorHueStrategy) -> HueLight +{ + if (getGamutBTypes().count(type)) + { + auto light = HueLight(id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy); + light.colorType = ColorType::GAMUT_B; + return light; + } + + else if (getGamutCTypes().count(type)) + { + auto light = HueLight(id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy); + light.colorType = ColorType::GAMUT_C; + return light; + } + + else if (getGamutATypes().count(type)) + { + auto light = HueLight(id, commands, simpleBrightnessStrategy, nullptr, simpleColorHueStrategy); + light.colorType = ColorType::GAMUT_A; + return light; + } + + else if (getNoColorTypes().count(type)) + { + auto light = HueLight(id, commands, simpleBrightnessStrategy, nullptr, nullptr); + light.colorType = ColorType::NONE; + return light; + } + + else if (getTemperatureLightTypes().count(type)) + { + auto light = HueLight(id, commands, simpleBrightnessStrategy, simpleColorTemperatureStrategy, nullptr); + light.colorType = ColorType::TEMPERATURE; + return light; + } + std::cerr << "Could not determine HueLight type:" << type << "!\n"; + throw HueException(CURRENT_FILE_INFO, "Could not determine HueLight type!"); +} diff --git a/hueplusplus/include/HueDeviceTypes.h b/hueplusplus/include/HueDeviceTypes.h new file mode 100644 index 0000000..0e963ad --- /dev/null +++ b/hueplusplus/include/HueDeviceTypes.h @@ -0,0 +1,43 @@ +/** + \file HueDeviceTypes.h + Copyright Notice\n + Copyright (C) 2020 Jan Rogall - developer\n + Copyright (C) 2020 Moritz Wirger - developer\n + + This file is part of hueplusplus. + + hueplusplus is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + hueplusplus is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with hueplusplus. If not, see . +**/ + + +#ifndef _HUEDEVICETYPES_H +#define _HUEDEVICETYPES_H + +#include +#include + +#include "HueLight.h" + +struct MakeHueLight { + auto operator()(std::string type, int id, HueCommandAPI commands, + std::shared_ptr simpleBrightnessStrategy, + std::shared_ptr extendedColorTemperatureStrategy, + std::shared_ptr simpleColorTemperatureStrategy, + std::shared_ptr extendedColorHueStrategy, + std::shared_ptr simpleColorHueStrategy) -> HueLight; +}; + + +#endif + diff --git a/hueplusplus/include/HueLight.h b/hueplusplus/include/HueLight.h index be434ad..0bd20ca 100644 --- a/hueplusplus/include/HueLight.h +++ b/hueplusplus/include/HueLight.h @@ -94,6 +94,7 @@ enum ColorType class HueLight { friend class Hue; + friend struct MakeHueLight; friend class SimpleBrightnessStrategy; friend class SimpleColorHueStrategy; friend class ExtendedColorHueStrategy;