Skip to content

Commit

Permalink
fix(integration): Handle errors when sending and unregistering entities
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Oct 1, 2024
1 parent 3319bf4 commit cb72c3f
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/common/integration/UnidirectionalEntityIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,13 @@ export default class UnidirectionalIntegration extends Integration {
attributes: Record<string, any>,
) {
const payload = this.getEntityPayload(state, attributes);
await this.homeAssistant.websocket.send(payload);
try {
await this.homeAssistant.websocket.send(payload);
} catch (err) {
this.entityConfigNode.error(
`Error updating entity. Error Message: ${err}`,
);
}
if (this.entityConfigNode.config.resend) {
const lastPayload = {
state,
Expand All @@ -240,7 +246,13 @@ export default class UnidirectionalIntegration extends Integration {

this.debugToClient('unregister', payload);

await this.homeAssistant?.websocket.send(payload);
try {
await this.homeAssistant?.websocket.send(payload);
} catch (err) {
this.entityConfigNode.error(
`Error unregistering entity. Error Message: ${err}`,
);
}
}

// device endpoints are only available in 1.1.0+
Expand All @@ -260,10 +272,16 @@ export default class UnidirectionalIntegration extends Integration {
`Removing device from Home Assistant: ${this.deviceConfigNode.config.name}`,
);

await this.homeAssistant?.websocket.send({
type: MessageType.RemoveDevice,
node_id: this.deviceConfigNode.id,
});
try {
await this.homeAssistant?.websocket.send({
type: MessageType.RemoveDevice,
node_id: this.deviceConfigNode.id,
});
} catch (err) {
this.deviceConfigNode.error(
`Error removing device. Error Message: ${err}`,
);
}
}

protected debugToClient(topic: string, message: any) {
Expand Down

0 comments on commit cb72c3f

Please sign in to comment.