-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
56 lines (42 loc) · 1.44 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
49
50
51
52
53
54
55
56
'use strict';
const { MyApp } = require('my-homey');
const { DINGZ } = require('./lib/dingzAPI');
const DingzNet = require('./lib/dingzNet');
module.exports = class DingzApp extends MyApp {
#onceDay = null;
static get DINGZ() {
return DINGZ;
}
async onInit() {
super.onInit();
// this.homey.settings.unset('mqtt'); // NOTE: Only for test
if (!this.homey.settings.get('mqtt')) {
await this.homey.settings.set('mqtt', JSON.stringify({
broker: 'localhost',
port: '1883',
user: 'dingzNet',
password: 'dingzNet',
}));
}
this.dingzNet = new DingzNet(this);
await this.dingzNet.initDingzNet(await this.getMqttBrokerUri());
}
async getMqttBrokerUri() {
const mqtt = JSON.parse(this.homey.settings.get('mqtt'));
const localAddress = (await this.homey.cloud.getLocalAddress()).split(':')[0];
return `mqtt://${mqtt.user}:${mqtt.password}@${mqtt.broker === 'localhost' || mqtt.broker === '127.0.0.1' ? localAddress : mqtt.broker}:${mqtt.port}`;
}
notifyDeviceWarning() {
// Only once a day
if (this.#onceDay !== new Date().toLocaleDateString()) {
this.#onceDay = new Date().toLocaleDateString();
this.notifyError('Your dingz devices are no longer working properly. Please read the "[App][Pro] dingz" documentation');
}
}
// NOTE: simplelog-api on/off
logDebug(msg) {
if (process.env.DEBUG === '1') {
super.logDebug(msg);
}
}
};