diff --git a/hueplusplus/Hue.cpp b/hueplusplus/Hue.cpp index c148601..04cccd6 100644 --- a/hueplusplus/Hue.cpp +++ b/hueplusplus/Hue.cpp @@ -283,6 +283,72 @@ std::unique_ptr Hue::getLight(int id) throw(std::runtime_error("Could not determine HueLight type!")); } +const std::map& Hue::getAllLightTypes() +{ + refreshState(); + for (const auto& name : state["lights"].getMemberNames()) + { + std::string type = state["lights"][name]["modelid"].asString(); + int id = std::stoi(name); + + if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001") + { + // HueExtendedColorLight Gamut B + lights[id] = ColorType::GAMUT_B; + } + else if (type == "LCT010" || type == "LCT011" || type == "LCT014" || type == "LLC020" || type == "LST002") + { + // HueExtendedColorLight Gamut C + lights[id] = ColorType::GAMUT_C; + } + else if (type == "LST001" || type == "LLC006" || type == "LLC007" || type == "LLC010" || type == "LLC011" || type == "LLC012" || type == "LLC013") + { + // HueColorLight Gamut A + lights[id] = ColorType::GAMUT_A; + } + else if (type == "LWB004" || type == "LWB006" || type == "LWB007" || type == "LWB010" || type == "LWB014") + { + // HueDimmableLight No Color Type + lights[id] = ColorType::NONE; + } + else if (type == "LLM010" || type == "LLM011" || type == "LLM012" || type == "LTW001" || type == "LTW004" || type == "LTW013" || type == "LTW014") + { + // HueTemperatureLight + lights[id] = ColorType::TEMPERATURE; + } + } + return lights; +} + + +std::vector> Hue::getAllLights() +{ + std::vector> result; + const std::map& lightTypes = getAllLightTypes(); + for (const auto& entry : lightTypes) + { + switch (entry.second) + { + case ColorType::GAMUT_B: + case ColorType::GAMUT_C: + result.emplace_back(new HueExtendedColorLight(ip, username, entry.first)); + break; + case ColorType::GAMUT_A: + result.emplace_back(new HueColorLight(ip, username, entry.first)); + break; + case ColorType::NONE: + result.emplace_back(new HueDimmableLight(ip, username, entry.first)); + break; + case ColorType::TEMPERATURE: + result.emplace_back(new HueTemperatureLight(ip, username, entry.first)); + break; + default: + break; + } + } + return result; +} + void Hue::refreshState() { if (username.empty()) diff --git a/hueplusplus/include/Hue.h b/hueplusplus/include/Hue.h index b5b0e16..7bfe687 100644 --- a/hueplusplus/include/Hue.h +++ b/hueplusplus/include/Hue.h @@ -106,6 +106,14 @@ public: //! \return \ref HueLight that can be controlled std::unique_ptr getLight(int id); + //! Function that returns all light types that are associated with this bridge + //! \return A map mapping light id's to light types for every light + const std::map& getAllLightTypes(); + + //! Function that returns all lights that are associated with this bridge + //! \return A vector containing pointers pointing to every HueLight + std::vector> getAllLights(); + private: //! Function that refreshes the local \ref state of the Hue bridge void refreshState(); @@ -114,6 +122,7 @@ private: std::string ip; std::string username; Json::Value state; + std::map lights; }; #endif \ No newline at end of file