Commit 2638bcb8f7db3e7d11cb4855765ebe46da4c1b6e
Committed by
Moritz Wirger
1 parent
3719728f
Add null check in group light ids for luminaires.
Showing
1 changed file
with
7 additions
and
4 deletions
src/Group.cpp
| @@ -37,7 +37,11 @@ std::vector<int> Group::getLightIds() const | @@ -37,7 +37,11 @@ std::vector<int> Group::getLightIds() const | ||
| 37 | ids.reserve(lights.size()); | 37 | ids.reserve(lights.size()); |
| 38 | for (const nlohmann::json& id : lights) | 38 | for (const nlohmann::json& id : lights) |
| 39 | { | 39 | { |
| 40 | - ids.push_back(std::stoi(id.get<std::string>())); | 40 | + // Luminaires can have null ids if not all light have been added |
| 41 | + if (!id.is_null()) | ||
| 42 | + { | ||
| 43 | + ids.push_back(std::stoi(id.get<std::string>())); | ||
| 44 | + } | ||
| 41 | } | 45 | } |
| 42 | return ids; | 46 | return ids; |
| 43 | } | 47 | } |
| @@ -141,8 +145,7 @@ std::string Group::getActionColorMode() const | @@ -141,8 +145,7 @@ std::string Group::getActionColorMode() const | ||
| 141 | StateTransaction Group::transaction() | 145 | StateTransaction Group::transaction() |
| 142 | { | 146 | { |
| 143 | // Do not pass state, because it is not the state of ALL lights in the group | 147 | // Do not pass state, because it is not the state of ALL lights in the group |
| 144 | - return StateTransaction( | ||
| 145 | - state.getCommandAPI(), "/groups/" + std::to_string(id) + "/action", nullptr); | 148 | + return StateTransaction(state.getCommandAPI(), "/groups/" + std::to_string(id) + "/action", nullptr); |
| 146 | } | 149 | } |
| 147 | 150 | ||
| 148 | void Group::setOn(bool on, uint8_t transition) | 151 | void Group::setOn(bool on, uint8_t transition) |
| @@ -256,6 +259,6 @@ nlohmann::json CreateGroup::getRequest() const | @@ -256,6 +259,6 @@ nlohmann::json CreateGroup::getRequest() const | ||
| 256 | CreateGroup::CreateGroup( | 259 | CreateGroup::CreateGroup( |
| 257 | const std::vector<int>& lights, const std::string& name, const std::string& type, const std::string& roomType) | 260 | const std::vector<int>& lights, const std::string& name, const std::string& type, const std::string& roomType) |
| 258 | : lights(lights), name(name), type(type), roomType(roomType) | 261 | : lights(lights), name(name), type(type), roomType(roomType) |
| 259 | -{} | 262 | +{ } |
| 260 | 263 | ||
| 261 | } // namespace hueplusplus | 264 | } // namespace hueplusplus |