diff --git a/WebDisplay/src/pages/kiosk.vue b/WebDisplay/src/pages/kiosk.vue index 2be5788..60f40ed 100644 --- a/WebDisplay/src/pages/kiosk.vue +++ b/WebDisplay/src/pages/kiosk.vue @@ -148,7 +148,8 @@
+ v-if="homeAssistantStore?.garageState" + v-on:click="homeAssistantStore.toggleGarage()"> diff --git a/WebDisplay/src/stores/homeAssistantStore.ts b/WebDisplay/src/stores/homeAssistantStore.ts index 543d993..36af072 100644 --- a/WebDisplay/src/stores/homeAssistantStore.ts +++ b/WebDisplay/src/stores/homeAssistantStore.ts @@ -1,5 +1,5 @@ import { defineStore } from 'pinia'; -import { createConnection, subscribeEntities, createLongLivedTokenAuth, Connection } from 'home-assistant-js-websocket'; +import { createConnection, subscribeEntities, createLongLivedTokenAuth, Connection, callService } from 'home-assistant-js-websocket'; import Environment from '@/environment'; export const useHomeAssistantStore = defineStore('home-assistant', { @@ -36,10 +36,17 @@ export const useHomeAssistantStore = defineStore('home-assistant', { this.$patch({ houseAlarmState: houseAlarmEntity.state }); } }); + + setInterval(async () => await this._connection?.ping(), 5000); }, async stop() { this._connection?.close(); this._connection = null; + }, + async toggleGarage() { + const garageDevice = Environment.getGarageDevice(); + + callService(this._connection as Connection, 'cover', this.garageState === 'closed' ? 'open_cover' : 'close_cover', { entity_id: garageDevice }); } } });