-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
43 lines (36 loc) · 1.04 KB
/
app.ts
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
import { Client } from '@dominicvonk/fah';
import Homey from 'homey';
class MyApp extends Homey.App {
/**
* onInit is called when the app is initialized.
*/
_client?: Client;
async onInit () {
this.log('MyApp has been initialized');
const username = this.homey.settings.get('username');
const password = this.homey.settings.get('password');
const ip = this.homey.settings.get('ip');
this._client = new Client(ip, username, password);
if (username && password && ip) {
try {
await this._client.start();
} catch (error) {
}
}
this.homey.settings.on("set", this._reconnectClient.bind(this));
}
getClient () {
return this._client;
}
async _reconnectClient (arg: any) {
const username = this.homey.settings.get('username');
const password = this.homey.settings.get('password');
const ip = this.homey.settings.get('ip');
try {
await this._client?.updateLogin(ip, username, password);
} catch {
}
}
}
module.exports = MyApp;
export default MyApp;