forked from chaosfish/com.xiaomi-mi-zigbee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·63 lines (49 loc) · 2.41 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
'use strict';
const Homey = require('homey');
const Log = require('homey-log').Log;
class XiaomiZigbee extends Homey.App {
onInit() {
this.log('Xiaomi Zigbee app is running...');
this.triggerButton1_scene = new Homey.FlowCardTriggerDevice('trigger_button1_scene');
this.triggerButton1_scene
.register()
.registerRunListener((args, state) => Promise.resolve(args.scene.id === state.scene))
.getArgument('scene')
.registerAutocompleteListener((query, args, callback) => args.device.onSceneAutocomplete(query, args, callback));
this.triggerButton2_scene = new Homey.FlowCardTriggerDevice('trigger_button2_scene');
this.triggerButton2_scene
.register()
.registerRunListener((args, state) =>
Promise.resolve(args.button.id === state.button && args.scene.id === state.scene));
this.triggerButton2_scene
.getArgument('scene')
.registerAutocompleteListener((query, args, callback) => args.device.onSceneAutocomplete(query, args, callback));
this.triggerButton2_scene
.getArgument('button')
.registerAutocompleteListener((query, args, callback) => args.device.onButtonAutocomplete(query, args, callback));
// Register triggers for flows
this._triggerSwitchTwoTurnedOn = new Homey.FlowCardTriggerDevice('trigger_switch2_turned_on').register();
this._triggerSwitchTwoTurnedOff = new Homey.FlowCardTriggerDevice('trigger_switch2_turned_off').register();
// Register conditions for flows
this._conditionSwitchTwoIsOn = new Homey.FlowCardCondition('condition_switch2_is_on')
.register()
.registerRunListener((args, state) => {
this.log('FlowCardCondition evalutated for', args.device.getName(), ', device state: ', args.device.getCapabilityValue('onoff.1'));
return args.device.getCapabilityValue('onoff.1');
});
// Register actions for flows
this._actionSwitchTwoTurnOff = new Homey.FlowCardAction('action_turn_on_switch2')
.register()
.registerRunListener((args, state) => {
this.log('FlowCardAction triggered for ', args.device.getName(), 'to switch on');
return args.device.triggerCapabilityListener('onoff.1', true, {});
});
this._actionSwitchTwoTurnOff = new Homey.FlowCardAction('action_turn_off_switch2')
.register()
.registerRunListener((args, state) => {
this.log('FlowCardAction triggered for ', args.device.getName(), 'to switch off');
return args.device.triggerCapabilityListener('onoff.1', false, {});
});
}
}
module.exports = XiaomiZigbee;