From 86c39c252f4de5a49b00b626ffa3042256e175d3 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Mon, 23 Dec 2024 15:55:33 +0000 Subject: [PATCH] Add stop for opening/closing of garage --- WebDisplay/src/stores/homeAssistantStore.ts | 26 +++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/WebDisplay/src/stores/homeAssistantStore.ts b/WebDisplay/src/stores/homeAssistantStore.ts index 36af072..b91e10b 100644 --- a/WebDisplay/src/stores/homeAssistantStore.ts +++ b/WebDisplay/src/stores/homeAssistantStore.ts @@ -23,7 +23,7 @@ export const useHomeAssistantStore = defineStore('home-assistant', { this._connection = await createConnection({ auth }); - subscribeEntities(this._connection as Connection, entities => { + subscribeEntities(this._connection as Connection, (entities) => { const garageEntity = entities[garageDevice]; if (garageEntity) { @@ -46,7 +46,29 @@ export const useHomeAssistantStore = defineStore('home-assistant', { async toggleGarage() { const garageDevice = Environment.getGarageDevice(); - callService(this._connection as Connection, 'cover', this.garageState === 'closed' ? 'open_cover' : 'close_cover', { entity_id: garageDevice }); + let action: string | null; + + switch (this.garageState) { + case 'closed': + action = 'open_cover'; + break; + case 'open': + action = 'close_cover'; + break; + case 'closing': + case 'opening': + action = 'stop_cover'; + break; + default: + action = null; + break; + } + + if (!action) { + return; + } + + callService(this._connection as Connection, 'cover', action, { entity_id: garageDevice }); } } });