forked from swttt/com.fibaro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (35 loc) · 1.76 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
'use strict';
const Homey = require('homey');
class FibaroApp extends Homey.App {
onInit() {
this.actionStartDimLevelChange = new Homey.FlowCardAction('FGD-21x_dim_startLevelChange')
.register()
.registerRunListener(this._actionStartDimLevelChangeRunListener.bind(this));
this.actionStopDimLevelChange = new Homey.FlowCardAction('FGD-21x_dim_stopLevelChange')
.register()
.registerRunListener(this._actionStopDimLevelChangeRunListener.bind(this));
}
async _actionStartDimLevelChangeRunListener(args, state) {
if (!args.hasOwnProperty('direction')) return Promise.reject('direction_property_missing');
args.device.log('FlowCardAction triggered to start dim level change in direction', args.direction);
const nodeCommandClassVersion = parseInt(args.device.node.CommandClass.COMMAND_CLASS_SWITCH_MULTILEVEL.version);
let startLevelChangeObj = {
'Properties1': new Buffer([args.direction === '1' ? (nodeCommandClassVersion > 2 ? 0x68 : 0x60) : 0x20]),
'Start Level': 0,
'Dimming Duration': args.duration / 1000 || 255, // if no duration has been set, use factory default (255),
'Step Size': 1,
}
if (args.device.node.CommandClass.COMMAND_CLASS_SWITCH_MULTILEVEL) {
return await args.device.node.CommandClass.COMMAND_CLASS_SWITCH_MULTILEVEL.SWITCH_MULTILEVEL_START_LEVEL_CHANGE(startLevelChangeObj);
}
return Promise.reject('unknown_error');
}
async _actionStopDimLevelChangeRunListener(args, state) {
args.device.log('FlowCardAction triggered to stop dim level change');
if (args.device.node.CommandClass.COMMAND_CLASS_SWITCH_MULTILEVEL) {
return await args.device.node.CommandClass.COMMAND_CLASS_SWITCH_MULTILEVEL.SWITCH_MULTILEVEL_STOP_LEVEL_CHANGE({});
}
return Promise.reject('unknown_error');
}
}
module.exports = FibaroApp;