Skip to content

Commit

Permalink
fix(issues): Wait until HA is in running state to check issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Aug 28, 2024
1 parent e1c4e4e commit fdda4fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/common/services/IssueService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,15 @@ export default class IssueService {
case IssueType.StateId: {
// listen for state changes to check if the issue is fixed
const eventName = `ha_events:state_changed:${issue.identity}`;
const onEvent = throttle((event: HassStateChangedEvent) => {
const onEvent = (event: HassStateChangedEvent) => {
if (event.entity_id === issue.identity) {
const foundIssues = this.#checkForIssues(node);
// if the issue is still present, keep listening
if (!includesIssue(foundIssues, issue)) {
ha.eventBus.off(eventName, onEvent);
}
}
}, 500);
};
ha.eventBus.on(eventName, onEvent);
break;
}
Expand All @@ -336,13 +336,13 @@ export default class IssueService {
issue.type as keyof typeof IssueTypeToRegistryEventMap
];
// listen for registry changes to check if the issue is fixed
const onEvent = throttle(() => {
const onEvent = () => {
const foundIssues = this.#checkForIssues(node);
// if the issue is still present, keep listening
if (!includesIssue(foundIssues, issue)) {
ha.eventBus.off(event, onEvent);
}
}, 500);
};
ha.eventBus.on(event, onEvent);
}

Expand Down
4 changes: 3 additions & 1 deletion src/homeAssistant/Websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ export default class Websocket {
this.#isFloorRegistryLoaded &&
this.#isLabelRegistryLoaded &&
this.isStatesLoaded &&
this.#servicesLoaded
this.#servicesLoaded &&
this.isHomeAssistantRunning
) {
this.#emitEvent(ClientEvent.RegistriesLoaded);
this.#isAllRegistriesLoaded = true;
Expand All @@ -320,6 +321,7 @@ export default class Websocket {
#onHomeAssistantRunning() {
if (!this.isHomeAssistantRunning) {
this.isHomeAssistantRunning = true;
this.#checkIfAllRegistriesLoaded();
this.#emitEvent(ClientEvent.Running);
if (this.integrationVersion === NO_VERSION) {
this.createIntegrationEvent(INTEGRATION_NOT_LOADED);
Expand Down

0 comments on commit fdda4fd

Please sign in to comment.