iobroker.zigbee 1.7.1 → 1.7.4

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.
Files changed (55) hide show
  1. package/.eslintignore +1 -1
  2. package/.eslintrc.json +36 -36
  3. package/.github/FUNDING.yml +3 -3
  4. package/.github/stale.yml +13 -13
  5. package/.github/workflows/test-and-release.yml +151 -151
  6. package/.travis/wiki.sh +27 -27
  7. package/LICENSE +21 -21
  8. package/README.md +379 -373
  9. package/admin/adapter-settings.js +244 -244
  10. package/admin/admin.js +2926 -2926
  11. package/admin/img/MLI-404011-MLI-404049.png +0 -0
  12. package/admin/img/philips_hue_lom001.png +0 -0
  13. package/admin/index.html +159 -159
  14. package/admin/index_m.html +1161 -1161
  15. package/admin/moment.min.js +1 -1
  16. package/admin/shuffle.min.js +2 -2
  17. package/admin/tab_m.html +944 -944
  18. package/admin/vis-network.min.css +1 -1
  19. package/admin/vis-network.min.js +27 -27
  20. package/admin/words.js +112 -112
  21. package/docs/de/readme.md +27 -27
  22. package/docs/en/readme.md +30 -30
  23. package/docs/flashing_via_arduino_(en).md +110 -110
  24. package/docs/ru/readme.md +28 -28
  25. package/docs/tutorial/groups-1.png +0 -0
  26. package/docs/tutorial/groups-2.png +0 -0
  27. package/docs/tutorial/tab-dev-1.png +0 -0
  28. package/io-package.json +354 -330
  29. package/lib/backup.js +171 -171
  30. package/lib/binding.js +325 -325
  31. package/lib/colors.js +460 -460
  32. package/lib/commands.js +501 -501
  33. package/lib/developer.js +148 -148
  34. package/lib/devices.js +3145 -3145
  35. package/lib/exclude.js +168 -168
  36. package/lib/exposes.js +804 -804
  37. package/lib/groups.js +342 -342
  38. package/lib/json.js +60 -60
  39. package/lib/networkmap.js +56 -56
  40. package/lib/ota.js +179 -179
  41. package/lib/rgb.js +255 -255
  42. package/lib/seriallist.js +37 -37
  43. package/lib/states.js +6416 -6416
  44. package/lib/statescontroller.js +666 -658
  45. package/lib/tools.js +54 -54
  46. package/lib/utils.js +151 -151
  47. package/lib/zbBaseExtension.js +36 -36
  48. package/lib/zbDelayedAction.js +152 -152
  49. package/lib/zbDeviceAvailability.js +315 -315
  50. package/lib/zbDeviceConfigure.js +152 -152
  51. package/lib/zbDeviceEvent.js +49 -49
  52. package/lib/zigbeecontroller.js +946 -946
  53. package/package.json +2 -2
  54. package/support/docgen.js +93 -93
  55. package/admin/img/zbt_remote.png +0 -0
package/lib/rgb.js CHANGED
@@ -1,255 +1,255 @@
1
- /*
2
- With these functions you can convert the CIE color space to the RGB color space and vice versa.
3
-
4
- The developer documentation for Philips Hue provides the formulas used in the code below:
5
- https://developers.meethue.com/documentation/color-conversions-rgb-xy
6
-
7
- I've used the formulas and Objective-C example code and transfered it to JavaScript.
8
-
9
-
10
- Examples:
11
-
12
- const rgb = cie_to_rgb(0.6611, 0.2936)
13
- const cie = rgb_to_cie(255, 39, 60)
14
-
15
- ------------------------------------------------------------------------------------
16
-
17
- The MIT License (MIT)
18
-
19
- Copyright (c) 2017 www.usolved.net
20
- Published under https://github.com/usolved/cie-rgb-converter
21
-
22
- Permission is hereby granted, free of charge, to any person obtaining a copy
23
- of this software and associated documentation files (the "Software"), to deal
24
- in the Software without restriction, including without limitation the rights
25
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
- copies of the Software, and to permit persons to whom the Software is
27
- furnished to do so, subject to the following conditions:
28
-
29
- The above copyright notice and this permission notice shall be included in
30
- all copies or substantial portions of the Software.
31
-
32
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38
- THE SOFTWARE.
39
- */
40
- 'use strict';
41
-
42
- const colors = require('./colors.js');
43
-
44
- /**
45
- * Converts CIE color space to RGB color space
46
- * @param {Number} x
47
- * @param {Number} y
48
- * @param {Number} brightness - Ranges from 1 to 254
49
- * @return {Array} Array that contains the color values for red, green and blue
50
- */
51
- function cie_to_rgb(x, y, brightness) {
52
- //Set to maximum brightness if no custom value was given (Not the slick ECMAScript 6 way for compatibility reasons)
53
- if (brightness === undefined) {
54
- brightness = 254;
55
- }
56
-
57
- const z = 1.0 - x - y;
58
- const Y = (brightness / 254).toFixed(2);
59
- const X = (Y / y) * x;
60
- const Z = (Y / y) * z;
61
-
62
- //Convert to RGB using Wide RGB D65 conversion
63
- let red = X * 1.656492 - Y * 0.354851 - Z * 0.255038;
64
- let green = -X * 0.707196 + Y * 1.655397 + Z * 0.036152;
65
- let blue = X * 0.051713 - Y * 0.121364 + Z * 1.011530;
66
-
67
- //If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
68
- if (red > blue && red > green && red > 1.0) {
69
-
70
- green = green / red;
71
- blue = blue / red;
72
- red = 1.0;
73
- }
74
- else if (green > blue && green > red && green > 1.0) {
75
-
76
- red = red / green;
77
- blue = blue / green;
78
- green = 1.0;
79
- }
80
- else if (blue > red && blue > green && blue > 1.0) {
81
-
82
- red = red / blue;
83
- green = green / blue;
84
- blue = 1.0;
85
- }
86
-
87
- //Reverse gamma correction
88
- red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, (1.0 / 2.4)) - 0.055;
89
- green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, (1.0 / 2.4)) - 0.055;
90
- blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, (1.0 / 2.4)) - 0.055;
91
-
92
-
93
- //Convert normalized decimal to decimal
94
- red = Math.round(red * 255);
95
- green = Math.round(green * 255);
96
- blue = Math.round(blue * 255);
97
-
98
- if (isNaN(red) || red < 0 ) {
99
- red = 0;
100
- }
101
-
102
- if (isNaN(green) || green < 0 ) {
103
- green = 0;
104
- }
105
-
106
- if (isNaN(blue) || blue < 0 ) {
107
- blue = 0;
108
- }
109
-
110
- return [red, green, blue];
111
- }
112
-
113
-
114
- /**
115
- * Converts RGB color space to CIE color space
116
- * @param {Number} red
117
- * @param {Number} green
118
- * @param {Number} blue
119
- * @return {Array} Array that contains the CIE color values for x and y
120
- */
121
- function rgb_to_cie(red, green, blue) {
122
- // Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device
123
- red = (red > 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red / 12.92);
124
- green = (green > 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : (green / 12.92);
125
- blue = (blue > 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : (blue / 12.92);
126
-
127
- // RGB values to XYZ using the Wide RGB D65 conversion formula
128
- const X = red * 0.664511 + green * 0.154324 + blue * 0.162028;
129
- const Y = red * 0.283881 + green * 0.668433 + blue * 0.047685;
130
- const Z = red * 0.000088 + green * 0.072310 + blue * 0.986039;
131
-
132
- // Calculate the xy values from the XYZ values
133
- let x = (X / (X + Y + Z)).toFixed(4);
134
- let y = (Y / (X + Y + Z)).toFixed(4);
135
-
136
- if (isNaN(x)) {
137
- x = 0;
138
- }
139
-
140
- if (isNaN(y)) {
141
- y = 0;
142
- }
143
-
144
- return [x, y];
145
- }
146
-
147
-
148
- function hsvToRGB(h, s, v) {
149
- h = h % 360 / 360;
150
- s = s / 100;
151
- v = v / 100;
152
-
153
- let r; let g; let b;
154
- if (arguments.length === 1) {
155
- s = h.s, v = h.v, h = h.h;
156
- }
157
- const i = Math.floor(h * 6);
158
- const f = h * 6 - i;
159
- const p = v * (1 - s);
160
- const q = v * (1 - f * s);
161
- const t = v * (1 - (1 - f) * s);
162
- switch (i % 6) {
163
- case 0: r = v, g = t, b = p; break;
164
- case 1: r = q, g = v, b = p; break;
165
- case 2: r = p, g = v, b = t; break;
166
- case 3: r = p, g = q, b = v; break;
167
- case 4: r = t, g = p, b = v; break;
168
- case 5: r = v, g = p, b = q; break;
169
- }
170
- return {
171
- r: Math.round(r * 255),
172
- g: Math.round(g * 255),
173
- b: Math.round(b * 255),
174
- };
175
- }
176
-
177
- function rgbToHSV(r, g, b, numeric) {
178
- if (arguments.length === 1) {
179
- g = r.g, b = r.b, r = r.r;
180
- }
181
- const max = Math.max(r, g, b); const min = Math.min(r, g, b);
182
- const d = max - min;
183
- let h;
184
- const s = (max === 0 ? 0 : d / max);
185
- const v = max / 255;
186
-
187
- switch (max) {
188
- case min: h = 0; break;
189
- case r: h = (g - b) + d * (g < b ? 6: 0); h /= 6 * d; break;
190
- case g: h = (b - r) + d * 2; h /= 6 * d; break;
191
- case b: h = (r - g) + d * 4; h /= 6 * d; break;
192
- }
193
- if (numeric) return {
194
- h: Math.round(h*360),
195
- s: Math.round(s*100),
196
- v: Math.round(v*100),
197
- };
198
- return {
199
- h: (h * 360).toFixed(3),
200
- s: (s * 100).toFixed(3),
201
- v: (v * 100).toFixed(3),
202
- };
203
- }
204
- function colorArrayFromString(value) {
205
- if (typeof(value) === 'string') {
206
- const rv = [];
207
- value.split(',').forEach(element => {
208
- rv.push(colors.ParseColor(element));
209
- });
210
- return rv;
211
- }
212
- return [{r:0,g:128,b:255}];
213
- }
214
-
215
- function colorStringFromRGBArray(payload)
216
- {
217
- let rv = []
218
- payload.forEach(element => {
219
- rv.push(rgb_to_rgbstring(element));
220
- });
221
- return rv.toString();
222
- }
223
-
224
- function hsv_to_cie(h,s,v){
225
- const rgb = hsvToRGB(h,s,v);
226
- return rgb_to_cie(rgb.r, rgb.g, rgb.b);
227
- }
228
-
229
- function rgb_to_rgbstring(element) {
230
- let col = '#';
231
- if (element && element.hasOwnProperty("r"))
232
- col = col + element.r.toString(16).padStart(2, '0');
233
- else col = col + '00';
234
- if (element && element.hasOwnProperty("g"))
235
- col = col + element.g.toString(16).padStart(2, '0');
236
- else col = col + '00';
237
- if (element && element.hasOwnProperty("b"))
238
- col = col + element.b.toString(16).padStart(2, '0');
239
- else col = col + '00';
240
- return col;
241
- }
242
-
243
-
244
- function hsvToRGBString(h,s,v) {
245
- return rgb_to_rgbstring(hsvToRGB(h,s,v))
246
- }
247
-
248
- exports.hsv_to_cie = hsv_to_cie;
249
- exports.rgb_to_cie = rgb_to_cie;
250
- exports.cie_to_rgb = cie_to_rgb;
251
- exports.hsvToRGB = hsvToRGB;
252
- exports.rgbToHSV = rgbToHSV;
253
- exports.colorArrayFromString = colorArrayFromString;
254
- exports.colorStringFromRGBArray = colorStringFromRGBArray;
255
- exports.hsvToRGBString = hsvToRGBString;
1
+ /*
2
+ With these functions you can convert the CIE color space to the RGB color space and vice versa.
3
+
4
+ The developer documentation for Philips Hue provides the formulas used in the code below:
5
+ https://developers.meethue.com/documentation/color-conversions-rgb-xy
6
+
7
+ I've used the formulas and Objective-C example code and transfered it to JavaScript.
8
+
9
+
10
+ Examples:
11
+
12
+ const rgb = cie_to_rgb(0.6611, 0.2936)
13
+ const cie = rgb_to_cie(255, 39, 60)
14
+
15
+ ------------------------------------------------------------------------------------
16
+
17
+ The MIT License (MIT)
18
+
19
+ Copyright (c) 2017 www.usolved.net
20
+ Published under https://github.com/usolved/cie-rgb-converter
21
+
22
+ Permission is hereby granted, free of charge, to any person obtaining a copy
23
+ of this software and associated documentation files (the "Software"), to deal
24
+ in the Software without restriction, including without limitation the rights
25
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
+ copies of the Software, and to permit persons to whom the Software is
27
+ furnished to do so, subject to the following conditions:
28
+
29
+ The above copyright notice and this permission notice shall be included in
30
+ all copies or substantial portions of the Software.
31
+
32
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38
+ THE SOFTWARE.
39
+ */
40
+ 'use strict';
41
+
42
+ const colors = require('./colors.js');
43
+
44
+ /**
45
+ * Converts CIE color space to RGB color space
46
+ * @param {Number} x
47
+ * @param {Number} y
48
+ * @param {Number} brightness - Ranges from 1 to 254
49
+ * @return {Array} Array that contains the color values for red, green and blue
50
+ */
51
+ function cie_to_rgb(x, y, brightness) {
52
+ //Set to maximum brightness if no custom value was given (Not the slick ECMAScript 6 way for compatibility reasons)
53
+ if (brightness === undefined) {
54
+ brightness = 254;
55
+ }
56
+
57
+ const z = 1.0 - x - y;
58
+ const Y = (brightness / 254).toFixed(2);
59
+ const X = (Y / y) * x;
60
+ const Z = (Y / y) * z;
61
+
62
+ //Convert to RGB using Wide RGB D65 conversion
63
+ let red = X * 1.656492 - Y * 0.354851 - Z * 0.255038;
64
+ let green = -X * 0.707196 + Y * 1.655397 + Z * 0.036152;
65
+ let blue = X * 0.051713 - Y * 0.121364 + Z * 1.011530;
66
+
67
+ //If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
68
+ if (red > blue && red > green && red > 1.0) {
69
+
70
+ green = green / red;
71
+ blue = blue / red;
72
+ red = 1.0;
73
+ }
74
+ else if (green > blue && green > red && green > 1.0) {
75
+
76
+ red = red / green;
77
+ blue = blue / green;
78
+ green = 1.0;
79
+ }
80
+ else if (blue > red && blue > green && blue > 1.0) {
81
+
82
+ red = red / blue;
83
+ green = green / blue;
84
+ blue = 1.0;
85
+ }
86
+
87
+ //Reverse gamma correction
88
+ red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, (1.0 / 2.4)) - 0.055;
89
+ green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, (1.0 / 2.4)) - 0.055;
90
+ blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, (1.0 / 2.4)) - 0.055;
91
+
92
+
93
+ //Convert normalized decimal to decimal
94
+ red = Math.round(red * 255);
95
+ green = Math.round(green * 255);
96
+ blue = Math.round(blue * 255);
97
+
98
+ if (isNaN(red) || red < 0 ) {
99
+ red = 0;
100
+ }
101
+
102
+ if (isNaN(green) || green < 0 ) {
103
+ green = 0;
104
+ }
105
+
106
+ if (isNaN(blue) || blue < 0 ) {
107
+ blue = 0;
108
+ }
109
+
110
+ return [red, green, blue];
111
+ }
112
+
113
+
114
+ /**
115
+ * Converts RGB color space to CIE color space
116
+ * @param {Number} red
117
+ * @param {Number} green
118
+ * @param {Number} blue
119
+ * @return {Array} Array that contains the CIE color values for x and y
120
+ */
121
+ function rgb_to_cie(red, green, blue) {
122
+ // Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device
123
+ red = (red > 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red / 12.92);
124
+ green = (green > 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : (green / 12.92);
125
+ blue = (blue > 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : (blue / 12.92);
126
+
127
+ // RGB values to XYZ using the Wide RGB D65 conversion formula
128
+ const X = red * 0.664511 + green * 0.154324 + blue * 0.162028;
129
+ const Y = red * 0.283881 + green * 0.668433 + blue * 0.047685;
130
+ const Z = red * 0.000088 + green * 0.072310 + blue * 0.986039;
131
+
132
+ // Calculate the xy values from the XYZ values
133
+ let x = (X / (X + Y + Z)).toFixed(4);
134
+ let y = (Y / (X + Y + Z)).toFixed(4);
135
+
136
+ if (isNaN(x)) {
137
+ x = 0;
138
+ }
139
+
140
+ if (isNaN(y)) {
141
+ y = 0;
142
+ }
143
+
144
+ return [x, y];
145
+ }
146
+
147
+
148
+ function hsvToRGB(h, s, v) {
149
+ h = h % 360 / 360;
150
+ s = s / 100;
151
+ v = v / 100;
152
+
153
+ let r; let g; let b;
154
+ if (arguments.length === 1) {
155
+ s = h.s, v = h.v, h = h.h;
156
+ }
157
+ const i = Math.floor(h * 6);
158
+ const f = h * 6 - i;
159
+ const p = v * (1 - s);
160
+ const q = v * (1 - f * s);
161
+ const t = v * (1 - (1 - f) * s);
162
+ switch (i % 6) {
163
+ case 0: r = v, g = t, b = p; break;
164
+ case 1: r = q, g = v, b = p; break;
165
+ case 2: r = p, g = v, b = t; break;
166
+ case 3: r = p, g = q, b = v; break;
167
+ case 4: r = t, g = p, b = v; break;
168
+ case 5: r = v, g = p, b = q; break;
169
+ }
170
+ return {
171
+ r: Math.round(r * 255),
172
+ g: Math.round(g * 255),
173
+ b: Math.round(b * 255),
174
+ };
175
+ }
176
+
177
+ function rgbToHSV(r, g, b, numeric) {
178
+ if (arguments.length === 1) {
179
+ g = r.g, b = r.b, r = r.r;
180
+ }
181
+ const max = Math.max(r, g, b); const min = Math.min(r, g, b);
182
+ const d = max - min;
183
+ let h;
184
+ const s = (max === 0 ? 0 : d / max);
185
+ const v = max / 255;
186
+
187
+ switch (max) {
188
+ case min: h = 0; break;
189
+ case r: h = (g - b) + d * (g < b ? 6: 0); h /= 6 * d; break;
190
+ case g: h = (b - r) + d * 2; h /= 6 * d; break;
191
+ case b: h = (r - g) + d * 4; h /= 6 * d; break;
192
+ }
193
+ if (numeric) return {
194
+ h: Math.round(h*360),
195
+ s: Math.round(s*100),
196
+ v: Math.round(v*100),
197
+ };
198
+ return {
199
+ h: (h * 360).toFixed(3),
200
+ s: (s * 100).toFixed(3),
201
+ v: (v * 100).toFixed(3),
202
+ };
203
+ }
204
+ function colorArrayFromString(value) {
205
+ if (typeof(value) === 'string') {
206
+ const rv = [];
207
+ value.split(',').forEach(element => {
208
+ rv.push(colors.ParseColor(element));
209
+ });
210
+ return rv;
211
+ }
212
+ return [{r:0,g:128,b:255}];
213
+ }
214
+
215
+ function colorStringFromRGBArray(payload)
216
+ {
217
+ let rv = []
218
+ payload.forEach(element => {
219
+ rv.push(rgb_to_rgbstring(element));
220
+ });
221
+ return rv.toString();
222
+ }
223
+
224
+ function hsv_to_cie(h,s,v){
225
+ const rgb = hsvToRGB(h,s,v);
226
+ return rgb_to_cie(rgb.r, rgb.g, rgb.b);
227
+ }
228
+
229
+ function rgb_to_rgbstring(element) {
230
+ let col = '#';
231
+ if (element && element.hasOwnProperty("r"))
232
+ col = col + element.r.toString(16).padStart(2, '0');
233
+ else col = col + '00';
234
+ if (element && element.hasOwnProperty("g"))
235
+ col = col + element.g.toString(16).padStart(2, '0');
236
+ else col = col + '00';
237
+ if (element && element.hasOwnProperty("b"))
238
+ col = col + element.b.toString(16).padStart(2, '0');
239
+ else col = col + '00';
240
+ return col;
241
+ }
242
+
243
+
244
+ function hsvToRGBString(h,s,v) {
245
+ return rgb_to_rgbstring(hsvToRGB(h,s,v))
246
+ }
247
+
248
+ exports.hsv_to_cie = hsv_to_cie;
249
+ exports.rgb_to_cie = rgb_to_cie;
250
+ exports.cie_to_rgb = cie_to_rgb;
251
+ exports.hsvToRGB = hsvToRGB;
252
+ exports.rgbToHSV = rgbToHSV;
253
+ exports.colorArrayFromString = colorArrayFromString;
254
+ exports.colorStringFromRGBArray = colorStringFromRGBArray;
255
+ exports.hsvToRGBString = hsvToRGBString;
package/lib/seriallist.js CHANGED
@@ -1,37 +1,37 @@
1
- 'use strict';
2
-
3
- const serialPortUtils = require('zigbee-herdsman/dist/adapter/serialPortUtils').default;
4
-
5
-
6
- class SerialList {
7
- constructor(adapter) {
8
- this.adapter = adapter;
9
- this.adapter.on('message', this.onMessage.bind(this));
10
- }
11
- /**
12
- * @param {ioBroker.Message} obj
13
- */
14
- onMessage(obj) {
15
- if (typeof obj === 'object' && obj.command) {
16
- switch (obj.command) {
17
- case 'listUart':
18
- if (obj.callback) {
19
- this.listSerial()
20
- .then((ports) => {
21
- this.adapter.log.debug('List of ports: ' + JSON.stringify(ports));
22
- this.adapter.sendTo(obj.from, obj.command, ports, obj.callback);
23
- });
24
- }
25
- break;
26
- }
27
- }
28
- }
29
-
30
- listSerial() {
31
- return serialPortUtils.find([{}]).then((ports) => {
32
- return ports.map((port) => {return {comName: port};});
33
- });
34
- }
35
- }
36
-
37
- module.exports = SerialList;
1
+ 'use strict';
2
+
3
+ const serialPortUtils = require('zigbee-herdsman/dist/adapter/serialPortUtils').default;
4
+
5
+
6
+ class SerialList {
7
+ constructor(adapter) {
8
+ this.adapter = adapter;
9
+ this.adapter.on('message', this.onMessage.bind(this));
10
+ }
11
+ /**
12
+ * @param {ioBroker.Message} obj
13
+ */
14
+ onMessage(obj) {
15
+ if (typeof obj === 'object' && obj.command) {
16
+ switch (obj.command) {
17
+ case 'listUart':
18
+ if (obj.callback) {
19
+ this.listSerial()
20
+ .then((ports) => {
21
+ this.adapter.log.debug('List of ports: ' + JSON.stringify(ports));
22
+ this.adapter.sendTo(obj.from, obj.command, ports, obj.callback);
23
+ });
24
+ }
25
+ break;
26
+ }
27
+ }
28
+ }
29
+
30
+ listSerial() {
31
+ return serialPortUtils.find([{}]).then((ports) => {
32
+ return ports.map((port) => {return {comName: port};});
33
+ });
34
+ }
35
+ }
36
+
37
+ module.exports = SerialList;