Skip to content

Commit

Permalink
fix: handle websocket unsubscribe errors gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
punxaphil committed Oct 28, 2024
1 parent 3ef5955 commit 6871380
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/services/hass-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,20 @@ export default class HassService {
return new Promise<HassEntity[]>(async (resolve) => {
const subscribeMessage = {
type: 'render_template',
template: "{{ device_entities(device_id('" + player.id + "')) }}",
template: `{{ device_entities(device_id('${player.id}')) }}`,
};
try {
const unsubscribe = await this.hass.connection.subscribeMessage<TemplateResult>((response) => {
unsubscribe();
resolve(
response.result
.filter((item: string) => entityTypes.some((type) => item.includes(type)))
.map((item) => this.hass.states[item]),
);
try {
unsubscribe();
resolve(
response.result
.filter((item: string) => entityTypes.some((type) => item.includes(type)))
.map((item) => this.hass.states[item]),
);
} catch {
resolve([]);
}
}, subscribeMessage);
} catch {
resolve([]);
Expand Down

0 comments on commit 6871380

Please sign in to comment.