-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
66 lines (54 loc) · 1.65 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
65
66
'use strict';
const Homey = require('homey');
const { HomeyAPI } = require('athom-api');
// Services
const Log = require("./Log.js");
//const DEBUG = process.env.DEBUG === '1';
//if (DEBUG) {
// require('inspector').open(9229, '0.0.0.0', false);
//}
class LightsManager extends Homey.App {
async getApi() {
if (!this._api) {
this._api = await HomeyAPI.forCurrentHomey();
}
return this._api;
}
async onInit() {
Log.info('Lights manager is running...');
//this.settings = Homey.ManagerSettings.get('settings') || {};
}
async getDevices() {
try {
const api = await this.getApi();
return await api.devices.getDevices();
} catch (e) {
Log.error(e);
}
}
async getZones() {
try {
const api = await this.getApi();
return await api.zones.getZones();
} catch (e) {
Log.error(e);
}
}
async settingsChanged() {
Log.info("Settings changed");
//this.settings = Homey.ManagerSettings.get('settings') || {};
//Log.debug(this.settings);
}
async setCapabilityValue(deviceId, capabilityId, value) {
if (typeof value === 'string') {
if (value === 'true') value = true;
if (value === 'false') value = false;
value = Number(value);
}
const state = { deviceId, capabilityId, value };
Log.debug("set " + capabilityId + ": " + JSON.stringify(state));
const api = await this.getApi();
await api.devices.setCapabilityValue(state);
}
}
module.exports = LightsManager;