From fc6224150918e8241642d6c8bfc92a7be42cc328 Mon Sep 17 00:00:00 2001 From: jason <37859597+zachowj@users.noreply.github.com> Date: Sun, 15 Sep 2024 23:27:55 -0700 Subject: [PATCH] fix(comms): update stateChanged handling to use HassEntity and prevent null entries --- src/nodes/config-server/Comms.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/nodes/config-server/Comms.ts b/src/nodes/config-server/Comms.ts index f2b58f353b..849046f14e 100644 --- a/src/nodes/config-server/Comms.ts +++ b/src/nodes/config-server/Comms.ts @@ -9,6 +9,7 @@ import { ClientEvent } from '../../homeAssistant/Websocket'; import { HassArea, HassDevice, + HassEntity, HassEntityRegistryEntry, HassFloor, HassLabel, @@ -85,7 +86,7 @@ export default class Comms { this.publish('services', services); } - #stateChangedBatchedUpdates: Map = new Map(); + #stateChangedBatchedUpdates: Map = new Map(); #throttledStateChangedPublish = throttle(() => { this.publish( 'entity', @@ -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(); }