Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT fixes #779

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/MQTT/BulbStateUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just group 0? Depending on your remote type you have 4 or 8 groups.

Also, this code reads as:
If group == 0 then update this current bulb in all groups with this new state.

While i'd expect it to read as:
if this bulb is a group, set the state to all bulbs in this group to this new state.

I could be completely wrong here, just explaining how i read the code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you're reading it incorrectly. a BulbId consists of a deviceId and a groupId (and a deviceType, which tells us if the device supports 4 or 8 groups). the deviceId corresponds to the particular fut089 remote for example. groupId 0 is a special group that means "all groups on this device". so this code says "if we're marking group 0 stale, find out how many groups this particular device type supports, and mark all groups on that device (note that it's reusing bulbId, without modifying its deviceId) as stale as well".

note that all "bulbs" are a "group", since you can synchronize as many physical bulbs as you want to a given group id (but not 0!). For example, I have a FUT089. The groups are:

  • Group 1: a single channel LED strip controller
  • Group 2: 4 RGB+CCT downlights
  • Group 3: 12 RGB+CCT downlights
  • Group 4: 4 RGB+CCT adjustable downlights
  • Group 5: two RGB+CCT LED strip controllers
  • Group 6: a RGB+CCT LED strip controller
  • Group 7: a single channel LED strip controller
  • Group 8: 4 RGB+CCT downlight

And then Group 0 is the All group.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for that explanation, that's much appreciated!
Perhaps a comment in code explaining this a little would be helpful?

The people actively hacking on this code probably know it and to them - like you - it's "common knowledge" by now. But newcomers are going to have a hard time understanding what's going on.

Side note, not a review at all. Just a comment from a fellow developer :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The people actively hacking on this code

Lulz. Soo.... no one apparently. Two commits in the last two years. This PR having gotten no response from @sidoh in a year and a half. That's why I added the precompiled binary as a release in my fork. If @sidoh indicates interest in actually merging this, I'll worry about it then.

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() {
Expand Down
2 changes: 1 addition & 1 deletion lib/MQTT/BulbStateUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down