iobroker.zigbee 1.7.5 → 1.7.6

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 (85) 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 +382 -376
  9. package/admin/adapter-settings.js +244 -244
  10. package/admin/admin.js +2927 -2926
  11. package/admin/img/philips_hue_lom001.png +0 -0
  12. package/admin/index.html +159 -159
  13. package/admin/index_m.html +1161 -1161
  14. package/admin/moment.min.js +1 -1
  15. package/admin/shuffle.min.js +2 -2
  16. package/admin/tab_m.html +944 -944
  17. package/admin/vis-network.min.css +1 -1
  18. package/admin/vis-network.min.js +27 -27
  19. package/admin/words.js +111 -112
  20. package/io-package.json +370 -366
  21. package/lib/backup.js +171 -171
  22. package/lib/binding.js +325 -325
  23. package/lib/colors.js +460 -460
  24. package/lib/commands.js +501 -501
  25. package/lib/developer.js +148 -148
  26. package/lib/devices.js +3145 -3145
  27. package/lib/exclude.js +168 -168
  28. package/lib/exposes.js +804 -804
  29. package/lib/groups.js +342 -342
  30. package/lib/json.js +60 -60
  31. package/lib/networkmap.js +56 -56
  32. package/lib/ota.js +179 -179
  33. package/lib/rgb.js +255 -255
  34. package/lib/seriallist.js +37 -37
  35. package/lib/states.js +6416 -6416
  36. package/lib/statescontroller.js +670 -670
  37. package/lib/tools.js +54 -54
  38. package/lib/utils.js +151 -151
  39. package/lib/zbBaseExtension.js +36 -36
  40. package/lib/zbDelayedAction.js +152 -152
  41. package/lib/zbDeviceAvailability.js +315 -315
  42. package/lib/zbDeviceConfigure.js +159 -152
  43. package/lib/zbDeviceEvent.js +49 -49
  44. package/lib/zigbeecontroller.js +951 -946
  45. package/package.json +3 -3
  46. package/support/docgen.js +93 -93
  47. package/docs/de/img/CC2531.png +0 -0
  48. package/docs/de/img/CC2538_CC2592_PA.PNG +0 -0
  49. package/docs/de/img/CC2591.png +0 -0
  50. package/docs/de/img/boards.jpg +0 -0
  51. package/docs/de/img/cc26x2r.PNG +0 -0
  52. package/docs/de/img/results.jpg +0 -0
  53. package/docs/de/img/sku_429478_2.png +0 -0
  54. package/docs/de/img/sku_429601_2.png +0 -0
  55. package/docs/de/readme.md +0 -27
  56. package/docs/en/img/CC2531.png +0 -0
  57. package/docs/en/img/CC2591.png +0 -0
  58. package/docs/en/img/deconz.png +0 -0
  59. package/docs/en/img/sku_429478_2.png +0 -0
  60. package/docs/en/img/sku_429601_2.png +0 -0
  61. package/docs/en/readme.md +0 -30
  62. package/docs/flashing_via_arduino_(en).md +0 -110
  63. package/docs/ru/img/CC2531.png +0 -0
  64. package/docs/ru/img/CC2591.png +0 -0
  65. package/docs/ru/img/sku_429478_2.png +0 -0
  66. package/docs/ru/img/sku_429601_2.png +0 -0
  67. package/docs/ru/readme.md +0 -28
  68. package/docs/tutorial/CC2530_20190425.zip +0 -0
  69. package/docs/tutorial/CC2530_CC2591_20190515.zip +0 -0
  70. package/docs/tutorial/CC2530_CC2592_20190515.zip +0 -0
  71. package/docs/tutorial/CC2531_20190425.zip +0 -0
  72. package/docs/tutorial/adm5_1.PNG +0 -0
  73. package/docs/tutorial/adm5_2.PNG +0 -0
  74. package/docs/tutorial/cat.PNG +0 -0
  75. package/docs/tutorial/groups-1.png +0 -0
  76. package/docs/tutorial/groups-2.png +0 -0
  77. package/docs/tutorial/inst.PNG +0 -0
  78. package/docs/tutorial/reflash-finish.PNG +0 -0
  79. package/docs/tutorial/reflash-step0.png +0 -0
  80. package/docs/tutorial/reflash-step1.PNG +0 -0
  81. package/docs/tutorial/reflash-step2.PNG +0 -0
  82. package/docs/tutorial/settings.png +0 -0
  83. package/docs/tutorial/tab-dev-1.png +0 -0
  84. package/docs/tutorial/zigbee.png +0 -0
  85. package/docs/tutorial/zigbee15.png +0 -0
package/lib/json.js CHANGED
@@ -1,61 +1,61 @@
1
- 'use strict';
2
-
3
- const hasProp = Object.prototype.hasOwnProperty;
4
-
5
- function throwsMessage(err) {
6
- return '[Throws: ' + (err ? err.message : '?') + ']';
7
- }
8
-
9
- function safeGetValueFromPropertyOnObject(obj, property) {
10
- if (hasProp.call(obj, property)) {
11
- try {
12
- return obj[property];
13
- }
14
- catch (err) {
15
- return throwsMessage(err);
16
- }
17
- }
18
-
19
- return obj[property];
20
- }
21
-
22
- function ensureProperties(obj) {
23
- const seen = [ ]; // store references to objects we have seen before
24
-
25
- function visit(obj) {
26
- if (obj === null || typeof obj !== 'object') {
27
- return obj;
28
- }
29
-
30
- if (seen.indexOf(obj) !== -1) {
31
- return '[Circular]';
32
- }
33
- seen.push(obj);
34
-
35
- if (typeof obj.toJSON === 'function') {
36
- try {
37
- return visit(obj.toJSON());
38
- } catch(err) {
39
- return throwsMessage(err);
40
- }
41
- }
42
-
43
- if (Array.isArray(obj)) {
44
- return obj.map(visit);
45
- }
46
-
47
- return Object.keys(obj).reduce((result, prop) => {
48
- // prevent faulty defined getter properties
49
- result[prop] = visit(safeGetValueFromPropertyOnObject(obj, prop));
50
- return result;
51
- }, {});
52
- }
53
-
54
- return visit(obj);
55
- }
56
-
57
- module.exports = function (data, replacer, space) {
58
- return JSON.stringify(ensureProperties(data), replacer, space);
59
- };
60
-
1
+ 'use strict';
2
+
3
+ const hasProp = Object.prototype.hasOwnProperty;
4
+
5
+ function throwsMessage(err) {
6
+ return '[Throws: ' + (err ? err.message : '?') + ']';
7
+ }
8
+
9
+ function safeGetValueFromPropertyOnObject(obj, property) {
10
+ if (hasProp.call(obj, property)) {
11
+ try {
12
+ return obj[property];
13
+ }
14
+ catch (err) {
15
+ return throwsMessage(err);
16
+ }
17
+ }
18
+
19
+ return obj[property];
20
+ }
21
+
22
+ function ensureProperties(obj) {
23
+ const seen = [ ]; // store references to objects we have seen before
24
+
25
+ function visit(obj) {
26
+ if (obj === null || typeof obj !== 'object') {
27
+ return obj;
28
+ }
29
+
30
+ if (seen.indexOf(obj) !== -1) {
31
+ return '[Circular]';
32
+ }
33
+ seen.push(obj);
34
+
35
+ if (typeof obj.toJSON === 'function') {
36
+ try {
37
+ return visit(obj.toJSON());
38
+ } catch(err) {
39
+ return throwsMessage(err);
40
+ }
41
+ }
42
+
43
+ if (Array.isArray(obj)) {
44
+ return obj.map(visit);
45
+ }
46
+
47
+ return Object.keys(obj).reduce((result, prop) => {
48
+ // prevent faulty defined getter properties
49
+ result[prop] = visit(safeGetValueFromPropertyOnObject(obj, prop));
50
+ return result;
51
+ }, {});
52
+ }
53
+
54
+ return visit(obj);
55
+ }
56
+
57
+ module.exports = function (data, replacer, space) {
58
+ return JSON.stringify(ensureProperties(data), replacer, space);
59
+ };
60
+
61
61
  module.exports.ensureProperties = ensureProperties;
package/lib/networkmap.js CHANGED
@@ -1,57 +1,57 @@
1
- 'use strict';
2
-
3
-
4
- class NetworkMap {
5
- constructor(adapter) {
6
- this.adapter = adapter;
7
- this.adapter.on('message', this.onMessage.bind(this));
8
- }
9
-
10
- start(zbController, stController) {
11
- this.zbController = zbController;
12
- this.stController = stController;
13
- }
14
-
15
- stop() {
16
- delete this.zbController;
17
- delete this.stController;
18
- }
19
-
20
- info(msg) {
21
- this.adapter.log.info(msg);
22
- }
23
-
24
- error(msg) {
25
- this.adapter.log.error(msg);
26
- }
27
-
28
- debug(msg) {
29
- this.adapter.log.debug(msg);
30
- }
31
-
32
- /**
33
- * @param {ioBroker.Message} obj
34
- */
35
- onMessage(obj) {
36
- if (typeof obj === 'object' && obj.command) {
37
- switch (obj.command) {
38
- case 'getMap':
39
- if (obj && obj.message && typeof obj.message === 'object') {
40
- this.getMap(obj.from, obj.command, obj.callback);
41
- }
42
- break;
43
- }
44
- }
45
- }
46
-
47
- getMap(from, command, callback) {
48
- if (this.zbController) {
49
- this.zbController.getMap((networkmap) => {
50
- this.adapter.log.debug('getMap result: ' + JSON.stringify(networkmap));
51
- this.adapter.sendTo(from, command, networkmap, callback);
52
- });
53
- }
54
- }
55
- }
56
-
1
+ 'use strict';
2
+
3
+
4
+ class NetworkMap {
5
+ constructor(adapter) {
6
+ this.adapter = adapter;
7
+ this.adapter.on('message', this.onMessage.bind(this));
8
+ }
9
+
10
+ start(zbController, stController) {
11
+ this.zbController = zbController;
12
+ this.stController = stController;
13
+ }
14
+
15
+ stop() {
16
+ delete this.zbController;
17
+ delete this.stController;
18
+ }
19
+
20
+ info(msg) {
21
+ this.adapter.log.info(msg);
22
+ }
23
+
24
+ error(msg) {
25
+ this.adapter.log.error(msg);
26
+ }
27
+
28
+ debug(msg) {
29
+ this.adapter.log.debug(msg);
30
+ }
31
+
32
+ /**
33
+ * @param {ioBroker.Message} obj
34
+ */
35
+ onMessage(obj) {
36
+ if (typeof obj === 'object' && obj.command) {
37
+ switch (obj.command) {
38
+ case 'getMap':
39
+ if (obj && obj.message && typeof obj.message === 'object') {
40
+ this.getMap(obj.from, obj.command, obj.callback);
41
+ }
42
+ break;
43
+ }
44
+ }
45
+ }
46
+
47
+ getMap(from, command, callback) {
48
+ if (this.zbController) {
49
+ this.zbController.getMap((networkmap) => {
50
+ this.adapter.log.debug('getMap result: ' + JSON.stringify(networkmap));
51
+ this.adapter.sendTo(from, command, networkmap, callback);
52
+ });
53
+ }
54
+ }
55
+ }
56
+
57
57
  module.exports = NetworkMap;
package/lib/ota.js CHANGED
@@ -1,179 +1,179 @@
1
- 'use strict';
2
-
3
- const getZbId = require('./utils').getZbId;
4
-
5
- class Ota {
6
- constructor(adapter) {
7
- this.adapter = adapter;
8
- this.adapter.on('message', this.onMessage.bind(this));
9
- this.inProgress = new Set();
10
- }
11
-
12
- start(zbController, stController) {
13
- this.zbController = zbController;
14
- this.stController = stController;
15
- }
16
-
17
- stop() {
18
- delete this.zbController;
19
- delete this.stController;
20
- }
21
-
22
- info(msg) {
23
- this.adapter.log.info(msg);
24
- }
25
-
26
- warn(msg) {
27
- this.adapter.log.info(msg);
28
- }
29
-
30
- error(msg) {
31
- this.adapter.log.error(msg);
32
- }
33
-
34
- debug(msg) {
35
- this.adapter.log.debug(msg);
36
- }
37
-
38
- /**
39
- * @param {ioBroker.Message} obj
40
- */
41
- onMessage(obj) {
42
- if (typeof obj === 'object' && obj.command) {
43
- switch (obj.command) {
44
- case 'checkOtaAvail':
45
- this.checkOtaAvail(obj);
46
- break;
47
- case 'startOta':
48
- this.startOta(obj);
49
- break;
50
- }
51
- }
52
- }
53
-
54
- async checkOtaAvail(obj) {
55
- const device = await this.getDeviceForMessage(obj);
56
- if (!device) {
57
- this.debug(`Device ${obj.message.devId} is unavailable`);
58
- this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is unavailable'}, obj.callback);
59
- return;
60
- }
61
- if (this.inProgress.has(device.device.ieeeAddr)) {
62
- this.warn(`Update or check already in progress for '${device.name}', skipping...`);
63
- return;
64
- }
65
- // do not attempt update for a device which has been deactivated or is unavailable
66
- const stateObj = await this.adapter.getObjectAsync(obj.message.devId);
67
- if (stateObj && stateObj.common && stateObj.common.deactivated) {
68
- this.warn(`Device ${obj.message.devId} is deactivated, skipping...`);
69
- this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is deactivated'}, obj.callback);
70
- return;
71
- }
72
- const availablestate = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.available');
73
- const lqi = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.link_quality');
74
- if ((availablestate && (!availablestate.val)) || (lqi && lqi.val < 1)) {
75
- this.warn(`Device ${obj.message.devId} is marked unavailable, skipping...`);
76
- this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is marked unavailable'}, obj.callback);
77
- return;
78
- }
79
- this.inProgress.add(device.device.ieeeAddr);
80
- const result = {status: 'unknown', device: device ? device.name : null};
81
- try {
82
- this.debug(`Checking if firmware update is available for ${device.name}`);
83
-
84
- if (device && device.mapped.ota) {
85
- const available = await device.mapped.ota.isUpdateAvailable(device.device, this);
86
- result.status = available ? 'available' : 'not_available';
87
- } else {
88
- result.status = 'not_supported';
89
- }
90
- this.debug(`Firmware update for ${device.name} is ${result.status}`);
91
- this.adapter.sendTo(obj.from, obj.command, result, obj.callback);
92
- } catch (error) {
93
- const message = `Failed to check if update available for '${device.name}' (${error.message})`;
94
- result.status = 'fail';
95
- result.msg = message;
96
- this.warn(message);
97
- this.adapter.sendTo(obj.from, obj.command, result, obj.callback);
98
- }
99
- this.inProgress.delete(device.device.ieeeAddr);
100
- }
101
-
102
- async startOta(obj) {
103
- const device = await this.getDeviceForMessage(obj);
104
- if (!device) {
105
- this.debug(`Device ${obj.message.devId} is unavailable`);
106
- this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is unavailable'}, obj.callback);
107
- return;
108
- }
109
- if (this.inProgress.has(device.device.ieeeAddr)) {
110
- this.error(`Update or check already in progress for '${device.name}', skipping...`);
111
- return;
112
- }
113
- // do not attempt update for a device which has been deactivated or is unavailable
114
- const stateObj = await this.adapter.getObjectAsync(obj.message.devId);
115
- if (stateObj && stateObj.common && stateObj.common.deactivated) {
116
- this.warn(`Device ${obj.message.devId} is deactivated, skipping...`);
117
- return;
118
- }
119
- const availablestate = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.available');
120
- const lqi = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.link_quality');
121
- if ((availablestate && (!availablestate.val)) || (lqi && lqi.val < 1)) {
122
- this.warn(`Device ${obj.message.devId} is marked unavailable, skipping...`);
123
- return;
124
- }
125
- this.inProgress.add(device.device.ieeeAddr);
126
- const result = {status: 'unknown', device: device ? device.name : null};
127
- try {
128
- this.info('Start firmware update for '+device.name);
129
-
130
- const onProgress = (progress, remaining) => {
131
- let message = `Update of '${device.name}' at ${progress}%`;
132
- if (remaining) {
133
- message += `, +- ${Math.round(remaining / 60)} minutes remaining`;
134
- }
135
- this.info(message);
136
- };
137
-
138
- const from_ = await this.readSoftwareBuildIDAndDateCode(device.device, false);
139
- await device.mapped.ota.updateToLatest(device.device, this, onProgress);
140
- const to = await this.readSoftwareBuildIDAndDateCode(device.device, true);
141
- const [fromS, toS] = [JSON.stringify(from_), JSON.stringify(to)];
142
- result.status = 'success';
143
- result.msg = `Finished update of '${device.name}'` + (to ? `, from '${fromS}' to '${toS}'` : ``);
144
- this.info(result.msg);
145
- this.adapter.sendTo(obj.from, obj.command, result, obj.callback);
146
- } catch (error) {
147
- const message = `Update of '${device.name}' failed (${error.message})`;
148
- result.status = 'fail';
149
- result.msg = message;
150
- this.error(message);
151
- this.adapter.sendTo(obj.from, obj.command, result, obj.callback);
152
- }
153
- this.inProgress.delete(device.device.ieeeAddr);
154
- }
155
-
156
- async readSoftwareBuildIDAndDateCode(device, update) {
157
- try {
158
- const endpoint = device.endpoints.find((e) => e.supportsInputCluster('genBasic'));
159
- const result = await endpoint.read('genBasic', ['dateCode', 'swBuildId']);
160
-
161
- if (update) {
162
- device.softwareBuildID = result.swBuildId;
163
- device.dateCode = result.dateCode;
164
- device.save();
165
- }
166
-
167
- return {softwareBuildID: result.swBuildId, dateCode: result.dateCode};
168
- } catch (e) {
169
- return null;
170
- }
171
- }
172
-
173
- async getDeviceForMessage(obj) {
174
- const devId = getZbId(obj.message.devId);
175
- return this.zbController.resolveEntity(devId);
176
- }
177
- }
178
-
179
- module.exports = Ota;
1
+ 'use strict';
2
+
3
+ const getZbId = require('./utils').getZbId;
4
+
5
+ class Ota {
6
+ constructor(adapter) {
7
+ this.adapter = adapter;
8
+ this.adapter.on('message', this.onMessage.bind(this));
9
+ this.inProgress = new Set();
10
+ }
11
+
12
+ start(zbController, stController) {
13
+ this.zbController = zbController;
14
+ this.stController = stController;
15
+ }
16
+
17
+ stop() {
18
+ delete this.zbController;
19
+ delete this.stController;
20
+ }
21
+
22
+ info(msg) {
23
+ this.adapter.log.info(msg);
24
+ }
25
+
26
+ warn(msg) {
27
+ this.adapter.log.info(msg);
28
+ }
29
+
30
+ error(msg) {
31
+ this.adapter.log.error(msg);
32
+ }
33
+
34
+ debug(msg) {
35
+ this.adapter.log.debug(msg);
36
+ }
37
+
38
+ /**
39
+ * @param {ioBroker.Message} obj
40
+ */
41
+ onMessage(obj) {
42
+ if (typeof obj === 'object' && obj.command) {
43
+ switch (obj.command) {
44
+ case 'checkOtaAvail':
45
+ this.checkOtaAvail(obj);
46
+ break;
47
+ case 'startOta':
48
+ this.startOta(obj);
49
+ break;
50
+ }
51
+ }
52
+ }
53
+
54
+ async checkOtaAvail(obj) {
55
+ const device = await this.getDeviceForMessage(obj);
56
+ if (!device) {
57
+ this.debug(`Device ${obj.message.devId} is unavailable`);
58
+ this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is unavailable'}, obj.callback);
59
+ return;
60
+ }
61
+ if (this.inProgress.has(device.device.ieeeAddr)) {
62
+ this.warn(`Update or check already in progress for '${device.name}', skipping...`);
63
+ return;
64
+ }
65
+ // do not attempt update for a device which has been deactivated or is unavailable
66
+ const stateObj = await this.adapter.getObjectAsync(obj.message.devId);
67
+ if (stateObj && stateObj.common && stateObj.common.deactivated) {
68
+ this.warn(`Device ${obj.message.devId} is deactivated, skipping...`);
69
+ this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is deactivated'}, obj.callback);
70
+ return;
71
+ }
72
+ const availablestate = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.available');
73
+ const lqi = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.link_quality');
74
+ if ((availablestate && (!availablestate.val)) || (lqi && lqi.val < 1)) {
75
+ this.warn(`Device ${obj.message.devId} is marked unavailable, skipping...`);
76
+ this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is marked unavailable'}, obj.callback);
77
+ return;
78
+ }
79
+ this.inProgress.add(device.device.ieeeAddr);
80
+ const result = {status: 'unknown', device: device ? device.name : null};
81
+ try {
82
+ this.debug(`Checking if firmware update is available for ${device.name}`);
83
+
84
+ if (device && device.mapped.ota) {
85
+ const available = await device.mapped.ota.isUpdateAvailable(device.device, this);
86
+ result.status = available ? 'available' : 'not_available';
87
+ } else {
88
+ result.status = 'not_supported';
89
+ }
90
+ this.debug(`Firmware update for ${device.name} is ${result.status}`);
91
+ this.adapter.sendTo(obj.from, obj.command, result, obj.callback);
92
+ } catch (error) {
93
+ const message = `Failed to check if update available for '${device.name}' (${error.message})`;
94
+ result.status = 'fail';
95
+ result.msg = message;
96
+ this.warn(message);
97
+ this.adapter.sendTo(obj.from, obj.command, result, obj.callback);
98
+ }
99
+ this.inProgress.delete(device.device.ieeeAddr);
100
+ }
101
+
102
+ async startOta(obj) {
103
+ const device = await this.getDeviceForMessage(obj);
104
+ if (!device) {
105
+ this.debug(`Device ${obj.message.devId} is unavailable`);
106
+ this.adapter.sendTo(obj.from, obj.command, {status: 'fail', device: getZbId(obj.message.devId), msg: 'Device is unavailable'}, obj.callback);
107
+ return;
108
+ }
109
+ if (this.inProgress.has(device.device.ieeeAddr)) {
110
+ this.error(`Update or check already in progress for '${device.name}', skipping...`);
111
+ return;
112
+ }
113
+ // do not attempt update for a device which has been deactivated or is unavailable
114
+ const stateObj = await this.adapter.getObjectAsync(obj.message.devId);
115
+ if (stateObj && stateObj.common && stateObj.common.deactivated) {
116
+ this.warn(`Device ${obj.message.devId} is deactivated, skipping...`);
117
+ return;
118
+ }
119
+ const availablestate = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.available');
120
+ const lqi = await this.adapter.getStateAsync(obj.message.devId.replace(this.namespace + '.', '') + '.link_quality');
121
+ if ((availablestate && (!availablestate.val)) || (lqi && lqi.val < 1)) {
122
+ this.warn(`Device ${obj.message.devId} is marked unavailable, skipping...`);
123
+ return;
124
+ }
125
+ this.inProgress.add(device.device.ieeeAddr);
126
+ const result = {status: 'unknown', device: device ? device.name : null};
127
+ try {
128
+ this.info('Start firmware update for '+device.name);
129
+
130
+ const onProgress = (progress, remaining) => {
131
+ let message = `Update of '${device.name}' at ${progress}%`;
132
+ if (remaining) {
133
+ message += `, +- ${Math.round(remaining / 60)} minutes remaining`;
134
+ }
135
+ this.info(message);
136
+ };
137
+
138
+ const from_ = await this.readSoftwareBuildIDAndDateCode(device.device, false);
139
+ await device.mapped.ota.updateToLatest(device.device, this, onProgress);
140
+ const to = await this.readSoftwareBuildIDAndDateCode(device.device, true);
141
+ const [fromS, toS] = [JSON.stringify(from_), JSON.stringify(to)];
142
+ result.status = 'success';
143
+ result.msg = `Finished update of '${device.name}'` + (to ? `, from '${fromS}' to '${toS}'` : ``);
144
+ this.info(result.msg);
145
+ this.adapter.sendTo(obj.from, obj.command, result, obj.callback);
146
+ } catch (error) {
147
+ const message = `Update of '${device.name}' failed (${error.message})`;
148
+ result.status = 'fail';
149
+ result.msg = message;
150
+ this.error(message);
151
+ this.adapter.sendTo(obj.from, obj.command, result, obj.callback);
152
+ }
153
+ this.inProgress.delete(device.device.ieeeAddr);
154
+ }
155
+
156
+ async readSoftwareBuildIDAndDateCode(device, update) {
157
+ try {
158
+ const endpoint = device.endpoints.find((e) => e.supportsInputCluster('genBasic'));
159
+ const result = await endpoint.read('genBasic', ['dateCode', 'swBuildId']);
160
+
161
+ if (update) {
162
+ device.softwareBuildID = result.swBuildId;
163
+ device.dateCode = result.dateCode;
164
+ device.save();
165
+ }
166
+
167
+ return {softwareBuildID: result.swBuildId, dateCode: result.dateCode};
168
+ } catch (e) {
169
+ return null;
170
+ }
171
+ }
172
+
173
+ async getDeviceForMessage(obj) {
174
+ const devId = getZbId(obj.message.devId);
175
+ return this.zbController.resolveEntity(devId);
176
+ }
177
+ }
178
+
179
+ module.exports = Ota;