Commit 6e00e6d5df953628f2fa4509ba15b44f21046bb2
Committed by
Moritz Wirger
1 parent
984de8e3
Base light type off the type parameter instead of modelid.
The only additional information which is needed is the gamut space for color lights.
Showing
3 changed files
with
22 additions
and
25 deletions
include/hueplusplus/HueDeviceTypes.h
| ... | ... | @@ -35,7 +35,7 @@ class HueLightFactory |
| 35 | 35 | public: |
| 36 | 36 | HueLightFactory(const HueCommandAPI& commands); |
| 37 | 37 | |
| 38 | - HueLight createLight(const std::string& type, int id); | |
| 38 | + HueLight createLight(const nlohmann::json& lightState, int id); | |
| 39 | 39 | |
| 40 | 40 | private: |
| 41 | 41 | HueCommandAPI commands; | ... | ... |
src/Hue.cpp
| ... | ... | @@ -231,8 +231,7 @@ HueLight& Hue::getLight(int id) |
| 231 | 231 | std::cerr << "Error in Hue getLight(): light with id " << id << " is not valid\n"; |
| 232 | 232 | throw HueException(CURRENT_FILE_INFO, "Light id is not valid"); |
| 233 | 233 | } |
| 234 | - std::string type = lightsCache[std::to_string(id)]["modelid"].get<std::string>(); | |
| 235 | - auto light = lightFactory.createLight(type, id); | |
| 234 | + auto light = lightFactory.createLight(lightsCache[std::to_string(id)], id); | |
| 236 | 235 | lights.emplace(id, light); |
| 237 | 236 | return lights.find(id)->second; |
| 238 | 237 | } | ... | ... |
src/HueDeviceTypes.cpp
| ... | ... | @@ -89,42 +89,40 @@ HueLightFactory::HueLightFactory(const HueCommandAPI& commands) |
| 89 | 89 | extendedColorTemperature(std::make_shared<ExtendedColorTemperatureStrategy>()) |
| 90 | 90 | {} |
| 91 | 91 | |
| 92 | -HueLight HueLightFactory::createLight(const std::string& type, int id) | |
| 92 | +HueLight HueLightFactory::createLight(const nlohmann::json& lightState, int id) | |
| 93 | 93 | { |
| 94 | - if (getGamutBTypes().count(type)) | |
| 95 | - { | |
| 96 | - auto light = HueLight(id, commands, simpleBrightness, extendedColorTemperature, extendedColorHue); | |
| 97 | - light.colorType = ColorType::GAMUT_B; | |
| 98 | - return light; | |
| 99 | - } | |
| 100 | - else if (getGamutCTypes().count(type)) | |
| 94 | + std::string type = lightState.value("type", ""); | |
| 95 | + // Ignore case | |
| 96 | + std::transform(type.begin(), type.end(), type.begin(), [](char c) { return std::tolower(c); }); | |
| 97 | + | |
| 98 | + if (type == "on/off light") | |
| 101 | 99 | { |
| 102 | - auto light = HueLight(id, commands, simpleBrightness, extendedColorTemperature, extendedColorHue); | |
| 103 | - light.colorType = ColorType::GAMUT_C; | |
| 100 | + HueLight light(id, commands, nullptr, nullptr, nullptr); | |
| 101 | + light.colorType = ColorType::NONE; | |
| 104 | 102 | return light; |
| 105 | 103 | } |
| 106 | - else if (getGamutATypes().count(type)) | |
| 104 | + else if (type == "dimmable light") | |
| 107 | 105 | { |
| 108 | - auto light = HueLight(id, commands, simpleBrightness, nullptr, simpleColorHue); | |
| 109 | - light.colorType = ColorType::GAMUT_A; | |
| 106 | + HueLight light(id, commands, simpleBrightness, nullptr, nullptr); | |
| 107 | + light.colorType = ColorType::NONE; | |
| 110 | 108 | return light; |
| 111 | 109 | } |
| 112 | - else if (getNoColorTypes().count(type)) | |
| 110 | + else if (type == "color temperature light") | |
| 113 | 111 | { |
| 114 | - auto light = HueLight(id, commands, simpleBrightness, nullptr, nullptr); | |
| 115 | - light.colorType = ColorType::NONE; | |
| 112 | + HueLight light(id, commands, simpleBrightness, simpleColorTemperature, nullptr); | |
| 113 | + light.colorType = ColorType::TEMPERATURE; | |
| 116 | 114 | return light; |
| 117 | 115 | } |
| 118 | - else if (getNonDimmableTypes().count(type)) | |
| 116 | + else if (type == "color light") | |
| 119 | 117 | { |
| 120 | - auto light = HueLight(id, commands); | |
| 121 | - light.colorType = ColorType::NONE; | |
| 118 | + HueLight light(id, commands, simpleBrightness, nullptr, simpleColorHue); | |
| 119 | + light.colorType = ColorType::GAMUT_A; // getColorType(state); | |
| 122 | 120 | return light; |
| 123 | 121 | } |
| 124 | - else if (getTemperatureLightTypes().count(type)) | |
| 122 | + else if (type == "extended color light") | |
| 125 | 123 | { |
| 126 | - auto light = HueLight(id, commands, simpleBrightness, simpleColorTemperature, nullptr); | |
| 127 | - light.colorType = ColorType::TEMPERATURE; | |
| 124 | + HueLight light(id, commands, simpleBrightness, extendedColorTemperature, extendedColorHue); | |
| 125 | + light.colorType = ColorType::GAMUT_B_TEMPERATURE; // getColorType(state); | |
| 128 | 126 | return light; |
| 129 | 127 | } |
| 130 | 128 | std::cerr << "Could not determine HueLight type:" << type << "!\n"; | ... | ... |