diff --git a/lib/MQTT/BulbStateUpdater.cpp b/lib/MQTT/BulbStateUpdater.cpp index 7bd8ce51..a609af28 100644 --- a/lib/MQTT/BulbStateUpdater.cpp +++ b/lib/MQTT/BulbStateUpdater.cpp @@ -17,11 +17,19 @@ void BulbStateUpdater::disable() { this->enabled = false; } -void BulbStateUpdater::enqueueUpdate(BulbId bulbId, GroupState& groupState) { +void BulbStateUpdater::enqueueUpdate(BulbId bulbId) { staleGroups.push(bulbId); + // if this was to group 0, we need to enqueue an update for all child groups as well + if (bulbId.groupId == 0) { + const MiLightRemoteConfig* remote = MiLightRemoteConfig::fromType(bulbId.deviceType); + + for (size_t i = 1; i <= remote->numGroups; i++) { + bulbId.groupId = i; + staleGroups.push(bulbId); + } + } //Remember time, when queue was added for debounce delay lastQueue = millis(); - } void BulbStateUpdater::loop() { diff --git a/lib/MQTT/BulbStateUpdater.h b/lib/MQTT/BulbStateUpdater.h index c89851c1..3f970907 100644 --- a/lib/MQTT/BulbStateUpdater.h +++ b/lib/MQTT/BulbStateUpdater.h @@ -14,7 +14,7 @@ class BulbStateUpdater { public: BulbStateUpdater(Settings& settings, MqttClient& mqttClient, GroupStateStore& stateStore); - void enqueueUpdate(BulbId bulbId, GroupState& groupState); + void enqueueUpdate(BulbId bulbId); void loop(); void enable(); void disable(); diff --git a/src/main.cpp b/src/main.cpp index 1c76567d..f96b5744 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -128,9 +128,7 @@ void onPacketSentHandler(uint8_t* packet, const MiLightRemoteConfig& config) { mqttClient->sendUpdate(remoteConfig, bulbId.deviceId, bulbId.groupId, output); // Sends the entire state - if (groupState != NULL) { - bulbStateUpdater->enqueueUpdate(bulbId, *groupState); - } + bulbStateUpdater->enqueueUpdate(bulbId); } httpServer->handlePacketSent(packet, remoteConfig); @@ -253,6 +251,10 @@ void applySettings() { settings.deletedGroupIdAliases.clear(); } + // make sure state is up to date + for (auto itr = settings.groupIdAliases.begin(); itr != settings.groupIdAliases.end(); ++itr) { + bulbStateUpdater->enqueueUpdate(itr->second); + } }); bulbStateUpdater = new BulbStateUpdater(settings, *mqttClient, *stateStore);