Add ping and ability to control garage

This commit is contained in:
2024-12-18 22:11:41 +00:00
parent 26aadfb65f
commit da7c19714f
2 changed files with 10 additions and 2 deletions

View File

@@ -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 });
}
}
});