From 2638bcb8f7db3e7d11cb4855765ebe46da4c1b6e Mon Sep 17 00:00:00 2001 From: Jojo-1000 <33495614+Jojo-1000@users.noreply.github.com> Date: Sat, 27 Jun 2020 23:33:27 +0200 Subject: [PATCH] Add null check in group light ids for luminaires. --- src/Group.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Group.cpp b/src/Group.cpp index 36e6977..6827519 100644 --- a/src/Group.cpp +++ b/src/Group.cpp @@ -37,7 +37,11 @@ std::vector Group::getLightIds() const ids.reserve(lights.size()); for (const nlohmann::json& id : lights) { - ids.push_back(std::stoi(id.get())); + // Luminaires can have null ids if not all light have been added + if (!id.is_null()) + { + ids.push_back(std::stoi(id.get())); + } } return ids; } @@ -141,8 +145,7 @@ std::string Group::getActionColorMode() const StateTransaction Group::transaction() { // Do not pass state, because it is not the state of ALL lights in the group - return StateTransaction( - state.getCommandAPI(), "/groups/" + std::to_string(id) + "/action", nullptr); + return StateTransaction(state.getCommandAPI(), "/groups/" + std::to_string(id) + "/action", nullptr); } void Group::setOn(bool on, uint8_t transition) @@ -256,6 +259,6 @@ nlohmann::json CreateGroup::getRequest() const CreateGroup::CreateGroup( const std::vector& lights, const std::string& name, const std::string& type, const std::string& roomType) : lights(lights), name(name), type(type), roomType(roomType) -{} +{ } } // namespace hueplusplus -- libgit2 0.21.4