forked from rogro82/io.homeassistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (33 loc) · 1.1 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const Homey = require('homey');
const Client = require('./lib/Client.js');
class App extends Homey.App {
onInit() {
super.onInit();
this.log('Home-Assistant is running...');
let address = Homey.ManagerSettings.get("address");
let token = Homey.ManagerSettings.get("token");
this._client = new Client(address, token)
.on("connection_update", (state) => {
Homey.ManagerApi.realtime('connection_update', state);
});
this._onFlowActionCallService = this._onFlowActionCallService.bind(this);
new Homey.FlowCardAction('callService')
.register()
.registerRunListener( this._onFlowActionCallService );
Homey.ManagerSettings.on("set", this._reconnectClient.bind(this));
}
getClient() {
return this._client;
}
_reconnectClient(arg) {
console.log("settings updated.... reconnecting");
let address = Homey.ManagerSettings.get("address");
let token = Homey.ManagerSettings.get("token");
this._client.connect(address, token, true);
}
_onFlowActionCallService(args) {
this._client.callService(args.domain, args.service, args.data);
}
}
module.exports = App;