Skip to content

Commit

Permalink
fix(comms): update stateChanged handling to use HassEntity and preven…
Browse files Browse the repository at this point in the history
…t null entries
  • Loading branch information
zachowj committed Sep 16, 2024
1 parent 4554a9a commit fc62241
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/nodes/config-server/Comms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ClientEvent } from '../../homeAssistant/Websocket';
import {
HassArea,
HassDevice,
HassEntity,
HassEntityRegistryEntry,
HassFloor,
HassLabel,
Expand Down Expand Up @@ -85,7 +86,7 @@ export default class Comms {
this.publish('services', services);
}

#stateChangedBatchedUpdates: Map<string, HassStateChangedEvent> = new Map();
#stateChangedBatchedUpdates: Map<string, HassEntity> = new Map();
#throttledStateChangedPublish = throttle(() => {
this.publish(
'entity',
Expand All @@ -95,7 +96,9 @@ export default class Comms {
}, 1000);

onStateChanged(event: HassStateChangedEvent): void {
this.#stateChangedBatchedUpdates.set(event.entity_id, event);
const entity = event.event.new_state;
if (!entity) return;
this.#stateChangedBatchedUpdates.set(event.entity_id, entity);
this.#throttledStateChangedPublish();
}

Expand Down

0 comments on commit fc62241

Please sign in to comment.