Skip to content

Commit

Permalink
fix(time): Handle onStateChanged errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Sep 24, 2023
1 parent 4b12a49 commit 8365b5a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
19 changes: 5 additions & 14 deletions src/nodes/time/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import BaseError from '../../common/errors/BaseError';
import ClientEvents from '../../common/events/ClientEvents';
import Status from '../../common/status/Status';
import { TypedInputTypes } from '../../const';
import { getEntitiesFromJsonata } from '../../helpers/utils';
import HomeAssistant from '../../homeAssistant/HomeAssistant';
Expand All @@ -11,19 +9,8 @@ export function startListener(
clientEvents: ClientEvents,
controller: TimeController,
homeAssistant: HomeAssistant,
node: TimeNode,
status: Status
node: TimeNode
) {
if (homeAssistant.isHomeAssistantRunning) {
try {
controller.onStateChanged();
} catch (e) {
if (e instanceof BaseError) {
status.setError(e.message);
}
throw e;
}
}
clientEvents.addListener(
'ha_client:ready',
controller.onStateChanged.bind(controller)
Expand All @@ -46,4 +33,8 @@ export function startListener(
);
});
}

if (homeAssistant.isHomeAssistantRunning) {
clientEvents.emit(`ha_events:state_changed:${node.config.entityId}`);
}
}
2 changes: 1 addition & 1 deletion src/nodes/time/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ export default function timeNode(this: TimeNode, config: TimeNodeProperties) {
...controllerDeps,
});

startListener(clientEvents, controller, homeAssistant, this, status);
startListener(clientEvents, controller, homeAssistant, this);
}

0 comments on commit 8365b5a

Please sign in to comment.