iobroker.zigbee 1.8.23 → 1.8.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +422 -415
- package/admin/adapter-settings.js +244 -244
- package/admin/admin.js +2991 -2981
- package/admin/i18n/de/translations.json +108 -108
- package/admin/i18n/en/translations.json +108 -108
- package/admin/i18n/es/translations.json +102 -102
- package/admin/i18n/fr/translations.json +108 -108
- package/admin/i18n/it/translations.json +102 -102
- package/admin/i18n/nl/translations.json +108 -108
- package/admin/i18n/pl/translations.json +108 -108
- package/admin/i18n/pt/translations.json +102 -102
- package/admin/i18n/ru/translations.json +108 -108
- package/admin/i18n/uk/translations.json +108 -108
- package/admin/i18n/zh-cn/translations.json +102 -102
- package/admin/img/LED1923R5.png +0 -0
- package/admin/img/philips_hue_lom001.png +0 -0
- package/admin/index.html +163 -159
- package/admin/index_m.html +1360 -1356
- package/admin/moment.min.js +1 -1
- package/admin/shuffle.min.js +2 -2
- package/admin/tab_m.html +1021 -1009
- package/admin/vis-network.min.css +1 -1
- package/admin/vis-network.min.js +26 -27
- package/admin/words.js +110 -110
- package/docs/de/basedocu.md +19 -19
- package/docs/de/readme.md +126 -126
- package/docs/en/readme.md +128 -128
- package/docs/flashing_via_arduino_(en).md +110 -110
- package/docs/ru/readme.md +28 -28
- package/docs/tutorial/groups-1.png +0 -0
- package/docs/tutorial/groups-2.png +0 -0
- package/docs/tutorial/tab-dev-1.png +0 -0
- package/io-package.json +41 -40
- package/lib/backup.js +171 -171
- package/lib/binding.js +319 -319
- package/lib/colors.js +465 -465
- package/lib/commands.js +534 -534
- package/lib/developer.js +151 -145
- package/lib/devices.js +3139 -3135
- package/lib/exclude.js +162 -162
- package/lib/exposes.js +913 -913
- package/lib/groups.js +345 -345
- package/lib/json.js +59 -59
- package/lib/networkmap.js +55 -55
- package/lib/ota.js +198 -198
- package/lib/rgb.js +297 -297
- package/lib/seriallist.js +48 -48
- package/lib/states.js +6420 -6420
- package/lib/statescontroller.js +672 -672
- package/lib/tools.js +54 -54
- package/lib/utils.js +165 -165
- package/lib/zbBaseExtension.js +36 -36
- package/lib/zbDelayedAction.js +144 -144
- package/lib/zbDeviceAvailability.js +319 -319
- package/lib/zbDeviceConfigure.js +151 -147
- package/lib/zbDeviceEvent.js +48 -48
- package/lib/zigbeecontroller.js +1014 -989
- package/main.js +2 -2
- package/package.json +14 -14
- package/support/docgen.js +93 -93
package/lib/exposes.js
CHANGED
|
@@ -1,913 +1,913 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
|
|
4
|
-
const statesDefs = require('./states.js').states;
|
|
5
|
-
const rgb = require('./rgb.js');
|
|
6
|
-
const utils = require('./utils.js');
|
|
7
|
-
const colors = require('./colors.js');
|
|
8
|
-
const ea =
|
|
9
|
-
|
|
10
|
-
function genState(expose, role, name, desc) {
|
|
11
|
-
let state;
|
|
12
|
-
const readable = (expose.access & ea.STATE) > 0;
|
|
13
|
-
const writable = (expose.access & ea.SET) > 0;
|
|
14
|
-
const stname = (name || expose.property);
|
|
15
|
-
if (typeof stname !== 'string') return;
|
|
16
|
-
const stateId = stname.replace(/\*/g, '');
|
|
17
|
-
const stateName = (desc || expose.description || expose.name);
|
|
18
|
-
const propName = expose.property;
|
|
19
|
-
switch (expose.type) {
|
|
20
|
-
case 'binary':
|
|
21
|
-
state = {
|
|
22
|
-
id: stateId,
|
|
23
|
-
prop: propName,
|
|
24
|
-
name: stateName,
|
|
25
|
-
icon: undefined,
|
|
26
|
-
role: role || 'state',
|
|
27
|
-
write: writable,
|
|
28
|
-
read: true,
|
|
29
|
-
type: 'boolean',
|
|
30
|
-
};
|
|
31
|
-
if (readable) {
|
|
32
|
-
state.getter = payload => payload[propName] === (expose.value_on || 'ON');
|
|
33
|
-
} else {
|
|
34
|
-
state.getter = payload => undefined;
|
|
35
|
-
}
|
|
36
|
-
if (writable) {
|
|
37
|
-
state.setter = (value) => (value) ? (expose.value_on || 'ON') : ((expose.value_off != undefined) ? expose.value_off : 'OFF');
|
|
38
|
-
state.setattr = expose.name;
|
|
39
|
-
}
|
|
40
|
-
if (expose.endpoint) {
|
|
41
|
-
state.epname = expose.endpoint;
|
|
42
|
-
}
|
|
43
|
-
break;
|
|
44
|
-
|
|
45
|
-
case 'numeric':
|
|
46
|
-
state = {
|
|
47
|
-
id: stateId,
|
|
48
|
-
prop: propName,
|
|
49
|
-
name: stateName,
|
|
50
|
-
icon: undefined,
|
|
51
|
-
role: role || 'state',
|
|
52
|
-
write: writable,
|
|
53
|
-
read: true,
|
|
54
|
-
type: 'number',
|
|
55
|
-
min: expose.value_min || 0,
|
|
56
|
-
max: expose.value_max,
|
|
57
|
-
unit: expose.unit,
|
|
58
|
-
};
|
|
59
|
-
if (expose.endpoint) {
|
|
60
|
-
state.epname = expose.endpoint;
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
|
|
64
|
-
case 'enum':
|
|
65
|
-
state = {
|
|
66
|
-
id: stateId,
|
|
67
|
-
prop: propName,
|
|
68
|
-
name: stateName,
|
|
69
|
-
icon: undefined,
|
|
70
|
-
role: role || 'state',
|
|
71
|
-
write: writable,
|
|
72
|
-
read: true,
|
|
73
|
-
type: 'string',
|
|
74
|
-
states: {},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
for (const val of expose.values) {
|
|
78
|
-
// if a definition of a enum states
|
|
79
|
-
if (val == '') {
|
|
80
|
-
state.states[propName] = propName;
|
|
81
|
-
} else {
|
|
82
|
-
state.states[val] = val;
|
|
83
|
-
}
|
|
84
|
-
state.type = typeof (val);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
switch (state.type) {
|
|
88
|
-
case 'boolean':
|
|
89
|
-
state.def = false;
|
|
90
|
-
break;
|
|
91
|
-
case 'number':
|
|
92
|
-
state.def = 0;
|
|
93
|
-
break;
|
|
94
|
-
case 'object':
|
|
95
|
-
state.def = {};
|
|
96
|
-
break;
|
|
97
|
-
case 'string':
|
|
98
|
-
state.def = '';
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// if a definition of a special button
|
|
103
|
-
if (state.states == ':') {
|
|
104
|
-
state.states = propName + ':' + propName;
|
|
105
|
-
state.type = 'object';
|
|
106
|
-
}
|
|
107
|
-
if (expose.endpoint) {
|
|
108
|
-
state.epname = expose.endpoint;
|
|
109
|
-
state.setattr = expose.name;
|
|
110
|
-
}
|
|
111
|
-
break;
|
|
112
|
-
|
|
113
|
-
case 'text':
|
|
114
|
-
state = {
|
|
115
|
-
id: stateId,
|
|
116
|
-
prop: propName,
|
|
117
|
-
name: stateName,
|
|
118
|
-
icon: undefined,
|
|
119
|
-
role: role || 'state',
|
|
120
|
-
write: writable,
|
|
121
|
-
read: true,
|
|
122
|
-
type: 'string',
|
|
123
|
-
};
|
|
124
|
-
if (expose.endpoint) {
|
|
125
|
-
state.epname = expose.endpoint;
|
|
126
|
-
}
|
|
127
|
-
break;
|
|
128
|
-
|
|
129
|
-
default:
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return state;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function createFromExposes(model, def) {
|
|
137
|
-
const states = [];
|
|
138
|
-
// make the different (set and get) part of state is updatable if different exposes is used for get and set
|
|
139
|
-
// as example:
|
|
140
|
-
// ...
|
|
141
|
-
// exposes.binary('some_option', ea.STATE, true, false).withDescription('Some Option'),
|
|
142
|
-
// exposes.composite('options', 'options')
|
|
143
|
-
// .withDescription('Some composite Options')
|
|
144
|
-
// .withFeature(exposes.binary('some_option', ea.SET, true, false).withDescription('Some Option'))
|
|
145
|
-
//in this case one state - `some_option` has two different exposes for set an get, we have to combine it ...
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
function pushToStates(state, access) {
|
|
149
|
-
if (state === undefined) {
|
|
150
|
-
return 0;
|
|
151
|
-
}
|
|
152
|
-
if (access === undefined) {
|
|
153
|
-
access = ea.ALL;
|
|
154
|
-
}
|
|
155
|
-
state.readable = (access & ea.STATE) > 0;
|
|
156
|
-
state.writable = (access & ea.SET) > 0;
|
|
157
|
-
const stateExists = states.findIndex((element, index, array) => element.id === state.id);
|
|
158
|
-
if (stateExists < 0) {
|
|
159
|
-
state.write = state.writable;
|
|
160
|
-
if (!state.writable) {
|
|
161
|
-
if (state.hasOwnProperty('setter')) {
|
|
162
|
-
delete state.setter;
|
|
163
|
-
}
|
|
164
|
-
if (state.hasOwnProperty('setattr')) {
|
|
165
|
-
delete state.setattr;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (!state.readable) {
|
|
169
|
-
if (state.hasOwnProperty('getter')) {
|
|
170
|
-
// to awoid some warnings on unprocessed data
|
|
171
|
-
state.getter = payload => undefined;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return states.push(state);
|
|
175
|
-
} else {
|
|
176
|
-
if ((state.readable) && (!states[stateExists].readable)) {
|
|
177
|
-
states[stateExists].read = state.read;
|
|
178
|
-
// as state is readable, it can't be button or event
|
|
179
|
-
if (states[stateExists].role === 'button') {
|
|
180
|
-
states[stateExists].role = state.role;
|
|
181
|
-
}
|
|
182
|
-
if (states[stateExists].hasOwnProperty('isEvent')) {
|
|
183
|
-
delete states[stateExists].isEvent;
|
|
184
|
-
}
|
|
185
|
-
// we have to use the getter from "new" state
|
|
186
|
-
if (state.hasOwnProperty('getter')) {
|
|
187
|
-
states[stateExists].getter = state.getter;
|
|
188
|
-
}
|
|
189
|
-
// trying to remove the `prop` property, as main key for get and set,
|
|
190
|
-
// as it can be different in new and old states, and leave only:
|
|
191
|
-
// setattr for old and id for new
|
|
192
|
-
if ((state.hasOwnProperty('prop')) && (state.prop === state.id)) {
|
|
193
|
-
if (states[stateExists].hasOwnProperty('prop')) {
|
|
194
|
-
if (states[stateExists].prop !== states[stateExists].id) {
|
|
195
|
-
if (!states[stateExists].hasOwnProperty('setattr')) {
|
|
196
|
-
states[stateExists].setattr = states[stateExists].prop;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
delete states[stateExists].prop;
|
|
200
|
-
}
|
|
201
|
-
} else if (state.hasOwnProperty('prop')) {
|
|
202
|
-
states[stateExists].prop = state.prop;
|
|
203
|
-
}
|
|
204
|
-
states[stateExists].readable = true;
|
|
205
|
-
}
|
|
206
|
-
if ((state.writable) && (!states[stateExists].writable)) {
|
|
207
|
-
states[stateExists].write = state.writable;
|
|
208
|
-
// use new state `setter`
|
|
209
|
-
if (state.hasOwnProperty('setter')) {
|
|
210
|
-
states[stateExists].setter = state.setter;
|
|
211
|
-
}
|
|
212
|
-
// use new state `setterOpt`
|
|
213
|
-
if (state.hasOwnProperty('setterOpt')) {
|
|
214
|
-
states[stateExists].setterOpt = state.setterOpt;
|
|
215
|
-
}
|
|
216
|
-
// use new state `inOptions`
|
|
217
|
-
if (state.hasOwnProperty('inOptions')) {
|
|
218
|
-
states[stateExists].inOptions = state.inOptions;
|
|
219
|
-
}
|
|
220
|
-
// as we have new state, responsible for set, we have to use new `isOption`
|
|
221
|
-
// or remove it
|
|
222
|
-
if (((!state.hasOwnProperty('isOption')) || (state.isOptions === false))
|
|
223
|
-
&& (states[stateExists].hasOwnProperty('isOption'))) {
|
|
224
|
-
delete states[stateExists].isOption;
|
|
225
|
-
} else {
|
|
226
|
-
states[stateExists].isOption = state.isOption;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// use new `setattr` or `prop` as `setattr`
|
|
230
|
-
if (state.hasOwnProperty('setattr')) {
|
|
231
|
-
states[stateExists].setattr = state.setattr;
|
|
232
|
-
} else if (state.hasOwnProperty('prop')) {
|
|
233
|
-
states[stateExists].setattr = state.prop;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// remove `prop` equal to if, due to prop is uses as key in set and get
|
|
237
|
-
if (states[stateExists].prop === states[stateExists].id) {
|
|
238
|
-
delete states[stateExists].prop;
|
|
239
|
-
}
|
|
240
|
-
if (state.hasOwnProperty('epname')) {
|
|
241
|
-
states[stateExists].epname = state.epname;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
states[stateExists].writable = true;
|
|
245
|
-
}
|
|
246
|
-
return states.length;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const icon = utils.getDeviceIcon(def);
|
|
251
|
-
for (const expose of def.exposes) {
|
|
252
|
-
let state;
|
|
253
|
-
|
|
254
|
-
switch (expose.type) {
|
|
255
|
-
case 'light':
|
|
256
|
-
for (const prop of expose.features) {
|
|
257
|
-
switch (prop.name) {
|
|
258
|
-
case 'state': {
|
|
259
|
-
const stateNameS = expose.endpoint ? `state_${expose.endpoint}` : 'state';
|
|
260
|
-
pushToStates({
|
|
261
|
-
id: stateNameS,
|
|
262
|
-
name: `Switch state ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
263
|
-
icon: undefined,
|
|
264
|
-
role: 'switch',
|
|
265
|
-
write: true,
|
|
266
|
-
read: true,
|
|
267
|
-
type: 'boolean',
|
|
268
|
-
getter: (payload) => (payload[stateNameS] === (prop.value_on || 'ON')),
|
|
269
|
-
setter: (value) => (value) ? prop.value_on || 'ON' : ((prop.value_off != undefined) ? prop.value_off : 'OFF'),
|
|
270
|
-
epname: expose.endpoint,
|
|
271
|
-
setattr: 'state',
|
|
272
|
-
}, prop.access);
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
case 'brightness': {
|
|
277
|
-
const stateNameB = expose.endpoint ? `brightness_${expose.endpoint}` : 'brightness';
|
|
278
|
-
pushToStates({
|
|
279
|
-
id: stateNameB,
|
|
280
|
-
name: `Brightness ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
281
|
-
icon: undefined,
|
|
282
|
-
role: 'level.dimmer',
|
|
283
|
-
write: true,
|
|
284
|
-
read: true,
|
|
285
|
-
type: 'number',
|
|
286
|
-
min: 0, // ignore expose.value_min
|
|
287
|
-
max: 100, // ignore expose.value_max
|
|
288
|
-
inOptions: true,
|
|
289
|
-
getter: payload => utils.bulbLevelToAdapterLevel(payload[stateNameB]),
|
|
290
|
-
setter: value => utils.adapterLevelToBulbLevel(value),
|
|
291
|
-
setterOpt: (value, options) => {
|
|
292
|
-
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
293
|
-
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
294
|
-
const preparedOptions = {...options, transition: transitionTime};
|
|
295
|
-
preparedOptions.brightness = utils.adapterLevelToBulbLevel(value);
|
|
296
|
-
return preparedOptions;
|
|
297
|
-
},
|
|
298
|
-
readResponse: resp => {
|
|
299
|
-
const respObj = resp[0];
|
|
300
|
-
if (respObj.status === 0 && respObj.attrData != undefined) {
|
|
301
|
-
return utils.bulbLevelToAdapterLevel(respObj.attrData);
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
epname: expose.endpoint,
|
|
305
|
-
setattr: 'brightness',
|
|
306
|
-
}, prop.access);
|
|
307
|
-
pushToStates(statesDefs.brightness_move, prop.access);
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
case 'color_temp': {
|
|
311
|
-
const stateNameT = expose.endpoint ? `colortemp_${expose.endpoint}` : 'colortemp';
|
|
312
|
-
pushToStates(
|
|
313
|
-
{
|
|
314
|
-
id: stateNameT,
|
|
315
|
-
prop: expose.endpoint ? `color_temp_${expose.endpoint}` : 'color_temp',
|
|
316
|
-
name: `Color temperature ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
317
|
-
icon: undefined,
|
|
318
|
-
role: 'level.color.temperature',
|
|
319
|
-
write: true,
|
|
320
|
-
read: true,
|
|
321
|
-
type: 'number',
|
|
322
|
-
// Ignore min and max value, so setting mireds and Kelvin with conversion to mireds works.
|
|
323
|
-
// https://github.com/ioBroker/ioBroker.zigbee/pull/1433#issuecomment-1113837035
|
|
324
|
-
min: undefined,
|
|
325
|
-
max: undefined,
|
|
326
|
-
setter: value => utils.toMired(value),
|
|
327
|
-
setterOpt: (value, options) => {
|
|
328
|
-
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
329
|
-
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
330
|
-
return {...options, transition: transitionTime};
|
|
331
|
-
},
|
|
332
|
-
epname: expose.endpoint,
|
|
333
|
-
setattr: 'color_temp',
|
|
334
|
-
},
|
|
335
|
-
prop.access);
|
|
336
|
-
pushToStates(statesDefs.colortemp_move, prop.access);
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
case 'color_xy': {
|
|
340
|
-
const stateNameC = expose.endpoint ? `color_${expose.endpoint}` : 'color';
|
|
341
|
-
pushToStates({
|
|
342
|
-
id: stateNameC,
|
|
343
|
-
prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
344
|
-
name: `Color ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
345
|
-
icon: undefined,
|
|
346
|
-
role: 'level.color.rgb',
|
|
347
|
-
write: true,
|
|
348
|
-
read: true,
|
|
349
|
-
type: 'string',
|
|
350
|
-
setter: value => {
|
|
351
|
-
// convert RGB to XY for set
|
|
352
|
-
/*
|
|
353
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(value);
|
|
354
|
-
let xy = [0, 0];
|
|
355
|
-
if (result) {
|
|
356
|
-
const r = parseInt(result[1], 16),
|
|
357
|
-
g = parseInt(result[2], 16),
|
|
358
|
-
b = parseInt(result[3], 16);
|
|
359
|
-
xy = rgb.rgb_to_cie(r, g, b);
|
|
360
|
-
}
|
|
361
|
-
return {
|
|
362
|
-
x: xy[0],
|
|
363
|
-
y: xy[1]
|
|
364
|
-
};
|
|
365
|
-
*/
|
|
366
|
-
let xy = [0, 0];
|
|
367
|
-
const rgbcolor = colors.ParseColor(value);
|
|
368
|
-
|
|
369
|
-
xy = rgb.rgb_to_cie(rgbcolor.r, rgbcolor.g, rgbcolor.b);
|
|
370
|
-
return {
|
|
371
|
-
x: xy[0],
|
|
372
|
-
y: xy[1],
|
|
373
|
-
};
|
|
374
|
-
},
|
|
375
|
-
setterOpt: (value, options) => {
|
|
376
|
-
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
377
|
-
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
378
|
-
return {...options, transition: transitionTime};
|
|
379
|
-
},
|
|
380
|
-
getter: payload => {
|
|
381
|
-
if (payload.color && payload.color.hasOwnProperty('x') && payload.color.hasOwnProperty('y')) {
|
|
382
|
-
const colorval = rgb.cie_to_rgb(payload.color.x, payload.color.y);
|
|
383
|
-
return `#${utils.decimalToHex(colorval[0])}${utils.decimalToHex(colorval[1])}${utils.decimalToHex(colorval[2])}`;
|
|
384
|
-
} else {
|
|
385
|
-
return undefined;
|
|
386
|
-
}
|
|
387
|
-
},
|
|
388
|
-
epname: expose.endpoint,
|
|
389
|
-
setattr: 'color',
|
|
390
|
-
}, prop.access);
|
|
391
|
-
break;
|
|
392
|
-
}
|
|
393
|
-
case 'color_hs': {
|
|
394
|
-
const stateNameH = expose.endpoint ? `color_${expose.endpoint}` : 'color';
|
|
395
|
-
pushToStates({
|
|
396
|
-
id: stateNameH,
|
|
397
|
-
prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
398
|
-
name: `Color ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
399
|
-
icon: undefined,
|
|
400
|
-
role: 'level.color.rgb',
|
|
401
|
-
write: true,
|
|
402
|
-
read: true,
|
|
403
|
-
type: 'string',
|
|
404
|
-
setter: value => {
|
|
405
|
-
const _rgb = colors.ParseColor(value);
|
|
406
|
-
const hsv = rgb.rgbToHSV(_rgb.r, _rgb.g, _rgb.b, true);
|
|
407
|
-
return {
|
|
408
|
-
hue: Math.min(Math.max(hsv.h, 1), 359),
|
|
409
|
-
saturation: hsv.s,
|
|
410
|
-
// brightness: Math.floor(hsv.v * 2.55),
|
|
411
|
-
};
|
|
412
|
-
},
|
|
413
|
-
setterOpt: (value, options) => {
|
|
414
|
-
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
415
|
-
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
416
|
-
return {...options, transition: transitionTime};
|
|
417
|
-
},
|
|
418
|
-
epname: expose.endpoint,
|
|
419
|
-
setattr: 'color',
|
|
420
|
-
}, prop.access);
|
|
421
|
-
pushToStates({
|
|
422
|
-
id: expose.endpoint ? `hue_${expose.endpoint}` : 'hue',
|
|
423
|
-
prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
424
|
-
name: `Hue ${expose.endpoint || ''}`.trim(),
|
|
425
|
-
icon: undefined,
|
|
426
|
-
role: 'level.color.hue',
|
|
427
|
-
write: true,
|
|
428
|
-
read: false,
|
|
429
|
-
type: 'number',
|
|
430
|
-
min: 0,
|
|
431
|
-
max: 360,
|
|
432
|
-
inOptions: true,
|
|
433
|
-
setter: (value, options) => {
|
|
434
|
-
return {
|
|
435
|
-
hue: value,
|
|
436
|
-
saturation: options.saturation,
|
|
437
|
-
};
|
|
438
|
-
},
|
|
439
|
-
setterOpt: (value, options) => {
|
|
440
|
-
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
441
|
-
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
442
|
-
const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
|
|
443
|
-
if (hasHueCalibrationTable)
|
|
444
|
-
try {
|
|
445
|
-
return {
|
|
446
|
-
...options,
|
|
447
|
-
transition: transitionTime,
|
|
448
|
-
hue_correction: JSON.parse(options.hue_calibration)
|
|
449
|
-
};
|
|
450
|
-
} catch {
|
|
451
|
-
const hue_correction_table = [];
|
|
452
|
-
options.hue_calibration.split(',').forEach(element => {
|
|
453
|
-
const match = /([0-9]+):([0-9]+)/.exec(element);
|
|
454
|
-
if (match && match.length === 3)
|
|
455
|
-
hue_correction_table.push({
|
|
456
|
-
in: Number(match[1]),
|
|
457
|
-
out: Number(match[2])
|
|
458
|
-
});
|
|
459
|
-
});
|
|
460
|
-
if (hue_correction_table.length > 0) {
|
|
461
|
-
return {
|
|
462
|
-
...options,
|
|
463
|
-
transition: transitionTime,
|
|
464
|
-
hue_correction: hue_correction_table
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return {...options, transition: transitionTime};
|
|
469
|
-
},
|
|
470
|
-
|
|
471
|
-
}, prop.access);
|
|
472
|
-
pushToStates({
|
|
473
|
-
id: expose.endpoint ? `saturation_${expose.endpoint}` : 'saturation',
|
|
474
|
-
prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
475
|
-
name: `Saturation ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
476
|
-
icon: undefined,
|
|
477
|
-
role: 'level.color.saturation',
|
|
478
|
-
write: true,
|
|
479
|
-
read: false,
|
|
480
|
-
type: 'number',
|
|
481
|
-
min: 0,
|
|
482
|
-
max: 100,
|
|
483
|
-
inOptions: true,
|
|
484
|
-
setter: (value, options) => ({
|
|
485
|
-
hue: options.hue,
|
|
486
|
-
saturation: value,
|
|
487
|
-
}),
|
|
488
|
-
setterOpt: (value, options) => {
|
|
489
|
-
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
490
|
-
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
491
|
-
const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
|
|
492
|
-
if (hasHueCalibrationTable)
|
|
493
|
-
try {
|
|
494
|
-
return {
|
|
495
|
-
...options,
|
|
496
|
-
transition: transitionTime,
|
|
497
|
-
hue_correction: JSON.parse(options.hue_calibration)
|
|
498
|
-
};
|
|
499
|
-
} catch {
|
|
500
|
-
const hue_correction_table = [];
|
|
501
|
-
options.hue_calibration.split(',').forEach(element => {
|
|
502
|
-
const match = /([0-9]+):([0-9]+)/.exec(element);
|
|
503
|
-
if (match && match.length === 3)
|
|
504
|
-
hue_correction_table.push({
|
|
505
|
-
in: Number(match[1]),
|
|
506
|
-
out: Number(match[2])
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
if (hue_correction_table.length > 0) {
|
|
510
|
-
return {
|
|
511
|
-
...options,
|
|
512
|
-
transition: transitionTime,
|
|
513
|
-
hue_correction: hue_correction_table
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
return {...options, transition: transitionTime};
|
|
518
|
-
},
|
|
519
|
-
|
|
520
|
-
}, prop.access);
|
|
521
|
-
pushToStates(statesDefs.hue_move, prop.access);
|
|
522
|
-
pushToStates(statesDefs.saturation_move, prop.access);
|
|
523
|
-
pushToStates({
|
|
524
|
-
id: 'hue_calibration',
|
|
525
|
-
prop: 'color',
|
|
526
|
-
name: 'Hue color calibration table',
|
|
527
|
-
icon: undefined,
|
|
528
|
-
role: 'table',
|
|
529
|
-
write: true,
|
|
530
|
-
read: false,
|
|
531
|
-
type: 'string',
|
|
532
|
-
inOptions: true,
|
|
533
|
-
setter: (value, options) => ({
|
|
534
|
-
hue: options.hue,
|
|
535
|
-
saturation: options.saturation,
|
|
536
|
-
}),
|
|
537
|
-
setterOpt: (value, options) => {
|
|
538
|
-
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
539
|
-
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
540
|
-
const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
|
|
541
|
-
if (hasHueCalibrationTable)
|
|
542
|
-
try {
|
|
543
|
-
return {
|
|
544
|
-
...options,
|
|
545
|
-
transition: transitionTime,
|
|
546
|
-
hue_correction: JSON.parse(options.hue_calibration)
|
|
547
|
-
};
|
|
548
|
-
} catch {
|
|
549
|
-
const hue_correction_table = [];
|
|
550
|
-
options.hue_calibration.split(',').forEach(element => {
|
|
551
|
-
const match = /([0-9]+):([0-9]+)/.exec(element);
|
|
552
|
-
if (match && match.length === 3) {
|
|
553
|
-
hue_correction_table.push({
|
|
554
|
-
in: Number(match[1]),
|
|
555
|
-
out: Number(match[2])
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
if (hue_correction_table.length > 0) {
|
|
560
|
-
return {
|
|
561
|
-
...options,
|
|
562
|
-
transition: transitionTime,
|
|
563
|
-
hue_correction: hue_correction_table
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return {...options, transition: transitionTime};
|
|
568
|
-
},
|
|
569
|
-
}, prop.access);
|
|
570
|
-
break;
|
|
571
|
-
}
|
|
572
|
-
default:
|
|
573
|
-
pushToStates(genState(prop), prop.access);
|
|
574
|
-
break;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
pushToStates(statesDefs.transition_time, ea.STATE_SET);
|
|
578
|
-
break;
|
|
579
|
-
|
|
580
|
-
case 'switch':
|
|
581
|
-
for (const prop of expose.features) {
|
|
582
|
-
switch (prop.name) {
|
|
583
|
-
case 'state':
|
|
584
|
-
pushToStates(genState(prop, 'switch'), prop.access);
|
|
585
|
-
break;
|
|
586
|
-
default:
|
|
587
|
-
pushToStates(genState(prop), prop.access);
|
|
588
|
-
break;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
break;
|
|
592
|
-
|
|
593
|
-
case 'numeric':
|
|
594
|
-
if (expose.endpoint) {
|
|
595
|
-
state = genState(expose);
|
|
596
|
-
} else {
|
|
597
|
-
switch (expose.name) {
|
|
598
|
-
case 'linkquality':
|
|
599
|
-
state = undefined;
|
|
600
|
-
break;
|
|
601
|
-
|
|
602
|
-
case 'battery':
|
|
603
|
-
state = statesDefs.battery;
|
|
604
|
-
break;
|
|
605
|
-
|
|
606
|
-
case 'voltage':
|
|
607
|
-
state = statesDefs.plug_voltage;
|
|
608
|
-
break;
|
|
609
|
-
|
|
610
|
-
case 'temperature':
|
|
611
|
-
state = statesDefs.temperature;
|
|
612
|
-
break;
|
|
613
|
-
|
|
614
|
-
case 'humidity':
|
|
615
|
-
state = statesDefs.humidity;
|
|
616
|
-
break;
|
|
617
|
-
|
|
618
|
-
case 'pressure':
|
|
619
|
-
state = statesDefs.pressure;
|
|
620
|
-
break;
|
|
621
|
-
|
|
622
|
-
case 'illuminance':
|
|
623
|
-
state = statesDefs.illuminance_raw;
|
|
624
|
-
break;
|
|
625
|
-
|
|
626
|
-
case 'illuminance_lux':
|
|
627
|
-
state = statesDefs.illuminance;
|
|
628
|
-
break;
|
|
629
|
-
|
|
630
|
-
case 'power':
|
|
631
|
-
state = statesDefs.load_power;
|
|
632
|
-
break;
|
|
633
|
-
|
|
634
|
-
default:
|
|
635
|
-
state = genState(expose);
|
|
636
|
-
break;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
if (state) {
|
|
640
|
-
pushToStates(state, expose.access);
|
|
641
|
-
}
|
|
642
|
-
break;
|
|
643
|
-
|
|
644
|
-
case 'enum':
|
|
645
|
-
switch (expose.name) {
|
|
646
|
-
case 'action': {
|
|
647
|
-
// Ansatz:
|
|
648
|
-
|
|
649
|
-
// Action aufspalten in 2 Blöcke:
|
|
650
|
-
// Action (bekommt text ausser hold und release, auto reset nach 250 ms)
|
|
651
|
-
// Hold: wird gesetzt bei hold, gelöscht bei passendem Release
|
|
652
|
-
|
|
653
|
-
if (!Array.isArray(expose.values)) break;
|
|
654
|
-
const hasHold = expose.values.find((actionName) => actionName.includes('hold'));
|
|
655
|
-
const hasRelease = expose.values.find((actionName) => actionName.includes('release'));
|
|
656
|
-
for (const actionName of expose.values) {
|
|
657
|
-
// is release state ? - skip
|
|
658
|
-
if (hasHold && hasRelease && actionName.includes('release')) continue;
|
|
659
|
-
// is hold state ?
|
|
660
|
-
if (hasHold && hasRelease && actionName.includes('hold')) {
|
|
661
|
-
const releaseActionName = actionName.replace('hold', 'release');
|
|
662
|
-
state = {
|
|
663
|
-
id: actionName.replace(/\*/g, ''),
|
|
664
|
-
prop: 'action',
|
|
665
|
-
name: actionName,
|
|
666
|
-
icon: undefined,
|
|
667
|
-
role: 'button',
|
|
668
|
-
write: false,
|
|
669
|
-
read: true,
|
|
670
|
-
type: 'boolean',
|
|
671
|
-
getter: payload => payload.action === actionName ? true : (payload.action === releaseActionName ? false : undefined),
|
|
672
|
-
};
|
|
673
|
-
} else {
|
|
674
|
-
state = {
|
|
675
|
-
id: actionName.replace(/\*/g, ''),
|
|
676
|
-
prop: 'action',
|
|
677
|
-
name: actionName,
|
|
678
|
-
icon: undefined,
|
|
679
|
-
role: 'button',
|
|
680
|
-
write: false,
|
|
681
|
-
read: true,
|
|
682
|
-
type: 'boolean',
|
|
683
|
-
getter: payload => payload.action === actionName ? true : undefined,
|
|
684
|
-
isEvent: true,
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
pushToStates(state, expose.access);
|
|
688
|
-
}
|
|
689
|
-
state = null;
|
|
690
|
-
break;
|
|
691
|
-
}
|
|
692
|
-
default:
|
|
693
|
-
state = genState(expose);
|
|
694
|
-
break;
|
|
695
|
-
}
|
|
696
|
-
if (state) pushToStates(state, expose.access);
|
|
697
|
-
break;
|
|
698
|
-
|
|
699
|
-
case 'binary':
|
|
700
|
-
if (expose.endpoint) {
|
|
701
|
-
state = genState(expose);
|
|
702
|
-
} else {
|
|
703
|
-
switch (expose.name) {
|
|
704
|
-
case 'contact':
|
|
705
|
-
state = statesDefs.contact;
|
|
706
|
-
pushToStates(statesDefs.opened, ea.STATE);
|
|
707
|
-
break;
|
|
708
|
-
|
|
709
|
-
case 'battery_low':
|
|
710
|
-
state = statesDefs.heiman_batt_low;
|
|
711
|
-
break;
|
|
712
|
-
|
|
713
|
-
case 'tamper':
|
|
714
|
-
state = statesDefs.tamper;
|
|
715
|
-
break;
|
|
716
|
-
|
|
717
|
-
case 'water_leak':
|
|
718
|
-
state = statesDefs.water_detected;
|
|
719
|
-
break;
|
|
720
|
-
|
|
721
|
-
case 'lock':
|
|
722
|
-
state = statesDefs.child_lock;
|
|
723
|
-
break;
|
|
724
|
-
|
|
725
|
-
case 'occupancy':
|
|
726
|
-
state = statesDefs.occupancy;
|
|
727
|
-
break;
|
|
728
|
-
|
|
729
|
-
default:
|
|
730
|
-
state = genState(expose);
|
|
731
|
-
break;
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
if (state) {
|
|
735
|
-
pushToStates(state, expose.access);
|
|
736
|
-
}
|
|
737
|
-
break;
|
|
738
|
-
|
|
739
|
-
case 'text':
|
|
740
|
-
state = genState(expose);
|
|
741
|
-
pushToStates(state, expose.access);
|
|
742
|
-
break;
|
|
743
|
-
|
|
744
|
-
case 'lock':
|
|
745
|
-
case 'fan':
|
|
746
|
-
case 'cover':
|
|
747
|
-
for (const prop of expose.features) {
|
|
748
|
-
switch (prop.name) {
|
|
749
|
-
case 'state':
|
|
750
|
-
pushToStates(genState(prop, 'switch'), prop.access);
|
|
751
|
-
break;
|
|
752
|
-
default:
|
|
753
|
-
pushToStates(genState(prop), prop.access);
|
|
754
|
-
break;
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
break;
|
|
758
|
-
|
|
759
|
-
case 'climate':
|
|
760
|
-
for (const prop of expose.features) {
|
|
761
|
-
switch (prop.name) {
|
|
762
|
-
case 'away_mode':
|
|
763
|
-
pushToStates(statesDefs.climate_away_mode, prop.access);
|
|
764
|
-
break;
|
|
765
|
-
case 'system_mode':
|
|
766
|
-
pushToStates(statesDefs.climate_system_mode, prop.access);
|
|
767
|
-
break;
|
|
768
|
-
case 'running_mode':
|
|
769
|
-
pushToStates(statesDefs.climate_running_mode, prop.access);
|
|
770
|
-
break;
|
|
771
|
-
default:
|
|
772
|
-
pushToStates(genState(prop), prop.access);
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
break;
|
|
777
|
-
|
|
778
|
-
case 'composite':
|
|
779
|
-
for (const prop of expose.features) {
|
|
780
|
-
if (prop.type == 'numeric') {
|
|
781
|
-
const st = genState(prop);
|
|
782
|
-
st.prop = expose.property;
|
|
783
|
-
st.inOptions = true;
|
|
784
|
-
// I'm not fully sure, as it really needed, but
|
|
785
|
-
st.setterOpt = (value, options) => {
|
|
786
|
-
const result = {};
|
|
787
|
-
options[prop.property] = value;
|
|
788
|
-
result[expose.property] = options;
|
|
789
|
-
return result;
|
|
790
|
-
};
|
|
791
|
-
// if we have a composite expose, the value have to be an object {expose.property : {prop.property: value}}
|
|
792
|
-
if (prop.access & ea.SET) {
|
|
793
|
-
st.setter = (value, options) => {
|
|
794
|
-
const result = {};
|
|
795
|
-
options[prop.property] = value;
|
|
796
|
-
result[expose.property] = options;
|
|
797
|
-
return result;
|
|
798
|
-
};
|
|
799
|
-
st.setattr = expose.property;
|
|
800
|
-
}
|
|
801
|
-
// if we have a composite expose, the payload will be an object {expose.property : {prop.property: value}}
|
|
802
|
-
if (prop.access & ea.STATE) {
|
|
803
|
-
st.getter = payload => {
|
|
804
|
-
if ((payload.hasOwnProperty(expose.property)) && (payload[expose.property] !== null) && payload[expose.property].hasOwnProperty(prop.property)) {
|
|
805
|
-
return !isNaN(payload[expose.property][prop.property]) ? payload[expose.property][prop.property] : undefined;
|
|
806
|
-
} else {
|
|
807
|
-
return undefined;
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
} else {
|
|
811
|
-
st.getter = payload => undefined;
|
|
812
|
-
}
|
|
813
|
-
pushToStates(st, prop.access);
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
if (prop.type == 'list') {
|
|
817
|
-
for (const propList of prop.item_type.features) {
|
|
818
|
-
const st = genState(propList);
|
|
819
|
-
st.prop = expose.property;
|
|
820
|
-
st.inOptions = true;
|
|
821
|
-
st.setterOpt = (value, options) => {
|
|
822
|
-
const result = {};
|
|
823
|
-
options[propList.property] = value;
|
|
824
|
-
result[expose.property] = options;
|
|
825
|
-
return result;
|
|
826
|
-
};
|
|
827
|
-
if (propList.access & ea.SET) {
|
|
828
|
-
st.setter = (value, options) => {
|
|
829
|
-
const result = {};
|
|
830
|
-
options[propList.property] = value;
|
|
831
|
-
result[expose.property] = options;
|
|
832
|
-
return result;
|
|
833
|
-
};
|
|
834
|
-
st.setattr = expose.property;
|
|
835
|
-
}
|
|
836
|
-
if (propList.access & ea.STATE) {
|
|
837
|
-
st.getter = payload => {
|
|
838
|
-
if ((payload.hasOwnProperty(expose.property)) && (payload[expose.property] !== null) && payload[expose.property].hasOwnProperty(propList.property)) {
|
|
839
|
-
return !isNaN(payload[expose.property][propList.property]) ? payload[expose.property][propList.property] : undefined;
|
|
840
|
-
} else {
|
|
841
|
-
return undefined;
|
|
842
|
-
}
|
|
843
|
-
};
|
|
844
|
-
} else {
|
|
845
|
-
st.getter = payload => undefined;
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
st.id = st.prop + '_' + st.id;
|
|
849
|
-
pushToStates(st, propList.access);
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
break;
|
|
854
|
-
default:
|
|
855
|
-
console.log(`Unhandled expose type ${expose.type} for device ${model}`);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
const newDev = {
|
|
859
|
-
models: [model],
|
|
860
|
-
icon,
|
|
861
|
-
states,
|
|
862
|
-
exposed: true,
|
|
863
|
-
};
|
|
864
|
-
// make the function code printable in log
|
|
865
|
-
//console.log(`Created mapping for device ${model}: ${JSON.stringify(newDev, function(key, value) {
|
|
866
|
-
// if (typeof value === 'function') {return value.toString() } else { return value } }, ' ')}`);
|
|
867
|
-
return newDev;
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
function applyExposes(mappedDevices, byModel, allExcludesObj) {
|
|
871
|
-
// for exclude search
|
|
872
|
-
const allExcludesStr = JSON.stringify(allExcludesObj);
|
|
873
|
-
// create or update device from exposes
|
|
874
|
-
for (const deviceDef of zigbeeHerdsmanConverters.definitions) {
|
|
875
|
-
applyDeviceDef(mappedDevices, byModel, allExcludesStr, deviceDef);
|
|
876
|
-
|
|
877
|
-
if (deviceDef.hasOwnProperty('whiteLabel')) {
|
|
878
|
-
for (const deviceWhiteLabel of deviceDef.whiteLabel) {
|
|
879
|
-
applyDeviceDef(mappedDevices, byModel, allExcludesStr, {
|
|
880
|
-
...deviceDef,
|
|
881
|
-
model: deviceWhiteLabel.model,
|
|
882
|
-
vendor: deviceWhiteLabel.vendor,
|
|
883
|
-
description: deviceWhiteLabel.description || deviceDef.description,
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
function applyDeviceDef(mappedDevices, byModel, allExcludesStr, deviceDef) {
|
|
891
|
-
const stripModel = utils.getModelRegEx(deviceDef.model);
|
|
892
|
-
// check if device is mapped
|
|
893
|
-
const existsMap = byModel.get(stripModel);
|
|
894
|
-
|
|
895
|
-
if ((deviceDef.hasOwnProperty('exposes') && (!existsMap || !existsMap.hasOwnProperty('states'))) || allExcludesStr.indexOf(stripModel) > 0) {
|
|
896
|
-
try {
|
|
897
|
-
const newDevice = createFromExposes(stripModel, deviceDef);
|
|
898
|
-
if (!existsMap) {
|
|
899
|
-
mappedDevices.push(newDevice);
|
|
900
|
-
byModel.set(stripModel, newDevice);
|
|
901
|
-
} else {
|
|
902
|
-
existsMap.states = newDevice.states;
|
|
903
|
-
existsMap.exposed = true;
|
|
904
|
-
}
|
|
905
|
-
} catch (e) {
|
|
906
|
-
console.log(`Wrong expose devicedefinition ${deviceDef.vendor} ${stripModel}`);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
module.exports = {
|
|
912
|
-
applyExposes: applyExposes,
|
|
913
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
|
|
4
|
+
const statesDefs = require('./states.js').states;
|
|
5
|
+
const rgb = require('./rgb.js');
|
|
6
|
+
const utils = require('./utils.js');
|
|
7
|
+
const colors = require('./colors.js');
|
|
8
|
+
const ea = require('zigbee-herdsman-converters/lib/exposes.js').access;
|
|
9
|
+
|
|
10
|
+
function genState(expose, role, name, desc) {
|
|
11
|
+
let state;
|
|
12
|
+
const readable = (expose.access & ea.STATE) > 0;
|
|
13
|
+
const writable = (expose.access & ea.SET) > 0;
|
|
14
|
+
const stname = (name || expose.property);
|
|
15
|
+
if (typeof stname !== 'string') return;
|
|
16
|
+
const stateId = stname.replace(/\*/g, '');
|
|
17
|
+
const stateName = (desc || expose.description || expose.name);
|
|
18
|
+
const propName = expose.property;
|
|
19
|
+
switch (expose.type) {
|
|
20
|
+
case 'binary':
|
|
21
|
+
state = {
|
|
22
|
+
id: stateId,
|
|
23
|
+
prop: propName,
|
|
24
|
+
name: stateName,
|
|
25
|
+
icon: undefined,
|
|
26
|
+
role: role || 'state',
|
|
27
|
+
write: writable,
|
|
28
|
+
read: true,
|
|
29
|
+
type: 'boolean',
|
|
30
|
+
};
|
|
31
|
+
if (readable) {
|
|
32
|
+
state.getter = payload => payload[propName] === (expose.value_on || 'ON');
|
|
33
|
+
} else {
|
|
34
|
+
state.getter = payload => undefined;
|
|
35
|
+
}
|
|
36
|
+
if (writable) {
|
|
37
|
+
state.setter = (value) => (value) ? (expose.value_on || 'ON') : ((expose.value_off != undefined) ? expose.value_off : 'OFF');
|
|
38
|
+
state.setattr = expose.name;
|
|
39
|
+
}
|
|
40
|
+
if (expose.endpoint) {
|
|
41
|
+
state.epname = expose.endpoint;
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
|
|
45
|
+
case 'numeric':
|
|
46
|
+
state = {
|
|
47
|
+
id: stateId,
|
|
48
|
+
prop: propName,
|
|
49
|
+
name: stateName,
|
|
50
|
+
icon: undefined,
|
|
51
|
+
role: role || 'state',
|
|
52
|
+
write: writable,
|
|
53
|
+
read: true,
|
|
54
|
+
type: 'number',
|
|
55
|
+
min: expose.value_min || 0,
|
|
56
|
+
max: expose.value_max,
|
|
57
|
+
unit: expose.unit,
|
|
58
|
+
};
|
|
59
|
+
if (expose.endpoint) {
|
|
60
|
+
state.epname = expose.endpoint;
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case 'enum':
|
|
65
|
+
state = {
|
|
66
|
+
id: stateId,
|
|
67
|
+
prop: propName,
|
|
68
|
+
name: stateName,
|
|
69
|
+
icon: undefined,
|
|
70
|
+
role: role || 'state',
|
|
71
|
+
write: writable,
|
|
72
|
+
read: true,
|
|
73
|
+
type: 'string',
|
|
74
|
+
states: {},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
for (const val of expose.values) {
|
|
78
|
+
// if a definition of a enum states
|
|
79
|
+
if (val == '') {
|
|
80
|
+
state.states[propName] = propName;
|
|
81
|
+
} else {
|
|
82
|
+
state.states[val] = val;
|
|
83
|
+
}
|
|
84
|
+
state.type = typeof (val);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
switch (state.type) {
|
|
88
|
+
case 'boolean':
|
|
89
|
+
state.def = false;
|
|
90
|
+
break;
|
|
91
|
+
case 'number':
|
|
92
|
+
state.def = 0;
|
|
93
|
+
break;
|
|
94
|
+
case 'object':
|
|
95
|
+
state.def = {};
|
|
96
|
+
break;
|
|
97
|
+
case 'string':
|
|
98
|
+
state.def = '';
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// if a definition of a special button
|
|
103
|
+
if (state.states == ':') {
|
|
104
|
+
state.states = propName + ':' + propName;
|
|
105
|
+
state.type = 'object';
|
|
106
|
+
}
|
|
107
|
+
if (expose.endpoint) {
|
|
108
|
+
state.epname = expose.endpoint;
|
|
109
|
+
state.setattr = expose.name;
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
|
|
113
|
+
case 'text':
|
|
114
|
+
state = {
|
|
115
|
+
id: stateId,
|
|
116
|
+
prop: propName,
|
|
117
|
+
name: stateName,
|
|
118
|
+
icon: undefined,
|
|
119
|
+
role: role || 'state',
|
|
120
|
+
write: writable,
|
|
121
|
+
read: true,
|
|
122
|
+
type: 'string',
|
|
123
|
+
};
|
|
124
|
+
if (expose.endpoint) {
|
|
125
|
+
state.epname = expose.endpoint;
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
|
|
129
|
+
default:
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return state;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function createFromExposes(model, def) {
|
|
137
|
+
const states = [];
|
|
138
|
+
// make the different (set and get) part of state is updatable if different exposes is used for get and set
|
|
139
|
+
// as example:
|
|
140
|
+
// ...
|
|
141
|
+
// exposes.binary('some_option', ea.STATE, true, false).withDescription('Some Option'),
|
|
142
|
+
// exposes.composite('options', 'options')
|
|
143
|
+
// .withDescription('Some composite Options')
|
|
144
|
+
// .withFeature(exposes.binary('some_option', ea.SET, true, false).withDescription('Some Option'))
|
|
145
|
+
//in this case one state - `some_option` has two different exposes for set an get, we have to combine it ...
|
|
146
|
+
//
|
|
147
|
+
|
|
148
|
+
function pushToStates(state, access) {
|
|
149
|
+
if (state === undefined) {
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
if (access === undefined) {
|
|
153
|
+
access = ea.ALL;
|
|
154
|
+
}
|
|
155
|
+
state.readable = (access & ea.STATE) > 0;
|
|
156
|
+
state.writable = (access & ea.SET) > 0;
|
|
157
|
+
const stateExists = states.findIndex((element, index, array) => element.id === state.id);
|
|
158
|
+
if (stateExists < 0) {
|
|
159
|
+
state.write = state.writable;
|
|
160
|
+
if (!state.writable) {
|
|
161
|
+
if (state.hasOwnProperty('setter')) {
|
|
162
|
+
delete state.setter;
|
|
163
|
+
}
|
|
164
|
+
if (state.hasOwnProperty('setattr')) {
|
|
165
|
+
delete state.setattr;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!state.readable) {
|
|
169
|
+
if (state.hasOwnProperty('getter')) {
|
|
170
|
+
// to awoid some warnings on unprocessed data
|
|
171
|
+
state.getter = payload => undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return states.push(state);
|
|
175
|
+
} else {
|
|
176
|
+
if ((state.readable) && (!states[stateExists].readable)) {
|
|
177
|
+
states[stateExists].read = state.read;
|
|
178
|
+
// as state is readable, it can't be button or event
|
|
179
|
+
if (states[stateExists].role === 'button') {
|
|
180
|
+
states[stateExists].role = state.role;
|
|
181
|
+
}
|
|
182
|
+
if (states[stateExists].hasOwnProperty('isEvent')) {
|
|
183
|
+
delete states[stateExists].isEvent;
|
|
184
|
+
}
|
|
185
|
+
// we have to use the getter from "new" state
|
|
186
|
+
if (state.hasOwnProperty('getter')) {
|
|
187
|
+
states[stateExists].getter = state.getter;
|
|
188
|
+
}
|
|
189
|
+
// trying to remove the `prop` property, as main key for get and set,
|
|
190
|
+
// as it can be different in new and old states, and leave only:
|
|
191
|
+
// setattr for old and id for new
|
|
192
|
+
if ((state.hasOwnProperty('prop')) && (state.prop === state.id)) {
|
|
193
|
+
if (states[stateExists].hasOwnProperty('prop')) {
|
|
194
|
+
if (states[stateExists].prop !== states[stateExists].id) {
|
|
195
|
+
if (!states[stateExists].hasOwnProperty('setattr')) {
|
|
196
|
+
states[stateExists].setattr = states[stateExists].prop;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
delete states[stateExists].prop;
|
|
200
|
+
}
|
|
201
|
+
} else if (state.hasOwnProperty('prop')) {
|
|
202
|
+
states[stateExists].prop = state.prop;
|
|
203
|
+
}
|
|
204
|
+
states[stateExists].readable = true;
|
|
205
|
+
}
|
|
206
|
+
if ((state.writable) && (!states[stateExists].writable)) {
|
|
207
|
+
states[stateExists].write = state.writable;
|
|
208
|
+
// use new state `setter`
|
|
209
|
+
if (state.hasOwnProperty('setter')) {
|
|
210
|
+
states[stateExists].setter = state.setter;
|
|
211
|
+
}
|
|
212
|
+
// use new state `setterOpt`
|
|
213
|
+
if (state.hasOwnProperty('setterOpt')) {
|
|
214
|
+
states[stateExists].setterOpt = state.setterOpt;
|
|
215
|
+
}
|
|
216
|
+
// use new state `inOptions`
|
|
217
|
+
if (state.hasOwnProperty('inOptions')) {
|
|
218
|
+
states[stateExists].inOptions = state.inOptions;
|
|
219
|
+
}
|
|
220
|
+
// as we have new state, responsible for set, we have to use new `isOption`
|
|
221
|
+
// or remove it
|
|
222
|
+
if (((!state.hasOwnProperty('isOption')) || (state.isOptions === false))
|
|
223
|
+
&& (states[stateExists].hasOwnProperty('isOption'))) {
|
|
224
|
+
delete states[stateExists].isOption;
|
|
225
|
+
} else {
|
|
226
|
+
states[stateExists].isOption = state.isOption;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// use new `setattr` or `prop` as `setattr`
|
|
230
|
+
if (state.hasOwnProperty('setattr')) {
|
|
231
|
+
states[stateExists].setattr = state.setattr;
|
|
232
|
+
} else if (state.hasOwnProperty('prop')) {
|
|
233
|
+
states[stateExists].setattr = state.prop;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// remove `prop` equal to if, due to prop is uses as key in set and get
|
|
237
|
+
if (states[stateExists].prop === states[stateExists].id) {
|
|
238
|
+
delete states[stateExists].prop;
|
|
239
|
+
}
|
|
240
|
+
if (state.hasOwnProperty('epname')) {
|
|
241
|
+
states[stateExists].epname = state.epname;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
states[stateExists].writable = true;
|
|
245
|
+
}
|
|
246
|
+
return states.length;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const icon = utils.getDeviceIcon(def);
|
|
251
|
+
for (const expose of def.exposes) {
|
|
252
|
+
let state;
|
|
253
|
+
|
|
254
|
+
switch (expose.type) {
|
|
255
|
+
case 'light':
|
|
256
|
+
for (const prop of expose.features) {
|
|
257
|
+
switch (prop.name) {
|
|
258
|
+
case 'state': {
|
|
259
|
+
const stateNameS = expose.endpoint ? `state_${expose.endpoint}` : 'state';
|
|
260
|
+
pushToStates({
|
|
261
|
+
id: stateNameS,
|
|
262
|
+
name: `Switch state ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
263
|
+
icon: undefined,
|
|
264
|
+
role: 'switch',
|
|
265
|
+
write: true,
|
|
266
|
+
read: true,
|
|
267
|
+
type: 'boolean',
|
|
268
|
+
getter: (payload) => (payload[stateNameS] === (prop.value_on || 'ON')),
|
|
269
|
+
setter: (value) => (value) ? prop.value_on || 'ON' : ((prop.value_off != undefined) ? prop.value_off : 'OFF'),
|
|
270
|
+
epname: expose.endpoint,
|
|
271
|
+
setattr: 'state',
|
|
272
|
+
}, prop.access);
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
case 'brightness': {
|
|
277
|
+
const stateNameB = expose.endpoint ? `brightness_${expose.endpoint}` : 'brightness';
|
|
278
|
+
pushToStates({
|
|
279
|
+
id: stateNameB,
|
|
280
|
+
name: `Brightness ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
281
|
+
icon: undefined,
|
|
282
|
+
role: 'level.dimmer',
|
|
283
|
+
write: true,
|
|
284
|
+
read: true,
|
|
285
|
+
type: 'number',
|
|
286
|
+
min: 0, // ignore expose.value_min
|
|
287
|
+
max: 100, // ignore expose.value_max
|
|
288
|
+
inOptions: true,
|
|
289
|
+
getter: payload => utils.bulbLevelToAdapterLevel(payload[stateNameB]),
|
|
290
|
+
setter: value => utils.adapterLevelToBulbLevel(value),
|
|
291
|
+
setterOpt: (value, options) => {
|
|
292
|
+
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
293
|
+
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
294
|
+
const preparedOptions = {...options, transition: transitionTime};
|
|
295
|
+
preparedOptions.brightness = utils.adapterLevelToBulbLevel(value);
|
|
296
|
+
return preparedOptions;
|
|
297
|
+
},
|
|
298
|
+
readResponse: resp => {
|
|
299
|
+
const respObj = resp[0];
|
|
300
|
+
if (respObj.status === 0 && respObj.attrData != undefined) {
|
|
301
|
+
return utils.bulbLevelToAdapterLevel(respObj.attrData);
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
epname: expose.endpoint,
|
|
305
|
+
setattr: 'brightness',
|
|
306
|
+
}, prop.access);
|
|
307
|
+
pushToStates(statesDefs.brightness_move, prop.access);
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
case 'color_temp': {
|
|
311
|
+
const stateNameT = expose.endpoint ? `colortemp_${expose.endpoint}` : 'colortemp';
|
|
312
|
+
pushToStates(
|
|
313
|
+
{
|
|
314
|
+
id: stateNameT,
|
|
315
|
+
prop: expose.endpoint ? `color_temp_${expose.endpoint}` : 'color_temp',
|
|
316
|
+
name: `Color temperature ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
317
|
+
icon: undefined,
|
|
318
|
+
role: 'level.color.temperature',
|
|
319
|
+
write: true,
|
|
320
|
+
read: true,
|
|
321
|
+
type: 'number',
|
|
322
|
+
// Ignore min and max value, so setting mireds and Kelvin with conversion to mireds works.
|
|
323
|
+
// https://github.com/ioBroker/ioBroker.zigbee/pull/1433#issuecomment-1113837035
|
|
324
|
+
min: undefined,
|
|
325
|
+
max: undefined,
|
|
326
|
+
setter: value => utils.toMired(value),
|
|
327
|
+
setterOpt: (value, options) => {
|
|
328
|
+
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
329
|
+
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
330
|
+
return {...options, transition: transitionTime};
|
|
331
|
+
},
|
|
332
|
+
epname: expose.endpoint,
|
|
333
|
+
setattr: 'color_temp',
|
|
334
|
+
},
|
|
335
|
+
prop.access);
|
|
336
|
+
pushToStates(statesDefs.colortemp_move, prop.access);
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
case 'color_xy': {
|
|
340
|
+
const stateNameC = expose.endpoint ? `color_${expose.endpoint}` : 'color';
|
|
341
|
+
pushToStates({
|
|
342
|
+
id: stateNameC,
|
|
343
|
+
prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
344
|
+
name: `Color ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
345
|
+
icon: undefined,
|
|
346
|
+
role: 'level.color.rgb',
|
|
347
|
+
write: true,
|
|
348
|
+
read: true,
|
|
349
|
+
type: 'string',
|
|
350
|
+
setter: value => {
|
|
351
|
+
// convert RGB to XY for set
|
|
352
|
+
/*
|
|
353
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(value);
|
|
354
|
+
let xy = [0, 0];
|
|
355
|
+
if (result) {
|
|
356
|
+
const r = parseInt(result[1], 16),
|
|
357
|
+
g = parseInt(result[2], 16),
|
|
358
|
+
b = parseInt(result[3], 16);
|
|
359
|
+
xy = rgb.rgb_to_cie(r, g, b);
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
x: xy[0],
|
|
363
|
+
y: xy[1]
|
|
364
|
+
};
|
|
365
|
+
*/
|
|
366
|
+
let xy = [0, 0];
|
|
367
|
+
const rgbcolor = colors.ParseColor(value);
|
|
368
|
+
|
|
369
|
+
xy = rgb.rgb_to_cie(rgbcolor.r, rgbcolor.g, rgbcolor.b);
|
|
370
|
+
return {
|
|
371
|
+
x: xy[0],
|
|
372
|
+
y: xy[1],
|
|
373
|
+
};
|
|
374
|
+
},
|
|
375
|
+
setterOpt: (value, options) => {
|
|
376
|
+
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
377
|
+
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
378
|
+
return {...options, transition: transitionTime};
|
|
379
|
+
},
|
|
380
|
+
getter: payload => {
|
|
381
|
+
if (payload.color && payload.color.hasOwnProperty('x') && payload.color.hasOwnProperty('y')) {
|
|
382
|
+
const colorval = rgb.cie_to_rgb(payload.color.x, payload.color.y);
|
|
383
|
+
return `#${utils.decimalToHex(colorval[0])}${utils.decimalToHex(colorval[1])}${utils.decimalToHex(colorval[2])}`;
|
|
384
|
+
} else {
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
epname: expose.endpoint,
|
|
389
|
+
setattr: 'color',
|
|
390
|
+
}, prop.access);
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
case 'color_hs': {
|
|
394
|
+
const stateNameH = expose.endpoint ? `color_${expose.endpoint}` : 'color';
|
|
395
|
+
pushToStates({
|
|
396
|
+
id: stateNameH,
|
|
397
|
+
prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
398
|
+
name: `Color ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
399
|
+
icon: undefined,
|
|
400
|
+
role: 'level.color.rgb',
|
|
401
|
+
write: true,
|
|
402
|
+
read: true,
|
|
403
|
+
type: 'string',
|
|
404
|
+
setter: value => {
|
|
405
|
+
const _rgb = colors.ParseColor(value);
|
|
406
|
+
const hsv = rgb.rgbToHSV(_rgb.r, _rgb.g, _rgb.b, true);
|
|
407
|
+
return {
|
|
408
|
+
hue: Math.min(Math.max(hsv.h, 1), 359),
|
|
409
|
+
saturation: hsv.s,
|
|
410
|
+
// brightness: Math.floor(hsv.v * 2.55),
|
|
411
|
+
};
|
|
412
|
+
},
|
|
413
|
+
setterOpt: (value, options) => {
|
|
414
|
+
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
415
|
+
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
416
|
+
return {...options, transition: transitionTime};
|
|
417
|
+
},
|
|
418
|
+
epname: expose.endpoint,
|
|
419
|
+
setattr: 'color',
|
|
420
|
+
}, prop.access);
|
|
421
|
+
pushToStates({
|
|
422
|
+
id: expose.endpoint ? `hue_${expose.endpoint}` : 'hue',
|
|
423
|
+
prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
424
|
+
name: `Hue ${expose.endpoint || ''}`.trim(),
|
|
425
|
+
icon: undefined,
|
|
426
|
+
role: 'level.color.hue',
|
|
427
|
+
write: true,
|
|
428
|
+
read: false,
|
|
429
|
+
type: 'number',
|
|
430
|
+
min: 0,
|
|
431
|
+
max: 360,
|
|
432
|
+
inOptions: true,
|
|
433
|
+
setter: (value, options) => {
|
|
434
|
+
return {
|
|
435
|
+
hue: value,
|
|
436
|
+
saturation: options.saturation,
|
|
437
|
+
};
|
|
438
|
+
},
|
|
439
|
+
setterOpt: (value, options) => {
|
|
440
|
+
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
441
|
+
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
442
|
+
const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
|
|
443
|
+
if (hasHueCalibrationTable)
|
|
444
|
+
try {
|
|
445
|
+
return {
|
|
446
|
+
...options,
|
|
447
|
+
transition: transitionTime,
|
|
448
|
+
hue_correction: JSON.parse(options.hue_calibration)
|
|
449
|
+
};
|
|
450
|
+
} catch {
|
|
451
|
+
const hue_correction_table = [];
|
|
452
|
+
options.hue_calibration.split(',').forEach(element => {
|
|
453
|
+
const match = /([0-9]+):([0-9]+)/.exec(element);
|
|
454
|
+
if (match && match.length === 3)
|
|
455
|
+
hue_correction_table.push({
|
|
456
|
+
in: Number(match[1]),
|
|
457
|
+
out: Number(match[2])
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
if (hue_correction_table.length > 0) {
|
|
461
|
+
return {
|
|
462
|
+
...options,
|
|
463
|
+
transition: transitionTime,
|
|
464
|
+
hue_correction: hue_correction_table
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return {...options, transition: transitionTime};
|
|
469
|
+
},
|
|
470
|
+
|
|
471
|
+
}, prop.access);
|
|
472
|
+
pushToStates({
|
|
473
|
+
id: expose.endpoint ? `saturation_${expose.endpoint}` : 'saturation',
|
|
474
|
+
prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
475
|
+
name: `Saturation ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
476
|
+
icon: undefined,
|
|
477
|
+
role: 'level.color.saturation',
|
|
478
|
+
write: true,
|
|
479
|
+
read: false,
|
|
480
|
+
type: 'number',
|
|
481
|
+
min: 0,
|
|
482
|
+
max: 100,
|
|
483
|
+
inOptions: true,
|
|
484
|
+
setter: (value, options) => ({
|
|
485
|
+
hue: options.hue,
|
|
486
|
+
saturation: value,
|
|
487
|
+
}),
|
|
488
|
+
setterOpt: (value, options) => {
|
|
489
|
+
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
490
|
+
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
491
|
+
const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
|
|
492
|
+
if (hasHueCalibrationTable)
|
|
493
|
+
try {
|
|
494
|
+
return {
|
|
495
|
+
...options,
|
|
496
|
+
transition: transitionTime,
|
|
497
|
+
hue_correction: JSON.parse(options.hue_calibration)
|
|
498
|
+
};
|
|
499
|
+
} catch {
|
|
500
|
+
const hue_correction_table = [];
|
|
501
|
+
options.hue_calibration.split(',').forEach(element => {
|
|
502
|
+
const match = /([0-9]+):([0-9]+)/.exec(element);
|
|
503
|
+
if (match && match.length === 3)
|
|
504
|
+
hue_correction_table.push({
|
|
505
|
+
in: Number(match[1]),
|
|
506
|
+
out: Number(match[2])
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
if (hue_correction_table.length > 0) {
|
|
510
|
+
return {
|
|
511
|
+
...options,
|
|
512
|
+
transition: transitionTime,
|
|
513
|
+
hue_correction: hue_correction_table
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return {...options, transition: transitionTime};
|
|
518
|
+
},
|
|
519
|
+
|
|
520
|
+
}, prop.access);
|
|
521
|
+
pushToStates(statesDefs.hue_move, prop.access);
|
|
522
|
+
pushToStates(statesDefs.saturation_move, prop.access);
|
|
523
|
+
pushToStates({
|
|
524
|
+
id: 'hue_calibration',
|
|
525
|
+
prop: 'color',
|
|
526
|
+
name: 'Hue color calibration table',
|
|
527
|
+
icon: undefined,
|
|
528
|
+
role: 'table',
|
|
529
|
+
write: true,
|
|
530
|
+
read: false,
|
|
531
|
+
type: 'string',
|
|
532
|
+
inOptions: true,
|
|
533
|
+
setter: (value, options) => ({
|
|
534
|
+
hue: options.hue,
|
|
535
|
+
saturation: options.saturation,
|
|
536
|
+
}),
|
|
537
|
+
setterOpt: (value, options) => {
|
|
538
|
+
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
539
|
+
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
540
|
+
const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
|
|
541
|
+
if (hasHueCalibrationTable)
|
|
542
|
+
try {
|
|
543
|
+
return {
|
|
544
|
+
...options,
|
|
545
|
+
transition: transitionTime,
|
|
546
|
+
hue_correction: JSON.parse(options.hue_calibration)
|
|
547
|
+
};
|
|
548
|
+
} catch {
|
|
549
|
+
const hue_correction_table = [];
|
|
550
|
+
options.hue_calibration.split(',').forEach(element => {
|
|
551
|
+
const match = /([0-9]+):([0-9]+)/.exec(element);
|
|
552
|
+
if (match && match.length === 3) {
|
|
553
|
+
hue_correction_table.push({
|
|
554
|
+
in: Number(match[1]),
|
|
555
|
+
out: Number(match[2])
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
if (hue_correction_table.length > 0) {
|
|
560
|
+
return {
|
|
561
|
+
...options,
|
|
562
|
+
transition: transitionTime,
|
|
563
|
+
hue_correction: hue_correction_table
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return {...options, transition: transitionTime};
|
|
568
|
+
},
|
|
569
|
+
}, prop.access);
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
default:
|
|
573
|
+
pushToStates(genState(prop), prop.access);
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
pushToStates(statesDefs.transition_time, ea.STATE_SET);
|
|
578
|
+
break;
|
|
579
|
+
|
|
580
|
+
case 'switch':
|
|
581
|
+
for (const prop of expose.features) {
|
|
582
|
+
switch (prop.name) {
|
|
583
|
+
case 'state':
|
|
584
|
+
pushToStates(genState(prop, 'switch'), prop.access);
|
|
585
|
+
break;
|
|
586
|
+
default:
|
|
587
|
+
pushToStates(genState(prop), prop.access);
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
break;
|
|
592
|
+
|
|
593
|
+
case 'numeric':
|
|
594
|
+
if (expose.endpoint) {
|
|
595
|
+
state = genState(expose);
|
|
596
|
+
} else {
|
|
597
|
+
switch (expose.name) {
|
|
598
|
+
case 'linkquality':
|
|
599
|
+
state = undefined;
|
|
600
|
+
break;
|
|
601
|
+
|
|
602
|
+
case 'battery':
|
|
603
|
+
state = statesDefs.battery;
|
|
604
|
+
break;
|
|
605
|
+
|
|
606
|
+
case 'voltage':
|
|
607
|
+
state = statesDefs.plug_voltage;
|
|
608
|
+
break;
|
|
609
|
+
|
|
610
|
+
case 'temperature':
|
|
611
|
+
state = statesDefs.temperature;
|
|
612
|
+
break;
|
|
613
|
+
|
|
614
|
+
case 'humidity':
|
|
615
|
+
state = statesDefs.humidity;
|
|
616
|
+
break;
|
|
617
|
+
|
|
618
|
+
case 'pressure':
|
|
619
|
+
state = statesDefs.pressure;
|
|
620
|
+
break;
|
|
621
|
+
|
|
622
|
+
case 'illuminance':
|
|
623
|
+
state = statesDefs.illuminance_raw;
|
|
624
|
+
break;
|
|
625
|
+
|
|
626
|
+
case 'illuminance_lux':
|
|
627
|
+
state = statesDefs.illuminance;
|
|
628
|
+
break;
|
|
629
|
+
|
|
630
|
+
case 'power':
|
|
631
|
+
state = statesDefs.load_power;
|
|
632
|
+
break;
|
|
633
|
+
|
|
634
|
+
default:
|
|
635
|
+
state = genState(expose);
|
|
636
|
+
break;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
if (state) {
|
|
640
|
+
pushToStates(state, expose.access);
|
|
641
|
+
}
|
|
642
|
+
break;
|
|
643
|
+
|
|
644
|
+
case 'enum':
|
|
645
|
+
switch (expose.name) {
|
|
646
|
+
case 'action': {
|
|
647
|
+
// Ansatz:
|
|
648
|
+
|
|
649
|
+
// Action aufspalten in 2 Blöcke:
|
|
650
|
+
// Action (bekommt text ausser hold und release, auto reset nach 250 ms)
|
|
651
|
+
// Hold: wird gesetzt bei hold, gelöscht bei passendem Release
|
|
652
|
+
|
|
653
|
+
if (!Array.isArray(expose.values)) break;
|
|
654
|
+
const hasHold = expose.values.find((actionName) => actionName.includes('hold'));
|
|
655
|
+
const hasRelease = expose.values.find((actionName) => actionName.includes('release'));
|
|
656
|
+
for (const actionName of expose.values) {
|
|
657
|
+
// is release state ? - skip
|
|
658
|
+
if (hasHold && hasRelease && actionName.includes('release')) continue;
|
|
659
|
+
// is hold state ?
|
|
660
|
+
if (hasHold && hasRelease && actionName.includes('hold')) {
|
|
661
|
+
const releaseActionName = actionName.replace('hold', 'release');
|
|
662
|
+
state = {
|
|
663
|
+
id: actionName.replace(/\*/g, ''),
|
|
664
|
+
prop: 'action',
|
|
665
|
+
name: actionName,
|
|
666
|
+
icon: undefined,
|
|
667
|
+
role: 'button',
|
|
668
|
+
write: false,
|
|
669
|
+
read: true,
|
|
670
|
+
type: 'boolean',
|
|
671
|
+
getter: payload => payload.action === actionName ? true : (payload.action === releaseActionName ? false : undefined),
|
|
672
|
+
};
|
|
673
|
+
} else {
|
|
674
|
+
state = {
|
|
675
|
+
id: actionName.replace(/\*/g, ''),
|
|
676
|
+
prop: 'action',
|
|
677
|
+
name: actionName,
|
|
678
|
+
icon: undefined,
|
|
679
|
+
role: 'button',
|
|
680
|
+
write: false,
|
|
681
|
+
read: true,
|
|
682
|
+
type: 'boolean',
|
|
683
|
+
getter: payload => payload.action === actionName ? true : undefined,
|
|
684
|
+
isEvent: true,
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
pushToStates(state, expose.access);
|
|
688
|
+
}
|
|
689
|
+
state = null;
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
692
|
+
default:
|
|
693
|
+
state = genState(expose);
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
if (state) pushToStates(state, expose.access);
|
|
697
|
+
break;
|
|
698
|
+
|
|
699
|
+
case 'binary':
|
|
700
|
+
if (expose.endpoint) {
|
|
701
|
+
state = genState(expose);
|
|
702
|
+
} else {
|
|
703
|
+
switch (expose.name) {
|
|
704
|
+
case 'contact':
|
|
705
|
+
state = statesDefs.contact;
|
|
706
|
+
pushToStates(statesDefs.opened, ea.STATE);
|
|
707
|
+
break;
|
|
708
|
+
|
|
709
|
+
case 'battery_low':
|
|
710
|
+
state = statesDefs.heiman_batt_low;
|
|
711
|
+
break;
|
|
712
|
+
|
|
713
|
+
case 'tamper':
|
|
714
|
+
state = statesDefs.tamper;
|
|
715
|
+
break;
|
|
716
|
+
|
|
717
|
+
case 'water_leak':
|
|
718
|
+
state = statesDefs.water_detected;
|
|
719
|
+
break;
|
|
720
|
+
|
|
721
|
+
case 'lock':
|
|
722
|
+
state = statesDefs.child_lock;
|
|
723
|
+
break;
|
|
724
|
+
|
|
725
|
+
case 'occupancy':
|
|
726
|
+
state = statesDefs.occupancy;
|
|
727
|
+
break;
|
|
728
|
+
|
|
729
|
+
default:
|
|
730
|
+
state = genState(expose);
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (state) {
|
|
735
|
+
pushToStates(state, expose.access);
|
|
736
|
+
}
|
|
737
|
+
break;
|
|
738
|
+
|
|
739
|
+
case 'text':
|
|
740
|
+
state = genState(expose);
|
|
741
|
+
pushToStates(state, expose.access);
|
|
742
|
+
break;
|
|
743
|
+
|
|
744
|
+
case 'lock':
|
|
745
|
+
case 'fan':
|
|
746
|
+
case 'cover':
|
|
747
|
+
for (const prop of expose.features) {
|
|
748
|
+
switch (prop.name) {
|
|
749
|
+
case 'state':
|
|
750
|
+
pushToStates(genState(prop, 'switch'), prop.access);
|
|
751
|
+
break;
|
|
752
|
+
default:
|
|
753
|
+
pushToStates(genState(prop), prop.access);
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
break;
|
|
758
|
+
|
|
759
|
+
case 'climate':
|
|
760
|
+
for (const prop of expose.features) {
|
|
761
|
+
switch (prop.name) {
|
|
762
|
+
case 'away_mode':
|
|
763
|
+
pushToStates(statesDefs.climate_away_mode, prop.access);
|
|
764
|
+
break;
|
|
765
|
+
case 'system_mode':
|
|
766
|
+
pushToStates(statesDefs.climate_system_mode, prop.access);
|
|
767
|
+
break;
|
|
768
|
+
case 'running_mode':
|
|
769
|
+
pushToStates(statesDefs.climate_running_mode, prop.access);
|
|
770
|
+
break;
|
|
771
|
+
default:
|
|
772
|
+
pushToStates(genState(prop), prop.access);
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
break;
|
|
777
|
+
|
|
778
|
+
case 'composite':
|
|
779
|
+
for (const prop of expose.features) {
|
|
780
|
+
if (prop.type == 'numeric') {
|
|
781
|
+
const st = genState(prop);
|
|
782
|
+
st.prop = expose.property;
|
|
783
|
+
st.inOptions = true;
|
|
784
|
+
// I'm not fully sure, as it really needed, but
|
|
785
|
+
st.setterOpt = (value, options) => {
|
|
786
|
+
const result = {};
|
|
787
|
+
options[prop.property] = value;
|
|
788
|
+
result[expose.property] = options;
|
|
789
|
+
return result;
|
|
790
|
+
};
|
|
791
|
+
// if we have a composite expose, the value have to be an object {expose.property : {prop.property: value}}
|
|
792
|
+
if (prop.access & ea.SET) {
|
|
793
|
+
st.setter = (value, options) => {
|
|
794
|
+
const result = {};
|
|
795
|
+
options[prop.property] = value;
|
|
796
|
+
result[expose.property] = options;
|
|
797
|
+
return result;
|
|
798
|
+
};
|
|
799
|
+
st.setattr = expose.property;
|
|
800
|
+
}
|
|
801
|
+
// if we have a composite expose, the payload will be an object {expose.property : {prop.property: value}}
|
|
802
|
+
if (prop.access & ea.STATE) {
|
|
803
|
+
st.getter = payload => {
|
|
804
|
+
if ((payload.hasOwnProperty(expose.property)) && (payload[expose.property] !== null) && payload[expose.property].hasOwnProperty(prop.property)) {
|
|
805
|
+
return !isNaN(payload[expose.property][prop.property]) ? payload[expose.property][prop.property] : undefined;
|
|
806
|
+
} else {
|
|
807
|
+
return undefined;
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
} else {
|
|
811
|
+
st.getter = payload => undefined;
|
|
812
|
+
}
|
|
813
|
+
pushToStates(st, prop.access);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
if (prop.type == 'list') {
|
|
817
|
+
for (const propList of prop.item_type.features) {
|
|
818
|
+
const st = genState(propList);
|
|
819
|
+
st.prop = expose.property;
|
|
820
|
+
st.inOptions = true;
|
|
821
|
+
st.setterOpt = (value, options) => {
|
|
822
|
+
const result = {};
|
|
823
|
+
options[propList.property] = value;
|
|
824
|
+
result[expose.property] = options;
|
|
825
|
+
return result;
|
|
826
|
+
};
|
|
827
|
+
if (propList.access & ea.SET) {
|
|
828
|
+
st.setter = (value, options) => {
|
|
829
|
+
const result = {};
|
|
830
|
+
options[propList.property] = value;
|
|
831
|
+
result[expose.property] = options;
|
|
832
|
+
return result;
|
|
833
|
+
};
|
|
834
|
+
st.setattr = expose.property;
|
|
835
|
+
}
|
|
836
|
+
if (propList.access & ea.STATE) {
|
|
837
|
+
st.getter = payload => {
|
|
838
|
+
if ((payload.hasOwnProperty(expose.property)) && (payload[expose.property] !== null) && payload[expose.property].hasOwnProperty(propList.property)) {
|
|
839
|
+
return !isNaN(payload[expose.property][propList.property]) ? payload[expose.property][propList.property] : undefined;
|
|
840
|
+
} else {
|
|
841
|
+
return undefined;
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
} else {
|
|
845
|
+
st.getter = payload => undefined;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
st.id = st.prop + '_' + st.id;
|
|
849
|
+
pushToStates(st, propList.access);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
break;
|
|
854
|
+
default:
|
|
855
|
+
console.log(`Unhandled expose type ${expose.type} for device ${model}`);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
const newDev = {
|
|
859
|
+
models: [model],
|
|
860
|
+
icon,
|
|
861
|
+
states,
|
|
862
|
+
exposed: true,
|
|
863
|
+
};
|
|
864
|
+
// make the function code printable in log
|
|
865
|
+
//console.log(`Created mapping for device ${model}: ${JSON.stringify(newDev, function(key, value) {
|
|
866
|
+
// if (typeof value === 'function') {return value.toString() } else { return value } }, ' ')}`);
|
|
867
|
+
return newDev;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
function applyExposes(mappedDevices, byModel, allExcludesObj) {
|
|
871
|
+
// for exclude search
|
|
872
|
+
const allExcludesStr = JSON.stringify(allExcludesObj);
|
|
873
|
+
// create or update device from exposes
|
|
874
|
+
for (const deviceDef of zigbeeHerdsmanConverters.definitions) {
|
|
875
|
+
applyDeviceDef(mappedDevices, byModel, allExcludesStr, deviceDef);
|
|
876
|
+
|
|
877
|
+
if (deviceDef.hasOwnProperty('whiteLabel')) {
|
|
878
|
+
for (const deviceWhiteLabel of deviceDef.whiteLabel) {
|
|
879
|
+
applyDeviceDef(mappedDevices, byModel, allExcludesStr, {
|
|
880
|
+
...deviceDef,
|
|
881
|
+
model: deviceWhiteLabel.model,
|
|
882
|
+
vendor: deviceWhiteLabel.vendor,
|
|
883
|
+
description: deviceWhiteLabel.description || deviceDef.description,
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
function applyDeviceDef(mappedDevices, byModel, allExcludesStr, deviceDef) {
|
|
891
|
+
const stripModel = utils.getModelRegEx(deviceDef.model);
|
|
892
|
+
// check if device is mapped
|
|
893
|
+
const existsMap = byModel.get(stripModel);
|
|
894
|
+
|
|
895
|
+
if ((deviceDef.hasOwnProperty('exposes') && (!existsMap || !existsMap.hasOwnProperty('states'))) || allExcludesStr.indexOf(stripModel) > 0) {
|
|
896
|
+
try {
|
|
897
|
+
const newDevice = createFromExposes(stripModel, deviceDef);
|
|
898
|
+
if (!existsMap) {
|
|
899
|
+
mappedDevices.push(newDevice);
|
|
900
|
+
byModel.set(stripModel, newDevice);
|
|
901
|
+
} else {
|
|
902
|
+
existsMap.states = newDevice.states;
|
|
903
|
+
existsMap.exposed = true;
|
|
904
|
+
}
|
|
905
|
+
} catch (e) {
|
|
906
|
+
console.log(`Wrong expose devicedefinition ${deviceDef.vendor} ${stripModel}`);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
module.exports = {
|
|
912
|
+
applyExposes: applyExposes,
|
|
913
|
+
};
|