iobroker.zigbee 1.7.6 → 1.8.0

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