From 3d4b9b93b172d900a2f225fd8403ead21fc81dc8 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Fri, 21 Oct 2022 11:52:10 -0600 Subject: [PATCH 1/2] ensure all bulbs get updated over MQTT when using group 0 --- lib/MQTT/BulbStateUpdater.cpp | 12 ++++++++++-- lib/MQTT/BulbStateUpdater.h | 2 +- src/main.cpp | 4 +--- 3 files changed, 12 insertions(+), 6 deletions(-) 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..a9d572a2 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); From 15568ee9329176fd9f1290df91da90124c4dbc7f Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Fri, 21 Oct 2022 11:54:08 -0600 Subject: [PATCH 2/2] update MQTT state after a reconnect if there was no change, isMqttDirty() will be false and no packet will be sent --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index a9d572a2..f96b5744 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -251,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);