Commit 94d8c613ef97100282a0dcae1f2de485b416d714
1 parent
21b6f464
add 2 new functions for getting all lights
Showing
2 changed files
with
75 additions
and
0 deletions
hueplusplus/Hue.cpp
| @@ -283,6 +283,72 @@ std::unique_ptr<HueLight> Hue::getLight(int id) | @@ -283,6 +283,72 @@ std::unique_ptr<HueLight> Hue::getLight(int id) | ||
| 283 | throw(std::runtime_error("Could not determine HueLight type!")); | 283 | throw(std::runtime_error("Could not determine HueLight type!")); |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | +const std::map<uint8_t, ColorType>& Hue::getAllLightTypes() | ||
| 287 | +{ | ||
| 288 | + refreshState(); | ||
| 289 | + for (const auto& name : state["lights"].getMemberNames()) | ||
| 290 | + { | ||
| 291 | + std::string type = state["lights"][name]["modelid"].asString(); | ||
| 292 | + int id = std::stoi(name); | ||
| 293 | + | ||
| 294 | + if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001") | ||
| 295 | + { | ||
| 296 | + // HueExtendedColorLight Gamut B | ||
| 297 | + lights[id] = ColorType::GAMUT_B; | ||
| 298 | + } | ||
| 299 | + else if (type == "LCT010" || type == "LCT011" || type == "LCT014" || type == "LLC020" || type == "LST002") | ||
| 300 | + { | ||
| 301 | + // HueExtendedColorLight Gamut C | ||
| 302 | + lights[id] = ColorType::GAMUT_C; | ||
| 303 | + } | ||
| 304 | + else if (type == "LST001" || type == "LLC006" || type == "LLC007" || type == "LLC010" || type == "LLC011" || type == "LLC012" || type == "LLC013") | ||
| 305 | + { | ||
| 306 | + // HueColorLight Gamut A | ||
| 307 | + lights[id] = ColorType::GAMUT_A; | ||
| 308 | + } | ||
| 309 | + else if (type == "LWB004" || type == "LWB006" || type == "LWB007" || type == "LWB010" || type == "LWB014") | ||
| 310 | + { | ||
| 311 | + // HueDimmableLight No Color Type | ||
| 312 | + lights[id] = ColorType::NONE; | ||
| 313 | + } | ||
| 314 | + else if (type == "LLM010" || type == "LLM011" || type == "LLM012" || type == "LTW001" || type == "LTW004" || type == "LTW013" || type == "LTW014") | ||
| 315 | + { | ||
| 316 | + // HueTemperatureLight | ||
| 317 | + lights[id] = ColorType::TEMPERATURE; | ||
| 318 | + } | ||
| 319 | + } | ||
| 320 | + return lights; | ||
| 321 | +} | ||
| 322 | + | ||
| 323 | + | ||
| 324 | +std::vector<std::unique_ptr<HueLight>> Hue::getAllLights() | ||
| 325 | +{ | ||
| 326 | + std::vector<std::unique_ptr<HueLight>> result; | ||
| 327 | + const std::map<uint8_t, ColorType>& lightTypes = getAllLightTypes(); | ||
| 328 | + for (const auto& entry : lightTypes) | ||
| 329 | + { | ||
| 330 | + switch (entry.second) | ||
| 331 | + { | ||
| 332 | + case ColorType::GAMUT_B: | ||
| 333 | + case ColorType::GAMUT_C: | ||
| 334 | + result.emplace_back(new HueExtendedColorLight(ip, username, entry.first)); | ||
| 335 | + break; | ||
| 336 | + case ColorType::GAMUT_A: | ||
| 337 | + result.emplace_back(new HueColorLight(ip, username, entry.first)); | ||
| 338 | + break; | ||
| 339 | + case ColorType::NONE: | ||
| 340 | + result.emplace_back(new HueDimmableLight(ip, username, entry.first)); | ||
| 341 | + break; | ||
| 342 | + case ColorType::TEMPERATURE: | ||
| 343 | + result.emplace_back(new HueTemperatureLight(ip, username, entry.first)); | ||
| 344 | + break; | ||
| 345 | + default: | ||
| 346 | + break; | ||
| 347 | + } | ||
| 348 | + } | ||
| 349 | + return result; | ||
| 350 | +} | ||
| 351 | + | ||
| 286 | void Hue::refreshState() | 352 | void Hue::refreshState() |
| 287 | { | 353 | { |
| 288 | if (username.empty()) | 354 | if (username.empty()) |
hueplusplus/include/Hue.h
| @@ -106,6 +106,14 @@ public: | @@ -106,6 +106,14 @@ public: | ||
| 106 | //! \return \ref HueLight that can be controlled | 106 | //! \return \ref HueLight that can be controlled |
| 107 | std::unique_ptr<HueLight> getLight(int id); | 107 | std::unique_ptr<HueLight> getLight(int id); |
| 108 | 108 | ||
| 109 | + //! Function that returns all light types that are associated with this bridge | ||
| 110 | + //! \return A map mapping light id's to light types for every light | ||
| 111 | + const std::map<uint8_t, ColorType>& getAllLightTypes(); | ||
| 112 | + | ||
| 113 | + //! Function that returns all lights that are associated with this bridge | ||
| 114 | + //! \return A vector containing pointers pointing to every HueLight | ||
| 115 | + std::vector<std::unique_ptr<HueLight>> getAllLights(); | ||
| 116 | + | ||
| 109 | private: | 117 | private: |
| 110 | //! Function that refreshes the local \ref state of the Hue bridge | 118 | //! Function that refreshes the local \ref state of the Hue bridge |
| 111 | void refreshState(); | 119 | void refreshState(); |
| @@ -114,6 +122,7 @@ private: | @@ -114,6 +122,7 @@ private: | ||
| 114 | std::string ip; | 122 | std::string ip; |
| 115 | std::string username; | 123 | std::string username; |
| 116 | Json::Value state; | 124 | Json::Value state; |
| 125 | + std::map<uint8_t, ColorType> lights; | ||
| 117 | }; | 126 | }; |
| 118 | 127 | ||
| 119 | #endif | 128 | #endif |
| 120 | \ No newline at end of file | 129 | \ No newline at end of file |