Skip to content

Commit

Permalink
fixing reconnect handling (#1627)
Browse files Browse the repository at this point in the history
After a reconnect the old heartbeat checker was not finished, but a new
heartbeat checker was created. After many reconnects, the checkers
stopped working because some checker always recognized a timeout and
caused a new reconnect.
  • Loading branch information
frankstolle authored Oct 7, 2024
1 parent 613e505 commit 4d0a842
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/homeAssistant/Websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ export default class Websocket {
this.isHomeAssistantRunning = false;
this.connectionState = ClientState.Connected;
if (this.#config.heartbeatInterval) {
this.#stopAssignedHeartbeat();
this.#stopHeartbeat = startHeartbeat(
this.client,
this.#config.heartbeatInterval,
Expand All @@ -581,11 +582,20 @@ export default class Websocket {
}

close(): void {
if (typeof this.#stopHeartbeat === 'function') this.#stopHeartbeat();
this.#stopAssignedHeartbeat();
this?.client?.close();
}

#stopAssignedHeartbeat(): void {
if (typeof this.#stopHeartbeat === 'function') {
const stopHeartbeat = this.#stopHeartbeat;
this.#stopHeartbeat = undefined;
stopHeartbeat();
}
}

resetClient(): void {
this.#stopAssignedHeartbeat();
this.integrationVersion = NO_VERSION;
this.isHomeAssistantRunning = false;
this.#servicesLoaded = false;
Expand Down

0 comments on commit 4d0a842

Please sign in to comment.