Fix group and device states changing when cached states are published. https://github.com/Koenkk/zigbee2mqtt/issues/13028

This commit is contained in:
Koen Kanters
2022-07-12 17:01:29 +02:00
parent 4347034ba1
commit 420b34c909
4 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -157,7 +157,7 @@ class Controller {
if (settings.get().advanced.cache_state_send_on_startup && settings.get().advanced.cache_state) {
for (const entity of [...devices, ...this.zigbee.groups()]) {
if (this.state.exists(entity)) {
this.publishEntityState(entity, this.state.get(entity));
this.publishEntityState(entity, this.state.get(entity), 'publishCached');
}
}
}
+1 -1
View File
@@ -101,7 +101,7 @@ export default class Groups extends Extension {
@bind async onStateChange(data: eventdata.StateChange): Promise<void> {
const reason = 'groupOptimistic';
if (data.reason === reason) {
if (data.reason === reason || data.reason === 'publishCached') {
return;
}
+1 -1
View File
@@ -1337,7 +1337,7 @@ export default class HomeAssistant extends Extension {
// Publish all device states.
for (const entity of [...this.zigbee.devices(false), ...this.zigbee.groups()]) {
if (this.state.exists(entity)) {
this.publishEntityState(entity, this.state.get(entity));
this.publishEntityState(entity, this.state.get(entity), 'publishCached');
}
}
+1 -1
View File
@@ -42,7 +42,7 @@ declare global {
// Types
interface MQTTResponse {data: KeyValue, status: 'error' | 'ok', error?: string, transaction?: string}
interface MQTTOptions {qos?: mqtt.QoS, retain?: boolean, properties?: {messageExpiryInterval: number}}
type StateChangeReason = 'publishDebounce' | 'groupOptimistic' | 'lastSeenChanged';
type StateChangeReason = 'publishDebounce' | 'groupOptimistic' | 'lastSeenChanged' | 'publishCached';
type PublishEntityState = (entity: Device | Group, payload: KeyValue,
stateChangeReason?: StateChangeReason) => Promise<void>;
type RecursivePartial<T> = {[P in keyof T]?: RecursivePartial<T[P]>;};