forked from jghaanstra/cloud.shelly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
53 lines (48 loc) · 2.18 KB
/
api.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
const Homey = require('homey');
const util = require('/lib/util.js');
module.exports = [
{
description: 'Shelly App API Callback Events',
method : 'GET',
path : '/button_actions/:devicetype/:deviceid/:action',
public : true,
fn: function(args, callback) {
(async () => {
let device = await Homey.ManagerDrivers.getDriver(args.params.devicetype).getDevice({'id': args.params.deviceid});
// EXTRA ACTIONS SHELLY DW
if (args.params.devicetype == 'shellydw' && !device.getCapabilityValue('alarm_contact') && (args.params.action == 'open_dark' || args.params.action == 'open_twilight')) {
device.setCapabilityValue('alarm_contact', true);
} else if (args.params.devicetype == 'shellydw' && device.getCapabilityValue('alarm_contact') && args.params.action == 'close') {
device.setCapabilityValue('alarm_contact', false);
}
// EXTRA ACTIONS SHELLY FLOOD
if (args.params.devicetype == 'shellyflood' && !device.getCapabilityValue('alarm_water') && args.params.action == 'flood_detected') {
device.setCapabilityValue('alarm_contact', true);
} else if (args.params.devicetype == 'shellyflood' && device.getCapabilityValue('alarm_water') && args.params.action == 'flood_gone') {
device.setCapabilityValue('alarm_water', false);
}
let callbackTrigger = new Homey.FlowCardTrigger('triggerCallbacks');
callbackTrigger.register().trigger({"id": args.params.deviceid, "device": device.getName(), "action": args.params.action});
callback(false, 'OK');
})().catch(err => {
callback(err, false);
});
}
},
{
description: 'Shelly App API Status Callbacks',
method : 'GET',
path : '/report_status/:devicetype/:deviceid',
public : true,
fn: function(args, callback) {
(async () => {
console.log(args); // leave this in for sending debug reports
let device = await Homey.ManagerDrivers.getDriver(args.params.devicetype).getDevice({'id': args.params.deviceid});
await device.updateReportStatus(device, args.query);
callback(false, 'OK');
})().catch(err => {
callback(err, false);
});
}
}
]