Skip to content

Commit

Permalink
Fix optimistic group state not published on startup. #3461
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Oct 10, 2020
1 parent ad09056 commit 723e3a3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/extension/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Extension = require('./extension');
const utils = require('../util/utils');
const postfixes = utils.getEndpointNames();
const stringify = require('json-stable-stringify-without-jsonify');
const equals = require('fast-deep-equal/es6');

const topicRegex =
new RegExp(`^${settings.get().mqtt.base_topic}/bridge/request/group/members/(remove|add|remove_all)$`);
Expand All @@ -15,6 +16,7 @@ class Groups extends Extension {
super(zigbee, mqtt, state, publishEntityState, eventBus);
this.onStateChange = this.onStateChange.bind(this);
this.legacyApi = settings.get().advanced.legacy_api;
this.lastOptimisticState = {};
}

onMQTTConnected() {
Expand Down Expand Up @@ -120,8 +122,9 @@ class Groups extends Extension {
if (resolvedEntity.type === 'device') {
for (const zigbeeGroup of zigbeeGroups) {
if (zigbeeGroup.hasMember(resolvedEntity.endpoint) &&
!utils.equalsPartial(this.state.get(zigbeeGroup.groupID) || {}, payload)) {
!equals(this.lastOptimisticState[zigbeeGroup.groupID], payload)) {
if (!payload || payload.state !== 'OFF' || this.areAllMembersOff(zigbeeGroup)) {
this.lastOptimisticState[zigbeeGroup.groupID] = payload;
await this.publishEntityState(zigbeeGroup.groupID, payload, reason);
}
}
Expand Down

0 comments on commit 723e3a3

Please sign in to comment.