mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Add ping and ability to control garage
This commit is contained in:
@@ -148,7 +148,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="kiosk-garage-door text-center pt-4"
|
class="kiosk-garage-door text-center pt-4"
|
||||||
v-if="homeAssistantStore?.garageState">
|
v-if="homeAssistantStore?.garageState"
|
||||||
|
v-on:click="homeAssistantStore.toggleGarage()">
|
||||||
<v-icon
|
<v-icon
|
||||||
class="kiosk-device-icon"
|
class="kiosk-device-icon"
|
||||||
:icon="homeAssistantStore.garageState === 'closed' ? 'mdi-garage' : 'mdi-garage-open'" />
|
:icon="homeAssistantStore.garageState === 'closed' ? 'mdi-garage' : 'mdi-garage-open'" />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from 'pinia';
|
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';
|
import Environment from '@/environment';
|
||||||
|
|
||||||
export const useHomeAssistantStore = defineStore('home-assistant', {
|
export const useHomeAssistantStore = defineStore('home-assistant', {
|
||||||
@@ -36,10 +36,17 @@ export const useHomeAssistantStore = defineStore('home-assistant', {
|
|||||||
this.$patch({ houseAlarmState: houseAlarmEntity.state });
|
this.$patch({ houseAlarmState: houseAlarmEntity.state });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setInterval(async () => await this._connection?.ping(), 5000);
|
||||||
},
|
},
|
||||||
async stop() {
|
async stop() {
|
||||||
this._connection?.close();
|
this._connection?.close();
|
||||||
this._connection = null;
|
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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user