-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
64 lines (51 loc) · 1.61 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
57
58
59
60
61
62
63
64
"use strict";
const Homey = require('homey')
const Settings = Homey.ManagerSettings;
const _settingsKey = 'com.ubnt.unifi.settings'
class UnifiApp extends Homey.App {
onInit() {
this.log('com.ubnt.unifi started...');
this.setStatus('Offline');
this.initSettings();
this.log('- Loaded settings', this.appSettings)
}
initSettings() {
let settingsInitialized = false;
Settings.getKeys().forEach(key => {
if (key == _settingsKey) {
settingsInitialized = true;
}
});
if (settingsInitialized) {
this.log('Found settings key', _settingsKey)
this.appSettings = Settings.get(_settingsKey);
return;
}
this.log('Freshly initializing com.ubnt.unifi.settings with some defaults')
this.updateSettings({
'host': 'unifi',
'port': '8443',
'user': 'ubnt',
'pass': 'ubnt',
'site': 'default'
});
}
updateSettings(settings) {
this.log('Got new settings:', settings)
this.appSettings = settings;
this.saveSettings();
Homey.ManagerDrivers.getDriver('wifi-client').getSettings(_settingsKey);
}
saveSettings() {
if (typeof this.appSettings === 'undefined') {
this.log('Not saving settings; settings empty!');
return;
}
this.log('Save settings.');
Settings.set(_settingsKey, this.appSettings)
}
setStatus(status) {
Settings.set('com.ubnt.unifi.status', status);
}
}
module.exports = UnifiApp;