Add stop for opening/closing of garage

This commit is contained in:
2024-12-23 15:55:33 +00:00
parent 5eb7d4a666
commit 86c39c252f

View File

@@ -23,7 +23,7 @@ export const useHomeAssistantStore = defineStore('home-assistant', {
this._connection = await createConnection({ auth }); this._connection = await createConnection({ auth });
subscribeEntities(this._connection as Connection, entities => { subscribeEntities(this._connection as Connection, (entities) => {
const garageEntity = entities[garageDevice]; const garageEntity = entities[garageDevice];
if (garageEntity) { if (garageEntity) {
@@ -46,7 +46,29 @@ export const useHomeAssistantStore = defineStore('home-assistant', {
async toggleGarage() { async toggleGarage() {
const garageDevice = Environment.getGarageDevice(); 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 });
} }
} }
}); });