mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-25 09:35:39 -05:00
Add ping and ability to control garage
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user