forked from Koenkk/zigbee2mqtt.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreepad_ext.js
130 lines (121 loc) Β· 4.14 KB
/
freepad_ext.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const e = exposes.presets;
const ea = exposes.access;
const getKey = (object, value) => {
for (const key in object) {
if (object[key] == value) return key;
}
};
const bind = async (endpoint, target, clusters) => {
for (const cluster of clusters) {
await endpoint.bind(cluster, target);
}
};
const fzLocal = {
diyruz_freepad_clicks: {
cluster: 'genMultistateInput',
type: ['readResponse', 'attributeReport'],
convert: (model, msg, publish, options, meta) => {
const button = getKey(model.endpoint(msg.device), msg.endpoint.ID);
const lookup = {
0: 'hold',
1: 'single',
2: 'double',
3: 'triple',
4: 'quadruple',
255: 'release',
};
const clicks = msg.data['presentValue'];
const action = lookup[clicks] ? lookup[clicks] : `many_${clicks}`;
return {
action: `${button}_${action}`,
};
},
},
};
const tzLocal = {
diyruz_freepad_on_off_config: {
key: ['switch_type', 'switch_actions'],
convertSet: async (entity, key, value, meta) => {
const switchTypesLookup = {
toggle: 0x00,
momentary: 0x01,
multifunction: 0x02,
};
const switchActionsLookup = {
on: 0x00,
off: 0x01,
toggle: 0x02,
};
const intVal = parseInt(value, 10);
const switchType = switchTypesLookup.hasOwnProperty(value) ? switchTypesLookup[value] : intVal;
const switchActions = switchActionsLookup.hasOwnProperty(value) ? switchActionsLookup[value] : intVal;
const payloads = {
switch_type: {
switchType,
},
switch_actions: {
switchActions,
},
};
await entity.write('genOnOffSwitchCfg', payloads[key]);
},
},
};
const definition = {
zigbeeModel: ['DIYRuZ_FreePad_ext'],
model: 'DIYRuZ_FreePad_ext',
vendor: 'DIYRuZ',
description: '[DiY 8/12/20 button keypad](http://modkam.ru/?p=1114)',
fromZigbee: [fzLocal.diyruz_freepad_clicks, fz.battery],
toZigbee: [tzLocal.diyruz_freepad_on_off_config, tz.factory_reset],
exposes: [e.battery(), e.action([
'button_*_hold', 'button_*_single', 'button_*_double', 'button_*_triple', 'button_*_quadruple', 'button_*_release'])],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await bind(endpoint, coordinatorEndpoint, ['genPowerCfg']);
const payload = [{
attribute: 'batteryPercentageRemaining',
minimumReportInterval: 0,
maximumReportInterval: 3600,
reportableChange: 0,
}, {
attribute: 'batteryVoltage',
minimumReportInterval: 0,
maximumReportInterval: 3600,
reportableChange: 0,
}];
await endpoint.configureReporting('genPowerCfg', payload);
device.endpoints.forEach(async (ep) => {
await bind(ep, coordinatorEndpoint, ['genMultistateInput']);
});
},
endpoint: (device) => {
return {
button_1: 1,
button_2: 2,
button_3: 3,
button_4: 4,
button_5: 5,
button_6: 6,
button_7: 7,
button_8: 8,
button_9: 9,
button_10: 10,
button_11: 11,
button_12: 12,
button_13: 13,
button_14: 14,
button_15: 15,
button_16: 16,
button_17: 17,
button_18: 18,
button_19: 19,
button_20: 20,
};
},
};
module.exports = definition;