zigbee-herdsman-converters 14.0.685 → 14.0.687
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/converters/fromZigbee.js +4 -0
- package/devices/danfoss.js +1 -1
- package/devices/philips.js +56 -16
- package/devices/sinope.js +11 -8
- package/devices/tuya.js +5 -2
- package/lib/color.js +11 -0
- package/lib/exposes.js +10 -0
- package/lib/philips.js +152 -0
- package/lib/tuya.js +19 -0
- package/lib/utils.js +11 -4
- package/package.json +1 -1
package/converters/fromZigbee.js
CHANGED
|
@@ -6278,6 +6278,10 @@ const converters = {
|
|
|
6278
6278
|
result.position = options.invert_cover ? 100 - result.position : result.position;
|
|
6279
6279
|
}
|
|
6280
6280
|
}
|
|
6281
|
+
// Add the state
|
|
6282
|
+
if ('position' in result) {
|
|
6283
|
+
result.state = result.position === 0 ? 'CLOSE' : 'OPEN';
|
|
6284
|
+
}
|
|
6281
6285
|
return result;
|
|
6282
6286
|
},
|
|
6283
6287
|
},
|
package/devices/danfoss.js
CHANGED
|
@@ -11,7 +11,7 @@ module.exports = [
|
|
|
11
11
|
{
|
|
12
12
|
// eTRV0100 is the same as Hive TRV001 and Popp eT093WRO. If implementing anything, please consider
|
|
13
13
|
// changing those two too.
|
|
14
|
-
zigbeeModel: ['eTRV0100', 'eTRV0101'],
|
|
14
|
+
zigbeeModel: ['eTRV0100', 'eTRV0101', 'eTRV0103'],
|
|
15
15
|
model: '014G2461',
|
|
16
16
|
vendor: 'Danfoss',
|
|
17
17
|
description: 'Ally thermostat',
|
package/devices/philips.js
CHANGED
|
@@ -4,6 +4,7 @@ const tz = require('../converters/toZigbee');
|
|
|
4
4
|
const ota = require('../lib/ota');
|
|
5
5
|
const reporting = require('../lib/reporting');
|
|
6
6
|
const globalStore = require('../lib/store');
|
|
7
|
+
const philips = require('../lib/philips');
|
|
7
8
|
const utils = require('../lib/utils');
|
|
8
9
|
const e = exposes.presets;
|
|
9
10
|
const ea = exposes.access;
|
|
@@ -40,6 +41,30 @@ const hueExtend = {
|
|
|
40
41
|
toZigbee: extendDontUse.light_onoff_brightness_colortemp_color({supportsHS: true, ...options})
|
|
41
42
|
.toZigbee.concat([tz.hue_power_on_behavior, tz.hue_power_on_error]),
|
|
42
43
|
}),
|
|
44
|
+
light_onoff_brightness_colortemp_color_gradient: (options={}) => ({
|
|
45
|
+
...extendDontUse.light_onoff_brightness_colortemp_color({supportsHS: true, noConfigure: true, ...options}),
|
|
46
|
+
ota: ota.zigbeeOTA,
|
|
47
|
+
meta: {turnsOffAtBrightness1: true},
|
|
48
|
+
configure: async (device, coordinatorEndpoint, logger) => {
|
|
49
|
+
await extendDontUse.light_onoff_brightness_colortemp_color({supportsHS: true, ...options})
|
|
50
|
+
.configure(device, coordinatorEndpoint, logger);
|
|
51
|
+
for (const ep of device.endpoints) {
|
|
52
|
+
await ep.bind('manuSpecificPhilips2', coordinatorEndpoint);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
exposes: extendDontUse.light_onoff_brightness_colortemp_color({supportsHS: true, ...options}).exposes.concat([
|
|
56
|
+
// gradient_scene is deprecated, use gradient instead
|
|
57
|
+
exposes.enum('gradient_scene', ea.SET, Object.keys(gradientScenes)),
|
|
58
|
+
exposes.list('gradient', ea.ALL, exposes.text('hex', 'Color in RGB HEX format (eg #663399)'))
|
|
59
|
+
.withLengthMin(1)
|
|
60
|
+
.withLengthMax(9)
|
|
61
|
+
.withDescription('List of RGB HEX colors'),
|
|
62
|
+
]),
|
|
63
|
+
fromZigbee: extendDontUse.light_onoff_brightness_colortemp_color({supportsHS: true, ...options}).fromZigbee.concat(
|
|
64
|
+
[fzLocal.gradient({reverse: true})]),
|
|
65
|
+
toZigbee: extendDontUse.light_onoff_brightness_colortemp_color({supportsHS: true, ...options}).toZigbee.concat(
|
|
66
|
+
[tz.hue_power_on_behavior, tz.hue_power_on_error, tzLocal.gradient_scene, tzLocal.gradient({reverse: true})]),
|
|
67
|
+
}),
|
|
43
68
|
};
|
|
44
69
|
|
|
45
70
|
const fzLocal = {
|
|
@@ -82,6 +107,20 @@ const fzLocal = {
|
|
|
82
107
|
return payload;
|
|
83
108
|
},
|
|
84
109
|
},
|
|
110
|
+
gradient: (opts = {reverse: false}) => {
|
|
111
|
+
return {
|
|
112
|
+
cluster: 'manuSpecificPhilips2',
|
|
113
|
+
type: ['attributeReport', 'readResponse'],
|
|
114
|
+
convert: (model, msg, publish, options, meta) => {
|
|
115
|
+
if (msg.data.hasOwnProperty('state')) {
|
|
116
|
+
const input = msg.data['state'].toString('hex');
|
|
117
|
+
const gradient = philips.decodeGradientColors(input, opts);
|
|
118
|
+
return {gradient: gradient.colors};
|
|
119
|
+
}
|
|
120
|
+
return {};
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
},
|
|
85
124
|
};
|
|
86
125
|
|
|
87
126
|
const gradientScenes = {
|
|
@@ -172,6 +211,19 @@ const tzLocal = {
|
|
|
172
211
|
await entity.command('manuSpecificPhilips2', 'multiColor', payload);
|
|
173
212
|
},
|
|
174
213
|
},
|
|
214
|
+
gradient: (opts = {reverse: false}) => {
|
|
215
|
+
return {
|
|
216
|
+
key: ['gradient'],
|
|
217
|
+
convertSet: async (entity, key, value, meta) => {
|
|
218
|
+
const scene = philips.encodeGradientColors(value, opts);
|
|
219
|
+
const payload = {data: Buffer.from(scene, 'hex')};
|
|
220
|
+
await entity.command('manuSpecificPhilips2', 'multiColor', payload);
|
|
221
|
+
},
|
|
222
|
+
convertGet: async (entity, key, meta) => {
|
|
223
|
+
await entity.read('manuSpecificPhilips2', ['state']);
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
},
|
|
175
227
|
};
|
|
176
228
|
|
|
177
229
|
module.exports = [
|
|
@@ -1650,20 +1702,14 @@ module.exports = [
|
|
|
1650
1702
|
model: '4080248U9',
|
|
1651
1703
|
vendor: 'Philips',
|
|
1652
1704
|
description: 'Hue White and color ambiance Signe floor light',
|
|
1653
|
-
|
|
1654
|
-
exposes: [exposes.enum('gradient_scene', ea.SET, Object.keys(gradientScenes)),
|
|
1655
|
-
...hueExtend.light_onoff_brightness_colortemp_color({colorTempRange: [153, 500]}).exposes],
|
|
1656
|
-
extend: hueExtend.light_onoff_brightness_colortemp_color({colorTempRange: [153, 500]}),
|
|
1705
|
+
extend: hueExtend.light_onoff_brightness_colortemp_color_gradient({colorTempRange: [153, 500]}),
|
|
1657
1706
|
},
|
|
1658
1707
|
{
|
|
1659
1708
|
zigbeeModel: ['915005987601'],
|
|
1660
1709
|
model: '915005987601',
|
|
1661
1710
|
vendor: 'Philips',
|
|
1662
1711
|
description: 'Hue Gradient Signe floor lamp (black)',
|
|
1663
|
-
|
|
1664
|
-
exposes: [exposes.enum('gradient_scene', ea.SET, Object.keys(gradientScenes)),
|
|
1665
|
-
...hueExtend.light_onoff_brightness_colortemp_color({colorTempRange: [153, 500]}).exposes],
|
|
1666
|
-
extend: hueExtend.light_onoff_brightness_colortemp_color({colorTempRange: [153, 500]}),
|
|
1712
|
+
extend: hueExtend.light_onoff_brightness_colortemp_color_gradient({colorTempRange: [153, 500]}),
|
|
1667
1713
|
},
|
|
1668
1714
|
{
|
|
1669
1715
|
zigbeeModel: ['LCT020'],
|
|
@@ -2954,20 +3000,14 @@ module.exports = [
|
|
|
2954
3000
|
model: '929003535301',
|
|
2955
3001
|
vendor: 'Philips',
|
|
2956
3002
|
description: 'Hue Festavia gradient light string 250',
|
|
2957
|
-
|
|
2958
|
-
exposes: [exposes.enum('gradient_scene', ea.SET, Object.keys(gradientScenes)),
|
|
2959
|
-
...hueExtend.light_onoff_brightness_colortemp_color({colorTempRange: [153, 500]}).exposes],
|
|
2960
|
-
extend: hueExtend.light_onoff_brightness_colortemp_color({colorTempRange: [153, 500]}),
|
|
3003
|
+
extend: hueExtend.light_onoff_brightness_colortemp_color_gradient({colorTempRange: [153, 500]}),
|
|
2961
3004
|
},
|
|
2962
3005
|
{
|
|
2963
3006
|
zigbeeModel: ['915005987101'],
|
|
2964
3007
|
model: '915005987101',
|
|
2965
3008
|
vendor: 'Philips',
|
|
2966
3009
|
description: 'Hue Gradient Signe floor lamp (white)',
|
|
2967
|
-
|
|
2968
|
-
exposes: [exposes.enum('gradient_scene', ea.SET, Object.keys(gradientScenes)),
|
|
2969
|
-
...hueExtend.light_onoff_brightness_colortemp_color({colorTempRange: [153, 500]}).exposes],
|
|
2970
|
-
extend: hueExtend.light_onoff_brightness_colortemp_color({colorTempRange: [153, 500]}),
|
|
3010
|
+
extend: hueExtend.light_onoff_brightness_colortemp_color_gradient({colorTempRange: [153, 500]}),
|
|
2971
3011
|
},
|
|
2972
3012
|
{
|
|
2973
3013
|
zigbeeModel: ['929003526301'],
|
package/devices/sinope.js
CHANGED
|
@@ -549,14 +549,20 @@ module.exports = [
|
|
|
549
549
|
configure: async (device, coordinatorEndpoint, logger) => {
|
|
550
550
|
const endpoint = device.getEndpoint(1);
|
|
551
551
|
const binds = [
|
|
552
|
-
'genBasic', 'genIdentify', 'hvacThermostat', 'hvacUserInterfaceCfg',
|
|
552
|
+
'genBasic', 'genIdentify', 'genGroups', 'hvacThermostat', 'hvacUserInterfaceCfg',
|
|
553
553
|
'msTemperatureMeasurement', 'haElectricalMeasurement', 'seMetering',
|
|
554
554
|
'manuSpecificSinope'];
|
|
555
555
|
await reporting.bind(endpoint, coordinatorEndpoint, binds);
|
|
556
|
+
const thermostatDate = new Date();
|
|
557
|
+
const thermostatTimeSec = thermostatDate.getTime() / 1000;
|
|
558
|
+
const thermostatTimezoneOffsetSec = thermostatDate.getTimezoneOffset() * 60;
|
|
559
|
+
const currentTimeToDisplay = Math.round(thermostatTimeSec - thermostatTimezoneOffsetSec - 946684800);
|
|
560
|
+
await endpoint.write('manuSpecificSinope', {currentTimeToDisplay}, {manufacturerCode: 0x119C});
|
|
561
|
+
await endpoint.write('manuSpecificSinope', {'secondScreenBehavior': 0}, {manufacturerCode: 0x119C}); // Mode auto
|
|
562
|
+
|
|
556
563
|
await reporting.thermostatTemperature(endpoint);
|
|
557
564
|
await reporting.thermostatPIHeatingDemand(endpoint);
|
|
558
565
|
await reporting.thermostatOccupiedHeatingSetpoint(endpoint);
|
|
559
|
-
await reporting.thermostatUnoccupiedHeatingSetpoint(endpoint);
|
|
560
566
|
await reporting.thermostatSystemMode(endpoint);
|
|
561
567
|
|
|
562
568
|
await reporting.readMeteringMultiplierDivisor(endpoint);
|
|
@@ -566,13 +572,10 @@ module.exports = [
|
|
|
566
572
|
await reporting.rmsCurrent(endpoint, {min: 10, max: 306, change: 100}); // divider 1000: 0.1Arms
|
|
567
573
|
await reporting.rmsVoltage(endpoint, {min: 10, max: 307, change: 5}); // divider 10: 0.5Vrms
|
|
568
574
|
|
|
569
|
-
const thermostatDate = new Date();
|
|
570
|
-
const thermostatTimeSec = thermostatDate.getTime() / 1000;
|
|
571
|
-
const thermostatTimezoneOffsetSec = thermostatDate.getTimezoneOffset() * 60;
|
|
572
|
-
const currentTimeToDisplay = Math.round(thermostatTimeSec - thermostatTimezoneOffsetSec - 946684800);
|
|
573
|
-
await endpoint.write('manuSpecificSinope', {currentTimeToDisplay}, {manufacturerCode: 0x119C});
|
|
574
|
-
|
|
575
575
|
await reporting.temperature(endpoint, {min: 1, max: 0xFFFF}); // Disable default reporting
|
|
576
|
+
try {
|
|
577
|
+
await reporting.thermostatUnoccupiedHeatingSetpoint(endpoint);
|
|
578
|
+
} catch (error) {/* Do nothing */} // Not enought space but shall pass
|
|
576
579
|
try {
|
|
577
580
|
await reporting.thermostatRunningState(endpoint);
|
|
578
581
|
} catch (error) {/* Do nothing */} // Not enought space
|
package/devices/tuya.js
CHANGED
|
@@ -2080,6 +2080,7 @@ module.exports = [
|
|
|
2080
2080
|
},
|
|
2081
2081
|
{
|
|
2082
2082
|
fingerprint: tuya.fingerprint('TS0601', [
|
|
2083
|
+
'_TZE200_sur6q7ko', /* model: '3012732', vendor: 'LSC Smart Connect' */
|
|
2083
2084
|
'_TZE200_hue3yfsn', /* model: 'TV02-Zigbee', vendor: 'TuYa' */
|
|
2084
2085
|
'_TZE200_e9ba97vf', /* model: 'TV01-ZB', vendor: 'Moes' */
|
|
2085
2086
|
'_TZE200_husqqvux', /* model: 'TSL-TRV-TV01ZG', vendor: 'Tesla Smart' */
|
|
@@ -2233,6 +2234,7 @@ module.exports = [
|
|
|
2233
2234
|
{
|
|
2234
2235
|
fingerprint: tuya.fingerprint('TS0601', [
|
|
2235
2236
|
'_TZE200_bvu2wnxz', /* model: 'ME167', vendor: 'Avatto' */
|
|
2237
|
+
'_TZE200_6rdj8dzm', /* model: 'ME167', vendor: 'Avatto' */
|
|
2236
2238
|
]),
|
|
2237
2239
|
model: 'TS0601_thermostat_3',
|
|
2238
2240
|
vendor: 'TuYa',
|
|
@@ -2824,7 +2826,7 @@ module.exports = [
|
|
|
2824
2826
|
},
|
|
2825
2827
|
},
|
|
2826
2828
|
{
|
|
2827
|
-
fingerprint: tuya.fingerprint('TS0014', ['_TZ3000_jr2atpww', '_TYZB01_dvakyzhd',
|
|
2829
|
+
fingerprint: tuya.fingerprint('TS0014', ['_TZ3000_jr2atpww', '_TYZB01_dvakyzhd', '_TZ3000_mrduubod',
|
|
2828
2830
|
'_TZ3210_w3hl6rao', '_TYZB01_bagt1e4o', '_TZ3000_r0pmi2p3', '_TZ3000_fxjdcikv', '_TZ3000_q6vxaod1']),
|
|
2829
2831
|
model: 'TS0014',
|
|
2830
2832
|
vendor: 'TuYa',
|
|
@@ -3075,7 +3077,8 @@ module.exports = [
|
|
|
3075
3077
|
fingerprint: [{modelID: 'TS0210', manufacturerName: '_TYZB01_3zv6oleo'},
|
|
3076
3078
|
{modelID: 'TS0210', manufacturerName: '_TYZB01_j9xxahcl'},
|
|
3077
3079
|
{modelID: 'TS0210', manufacturerName: '_TYZB01_kulduhbj'},
|
|
3078
|
-
{modelID: 'TS0210', manufacturerName: '_TZ3000_bmfw9ykl'}
|
|
3080
|
+
{modelID: 'TS0210', manufacturerName: '_TZ3000_bmfw9ykl'},
|
|
3081
|
+
{modelID: 'TS0210', manufacturerName: '_TZ3000_fkxmyics'}],
|
|
3079
3082
|
model: 'TS0210',
|
|
3080
3083
|
vendor: 'TuYa',
|
|
3081
3084
|
description: 'Vibration sensor',
|
package/lib/color.js
CHANGED
|
@@ -180,6 +180,17 @@ class ColorRGB {
|
|
|
180
180
|
}
|
|
181
181
|
return new ColorRGB(transform(this.red), transform(this.green), transform(this.blue));
|
|
182
182
|
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Create hex string from RGB color
|
|
186
|
+
* @return {ColorRGB} hex hex encoded RGB color
|
|
187
|
+
*/
|
|
188
|
+
toHEX() {
|
|
189
|
+
return '#' +
|
|
190
|
+
parseInt((this.red * 255).toFixed(0)).toString(16).padStart(2, '0')+
|
|
191
|
+
parseInt((this.green * 255).toFixed(0)).toString(16).padStart(2, '0')+
|
|
192
|
+
parseInt((this.blue * 255).toFixed(0)).toString(16).padStart(2, '0');
|
|
193
|
+
}
|
|
183
194
|
}
|
|
184
195
|
|
|
185
196
|
/**
|
package/lib/exposes.js
CHANGED
|
@@ -124,6 +124,16 @@ class List extends Base {
|
|
|
124
124
|
this.item_type = itemType;
|
|
125
125
|
delete this.item_type.property;
|
|
126
126
|
}
|
|
127
|
+
|
|
128
|
+
withLengthMin(value) {
|
|
129
|
+
this.length_min = value;
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
withLengthMax(value) {
|
|
134
|
+
this.length_max = value;
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
127
137
|
}
|
|
128
138
|
|
|
129
139
|
class Numeric extends Base {
|
package/lib/philips.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ColorXY = require('./color').ColorXY;
|
|
4
|
+
const ColorRGB = require('./color').ColorRGB;
|
|
5
|
+
|
|
6
|
+
const encodeRGBToScaledGradient = (hex) => {
|
|
7
|
+
const xy = ColorRGB.fromHex(hex).toXY();
|
|
8
|
+
const x = xy.x * 4095 / 0.7347;
|
|
9
|
+
const y = xy.y * 4095 / 0.8413;
|
|
10
|
+
const xx = Math.round(x).toString(16);
|
|
11
|
+
const yy = Math.round(y).toString(16);
|
|
12
|
+
|
|
13
|
+
return [
|
|
14
|
+
xx[1], xx[2],
|
|
15
|
+
yy[2], xx[0],
|
|
16
|
+
yy[0], yy[1],
|
|
17
|
+
].join('');
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const decodeScaledGradientToRGB = (p) => {
|
|
21
|
+
const x = p[3] + p[0] + p[1];
|
|
22
|
+
const y = p[4] + p[5] + p[2];
|
|
23
|
+
|
|
24
|
+
const xx = (parseInt(x, 16) * 0.7347 / 4095).toFixed(4);
|
|
25
|
+
const yy = (parseInt(y, 16) * 0.8413 / 4095).toFixed(4);
|
|
26
|
+
|
|
27
|
+
return new ColorXY(xx, yy).toRGB().toHEX();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function decodeGradientColors(input, opts) {
|
|
31
|
+
// Example set: 500104001350000000f3297ff3bd52f3bd52f3297ff3bd522800
|
|
32
|
+
// Example get 4b010164fb74346b1350000000f3297fda7d55da7d55f3297fda7d552800
|
|
33
|
+
|
|
34
|
+
// 4b01 - mode? (4) (0b00 single color?, 4b01 gradient?)
|
|
35
|
+
// 01 - on/off (2) or is it 1 full byte?
|
|
36
|
+
// 64 - brightness (2)
|
|
37
|
+
// fb74346b - unknown (8)
|
|
38
|
+
// 13 - length (2)
|
|
39
|
+
// 50 - ncolors (2)
|
|
40
|
+
// 000000 - unknown (6)
|
|
41
|
+
// f3297fda7d55da7d55f3297fda7d55 - colors (6 * ncolors)
|
|
42
|
+
// 28 - segments (2)
|
|
43
|
+
// 00 - offset (2)
|
|
44
|
+
|
|
45
|
+
// Skip the unknown prefix (4 bytes)
|
|
46
|
+
input = input.slice(4);
|
|
47
|
+
|
|
48
|
+
// On/off (1 byte)
|
|
49
|
+
const on = parseInt(input.slice(0, 2), 16) === 1;
|
|
50
|
+
input = input.slice(2);
|
|
51
|
+
|
|
52
|
+
// Brightness (2 bytes)
|
|
53
|
+
const brightness = parseInt(input.slice(0, 2), 16);
|
|
54
|
+
input = input.slice(2);
|
|
55
|
+
|
|
56
|
+
// Unknown (8 bytes)
|
|
57
|
+
input = input.slice(8);
|
|
58
|
+
|
|
59
|
+
// Length (2 bytes)
|
|
60
|
+
input = input.slice(2);
|
|
61
|
+
|
|
62
|
+
// Number of colors (2 bytes)
|
|
63
|
+
const nColors = parseInt(input.slice(0, 2), 16) >> 4;
|
|
64
|
+
input = input.slice(2);
|
|
65
|
+
|
|
66
|
+
// Unknown (6 bytes)
|
|
67
|
+
input = input.slice(6);
|
|
68
|
+
|
|
69
|
+
// Colors (6 * nColors bytes)
|
|
70
|
+
const colorsPayload = input.slice(0, 6 * nColors);
|
|
71
|
+
input = input.slice(6 * nColors);
|
|
72
|
+
const colors = colorsPayload.match(/.{6}/g).map(decodeScaledGradientToRGB);
|
|
73
|
+
|
|
74
|
+
// Segments (2 bytes)
|
|
75
|
+
const segments = parseInt(input.slice(0, 2), 16) >> 3;
|
|
76
|
+
input = input.slice(2);
|
|
77
|
+
|
|
78
|
+
// Offset (2 bytes)
|
|
79
|
+
const offset = parseInt(input.slice(0, 2), 16) >> 3;
|
|
80
|
+
|
|
81
|
+
if (opts.reverse) {
|
|
82
|
+
colors.reverse();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
colors,
|
|
87
|
+
|
|
88
|
+
gradient_extras: {
|
|
89
|
+
colors: nColors,
|
|
90
|
+
segments,
|
|
91
|
+
offset,
|
|
92
|
+
brightness,
|
|
93
|
+
on,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Value is a list of RGB HEX colors
|
|
99
|
+
function encodeGradientColors(value, opts) {
|
|
100
|
+
if (value.length > 9) {
|
|
101
|
+
throw new Error(`Expected up to 9 colors, got ${value.length}`);
|
|
102
|
+
}
|
|
103
|
+
if (value.length < 1) {
|
|
104
|
+
throw new Error(`Expected at least 1 color, got 0`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// For devices where it makes more sense to specify the colors in reverse
|
|
108
|
+
// For example Hue Signe, where the last color is the top color.
|
|
109
|
+
if (opts.reverse) {
|
|
110
|
+
value.reverse();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The number of colors and segments can technically differ. Here they are always the same, but we could
|
|
114
|
+
// support it by extending the API.
|
|
115
|
+
// If number of colors is less than the number of segments, the colors will repeat.
|
|
116
|
+
// It seems like the maximum number of colors is 9, and the maximum number of segments is 31.
|
|
117
|
+
const nColors = (value.length << 4).toString(16).padStart(2, '0');
|
|
118
|
+
|
|
119
|
+
let segments = value.length;
|
|
120
|
+
if (opts.segments) {
|
|
121
|
+
segments = opts.segments;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (segments < 1 || segments > 31) {
|
|
125
|
+
throw new Error(`Expected segments to be between 1 and 31 (inclusive), got ${segments}`);
|
|
126
|
+
}
|
|
127
|
+
const segmentsPayload = (segments << 3).toString(16).padStart(2, '0');
|
|
128
|
+
|
|
129
|
+
// Encode the colors
|
|
130
|
+
const colorsPayload = value.map(encodeRGBToScaledGradient).join('');
|
|
131
|
+
|
|
132
|
+
// Offset of the first color. 0 means the first segment uses the first color. (min 0, max 31)
|
|
133
|
+
let offset = 0;
|
|
134
|
+
if (opts.offset) {
|
|
135
|
+
offset = opts.offset;
|
|
136
|
+
}
|
|
137
|
+
const offsetPayload = (offset << 3).toString(16).padStart(2, '0');
|
|
138
|
+
|
|
139
|
+
// Payload length
|
|
140
|
+
const length = (1 + 3 * (value.length + 1)).toString(16).padStart(2, '0');
|
|
141
|
+
|
|
142
|
+
// 5001 - mode? set gradient?
|
|
143
|
+
// 0400 - unknown
|
|
144
|
+
const scene = `50010400${length}${nColors}000000${colorsPayload}${segmentsPayload}${offsetPayload}`;
|
|
145
|
+
|
|
146
|
+
return scene;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
decodeGradientColors,
|
|
151
|
+
encodeGradientColors,
|
|
152
|
+
};
|
package/lib/tuya.js
CHANGED
|
@@ -1652,6 +1652,17 @@ const tuyaFz = {
|
|
|
1652
1652
|
datapoints: {
|
|
1653
1653
|
cluster: 'manuSpecificTuya',
|
|
1654
1654
|
type: ['commandDataResponse', 'commandDataReport', 'commandActiveStatusReport', 'commandActiveStatusReportAlt'],
|
|
1655
|
+
options: (definition) => {
|
|
1656
|
+
const result = [];
|
|
1657
|
+
for (const datapoint of definition.meta.tuyaDatapoints) {
|
|
1658
|
+
const dpKey = datapoint[1];
|
|
1659
|
+
if (dpKey in utils.calibrateAndPrecisionRoundOptionsDefaultPrecision) {
|
|
1660
|
+
const type = utils.calibrateAndPrecisionRoundOptionsIsPercentual(dpKey) ? 'percentual' : 'absolute';
|
|
1661
|
+
result.push(exposes.options.precision(dpKey), exposes.options.calibration(dpKey, type));
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
return result;
|
|
1665
|
+
},
|
|
1655
1666
|
convert: (model, msg, publish, options, meta) => {
|
|
1656
1667
|
let result = {};
|
|
1657
1668
|
if (!model.meta || !model.meta.tuyaDatapoints) throw new Error('No datapoints map defined');
|
|
@@ -1671,6 +1682,14 @@ const tuyaFz = {
|
|
|
1671
1682
|
`with data ${JSON.stringify(dpValue)}`);
|
|
1672
1683
|
}
|
|
1673
1684
|
}
|
|
1685
|
+
|
|
1686
|
+
// Apply calibrateAndPrecisionRoundOptions
|
|
1687
|
+
const keys = Object.keys(utils.calibrateAndPrecisionRoundOptionsDefaultPrecision);
|
|
1688
|
+
for (const entry of Object.entries(result)) {
|
|
1689
|
+
if (keys.includes(entry[0])) {
|
|
1690
|
+
result[entry[0]] = utils.calibrateAndPrecisionRoundOptions(entry[1], options, entry[0]);
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1674
1693
|
return result;
|
|
1675
1694
|
},
|
|
1676
1695
|
},
|
package/lib/utils.js
CHANGED
|
@@ -75,13 +75,18 @@ function hasAlreadyProcessedMessage(msg, model, ID=null, key=null) {
|
|
|
75
75
|
return false;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
const
|
|
79
|
-
|
|
78
|
+
const calibrateAndPrecisionRoundOptionsDefaultPrecision = {
|
|
79
|
+
temperature: 2, humidity: 2, pressure: 1, pm25: 0, power: 2, current: 2, current_phase_b: 2, current_phase_c: 2,
|
|
80
|
+
voltage: 2, voltage_phase_b: 2, voltage_phase_c: 2, power_phase_b: 2, power_phase_c: 2,
|
|
81
|
+
};
|
|
82
|
+
function calibrateAndPrecisionRoundOptionsIsPercentual(type) {
|
|
83
|
+
return type.startsWith('current') || type.startsWith('voltage') || type.startsWith('power') || type.startsWith('illuminance');
|
|
84
|
+
}
|
|
80
85
|
function calibrateAndPrecisionRoundOptions(number, options, type) {
|
|
81
86
|
// Calibrate
|
|
82
87
|
const calibrateKey = `${type}_calibration`;
|
|
83
88
|
let calibrationOffset = options && options.hasOwnProperty(calibrateKey) ? options[calibrateKey] : 0;
|
|
84
|
-
if (
|
|
89
|
+
if (calibrateAndPrecisionRoundOptionsIsPercentual(type)) {
|
|
85
90
|
// linear calibration because measured value is zero based
|
|
86
91
|
// +/- percent
|
|
87
92
|
calibrationOffset = Math.round(number * calibrationOffset / 100);
|
|
@@ -90,7 +95,7 @@ function calibrateAndPrecisionRoundOptions(number, options, type) {
|
|
|
90
95
|
|
|
91
96
|
// Precision round
|
|
92
97
|
const precisionKey = `${type}_precision`;
|
|
93
|
-
const defaultValue =
|
|
98
|
+
const defaultValue = calibrateAndPrecisionRoundOptionsDefaultPrecision[type] || 0;
|
|
94
99
|
const precision = options && options.hasOwnProperty(precisionKey) ? options[precisionKey] : defaultValue;
|
|
95
100
|
return precisionRound(number, precision);
|
|
96
101
|
}
|
|
@@ -436,6 +441,8 @@ module.exports = {
|
|
|
436
441
|
mapNumberRange,
|
|
437
442
|
hasAlreadyProcessedMessage,
|
|
438
443
|
calibrateAndPrecisionRoundOptions,
|
|
444
|
+
calibrateAndPrecisionRoundOptionsIsPercentual,
|
|
445
|
+
calibrateAndPrecisionRoundOptionsDefaultPrecision,
|
|
439
446
|
toPercentage,
|
|
440
447
|
addActionGroup,
|
|
441
448
|
postfixWithEndpointName,
|