iobroker.zigbee2mqtt 2.7.1 → 2.7.3

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/README.md CHANGED
@@ -32,6 +32,14 @@ This adapter allows to control the data points of the devices of a Zigbee2MQTT i
32
32
  Placeholder for the next version (at the beginning of the line):
33
33
  ### **WORK IN PROGRESS**
34
34
  -->
35
+ ### 2.7.3 (2023-02-18)
36
+
37
+ - (o0shojo0o) hotfix for Aqara presence detector FP1
38
+
39
+ ### 2.7.2 (2023-02-01)
40
+
41
+ - (o0shojo0o) rework of the detection of removed devices
42
+
35
43
  ### 2.7.1 (2023-01-24)
36
44
 
37
45
  - (o0shojo0o) added option for use folder description
@@ -25,5 +25,6 @@
25
25
  "Proxy Zigbee2MQTT logs to ioBroker logs": "Proxy Zigbee2MQTT logs to ioBroker logs",
26
26
  "Brightness move should also turn the light on or off": "Brightness move should also turn the light on or off",
27
27
  "Brightness step should also turn the light on or off": "Brightness step should also turn the light on or off",
28
- "The events such as 'Device removed' or 'Disabled' are displayed in the description instead of in the name.": "The events such as 'Device removed' or 'Disabled' are displayed in the description instead of in the name."
28
+ "The events such as 'Device removed' or 'Disabled' are displayed in the description instead of in the name.": "The events such as 'Device removed' or 'Disabled' are displayed in the description instead of in the name.",
29
+ "Scheme": "Scheme"
29
30
  }
@@ -108,6 +108,7 @@
108
108
  },
109
109
  "webUIScheme": {
110
110
  "type": "select",
111
+ "label": "Scheme",
111
112
  "options": [
112
113
  {
113
114
  "label": "HTTP",
package/io-package.json CHANGED
@@ -1,8 +1,34 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "zigbee2mqtt",
4
- "version": "2.7.1",
4
+ "version": "2.7.3",
5
5
  "news": {
6
+ "2.7.3": {
7
+ "en": "hotfix for Aqara presence detector FP1",
8
+ "de": "hotfix für Aqara Präsenzmelder FP1",
9
+ "ru": "hotfix для детектора присутствия Aqara FP1",
10
+ "pt": "hotfix para detector de presença Aqara FP1",
11
+ "nl": "quality over Quanteur FP1",
12
+ "fr": "hotfix pour détecteur de présence Aqara FP1",
13
+ "it": "hotfix per rilevatore di presenza Aqara FP1",
14
+ "es": "hotfix para detector de presencia Aqara FP1",
15
+ "pl": "hotfix",
16
+ "uk": "hotfix для датчика присутності Aqara FP1",
17
+ "zh-cn": "aqara存在侦查员FP1"
18
+ },
19
+ "2.7.2": {
20
+ "en": "rework of the detection of removed devices",
21
+ "de": "nacharbeiten der erkennung von entfernten geräten",
22
+ "ru": "переработка обнаружения удаленных устройств",
23
+ "pt": "retrabalho da detecção de dispositivos removidos",
24
+ "nl": "_",
25
+ "fr": "retravail de la détection des dispositifs enlevés",
26
+ "it": "rielaborazione del rilevamento dei dispositivi rimossi",
27
+ "es": "rework of the detection of removed devices",
28
+ "pl": "przepraszanie detekcji usuniętych urządzeń",
29
+ "uk": "реконструкція виявлення видалених пристроїв",
30
+ "zh-cn": "清除装置的探查工作"
31
+ },
6
32
  "2.7.1": {
7
33
  "en": "added option for use folder description\nuse the iobroker device folder description for device description or events",
8
34
  "de": "zusatzoption für die ordnerbeschreibung\ndie beschreibung des iobroker geräteordners für gerätebeschreibung oder ereignisse",
@@ -67,32 +93,6 @@
67
93
  "pl": "tekst do akcji #84 (https:/github.com/o0shojo0o/ioBroker.zigbee2mqtt/issues/84)",
68
94
  "uk": "javaScript licenses API Веб-сайт Go1.13.8",
69
95
  "zh-cn": "行动案文[84](http://github.com/oshojo0o/ioBroker.zigbee2mqt/issues/84)"
70
- },
71
- "2.4.4": {
72
- "en": "better state identification ([#79](https://github.com/o0shojo0o/ioBroker.zigbee2mqtt/issues/79))",
73
- "de": "bessere Zustandserkennung #[79](https://github.com/o0shojo0o/ioBroker.zigbee2mqt/issues/79)",
74
- "ru": "лучшая государственная идентификация #[79](https://github.com/o0shojo0o/ioBroker.zigbee2mqtt/issues/79)",
75
- "pt": "melhor identificação do estado #[79](https://github.com/o0shojo0o/ioBroker.zigbee2mqtt/issues/79)",
76
- "nl": "identificatie van de staat is beter",
77
- "fr": "meilleure identification de l ' État #[79](https://github.com/o0shojo0o/ioBroker.zigbee2mqt/issues/79)",
78
- "it": "migliore identificazione dello stato #[79](https://github.com/o0shojo0o/ioBroker.zigbee2mqt/issues/79)",
79
- "es": "mejor identificación estatal #[79](https://github.com/o0shojo0o/ioBroker.zigbee2mqtt/issues/79)",
80
- "pl": "zobacz też: #79 (https:/github.com/o0shojo0o/ioBroker.zigbee2mqtt/issues/79)",
81
- "uk": "[79] (https://github.com/o0shojo0o/ioBroker.zigbee2mqtt/issues/79)",
82
- "zh-cn": "更好的国家辨认(http://github.com/oshojo0o/ioBroker.zigbee2mqt/issues/79)"
83
- },
84
- "2.4.3": {
85
- "en": "fix availability when `friendly_name` `/` contains",
86
- "de": "verfügbarkeit korrigieren bei friendly_name `/` enthält",
87
- "ru": "исправить доступность когда friendly_name `/` содержит",
88
- "pt": "corrigir disponibilidade quando friendly_name `/` contém",
89
- "nl": "_ _",
90
- "fr": "fixer la disponibilité lorsque friendly_name `/` contient",
91
- "it": "fissare la disponibilità quando amichevole_name `/` contiene",
92
- "es": "fijar disponibilidad cuando friendly_name `/` contiene",
93
- "pl": "ustanowić dostęp do przyjaznej nazwy. zawierać",
94
- "uk": "застосувати доступність при дружній_ім`я `/` в наявності",
95
- "zh-cn": "f 在友好的情况下,可提供“/”一词 内载"
96
96
  }
97
97
  },
98
98
  "titleLang": {
@@ -143,6 +143,7 @@
143
143
  "mode": "daemon",
144
144
  "type": "hardware",
145
145
  "compact": true,
146
+ "stopTimeout": 2000,
146
147
  "connectionType": "local",
147
148
  "dataSource": "push",
148
149
  "adminUI": {
@@ -3,7 +3,6 @@ const createDeviceFromExposes = require('./exposes').createDeviceFromExposes;
3
3
  const utils = require('./utils');
4
4
  const colors = require('./colors.js');
5
5
  const rgb = require('./rgb.js');
6
- //const createCache = {};
7
6
 
8
7
  class DeviceController {
9
8
  constructor(adapter, deviceCache, groupCache, config, logCustomizations, createCache) {
@@ -15,7 +14,7 @@ class DeviceController {
15
14
  this.createCache = createCache;
16
15
  }
17
16
 
18
- async createDeviceDefinitions(devicesMessage) {
17
+ createDeviceDefinitions(devicesMessage) {
19
18
  utils.clearArray(this.deviceCache);
20
19
  for (const devicesMessag of devicesMessage) {
21
20
  if (this.logCustomizations.debugDevices.includes(devicesMessag.ieee_address)) {
@@ -27,8 +26,15 @@ class DeviceController {
27
26
  this.removeDeviceByIeee(this.deviceCache, devicesMessag.ieee_address);
28
27
 
29
28
  if (devicesMessag.definition.exposes) {
30
- const newDevice = createDeviceFromExposes(devicesMessag, this.config);
31
- this.deviceCache.push(newDevice);
29
+ try {
30
+ const newDevice = createDeviceFromExposes(devicesMessag, this.config);
31
+ this.deviceCache.push(newDevice);
32
+ } catch (err) {
33
+ this.adapter.log.warn(`Cannot ${devicesMessag.friendly_name} create Device from Exposes!`);
34
+ this.adapter.log.debug(JSON.stringify(devicesMessag));
35
+ this.adapter.log.debug(err);
36
+ }
37
+
32
38
  }
33
39
  }
34
40
  }
@@ -198,10 +204,13 @@ class DeviceController {
198
204
  this.groupCache.push(newDevice);
199
205
  }
200
206
 
201
- async createGroupDefinitions(exposes) {
207
+ async createGroupDefinitions(groupsMessage) {
202
208
  utils.clearArray(this.groupCache);
203
- for (const expose of exposes) {
204
- await this.defineGroupDevice(expose.friendly_name, `group_${expose.id}`, expose.scenes);
209
+ for (const groupMessage of groupsMessage) {
210
+ if (this.logCustomizations.debugDevices.includes(groupMessage.id)) {
211
+ this.adapter.log.warn(`--->>> fromZ2M -> ${groupMessage.id} exposes: ${JSON.stringify(groupMessage)}`);
212
+ }
213
+ await this.defineGroupDevice(groupMessage.friendly_name, `group_${groupMessage.id}`, groupMessage.scenes);
205
214
  }
206
215
  }
207
216
 
@@ -231,22 +240,26 @@ class DeviceController {
231
240
  type: 'device',
232
241
  common: {
233
242
  name: deviceName,
234
- desc: description
243
+ desc: description,
244
+ statusStates: { onlineId: '' }
235
245
  },
236
-
237
- native: {}
246
+ native: {
247
+ deviceRemoved: false,
248
+ groupDevice: false
249
+ }
238
250
  };
239
251
 
240
- // Only the onlineId is set if the device is not disabled and is not a group
241
- if (!device.ieee_address.includes('group_') && (!device.disabled || device.disabled == false)) {
242
- deviceObj.common.statusStates = {
243
- onlineId: `${this.adapter.name}.${this.adapter.instance}.${device.ieee_address}.available`
244
- };
252
+ // Group Device
253
+ if (device.ieee_address.includes('group_')) {
254
+ deviceObj.native.groupDevice = true;
245
255
  }
256
+ // Disabled Device
257
+ else if (device.disabled || device.disabled == true) {
258
+ // Placeholder for possible later logic
259
+ }
260
+ // Only the onlineId is set if the device is not disabled and is not a group
246
261
  else {
247
- deviceObj.common.statusStates = {
248
- onlineId: ''
249
- };
262
+ deviceObj.common.statusStates.onlineId = `${this.adapter.name}.${this.adapter.instance}.${device.ieee_address}.available`;
250
263
  }
251
264
 
252
265
  //@ts-ignore
@@ -287,40 +300,41 @@ class DeviceController {
287
300
  }
288
301
  }
289
302
 
290
- processRemoveEvent(messageObj) {
291
- let ieee_address = undefined;
303
+ async checkAndProgressDeviceRemove() {
292
304
  let description = '';
293
305
  let deviceName = '';
294
- if (messageObj.payload && messageObj.payload.type == 'device_leave') {
295
- ieee_address = messageObj.payload.data.ieee_address;
296
- }
306
+ let iobDevices = await this.adapter.getDevicesAsync();
307
+ // Do not consider devices already marked as "deviceRemoved"
308
+ iobDevices = iobDevices.filter(x => x.native.deviceRemoved == false);
309
+ // Do not consider groups
310
+ iobDevices = iobDevices.filter(x => x.native.groupDevice == false);
297
311
 
298
- //{"data":{"block":false,"force":true,"id":"0xa4c138c954baaf54"},"status":"ok","transaction":"zhvjf-5"}
299
- if (messageObj.payload && messageObj.payload.data) {
300
- const device = this.deviceCache.find(x => x.id == messageObj.payload.data.id);
301
- if (device) {
302
- ieee_address = device.ieee_address;
303
- deviceName = this.getDeviceName(device);
304
- }
305
- }
312
+ for (const iobDevice of iobDevices) {
313
+ const ieee_address = iobDevice._id.split('.')[2];
314
+ //Check whether the devices found from the object tree are also available in the DeviceCache
315
+ if (!this.deviceCache.find(x => x.ieee_address == ieee_address)) {
316
+ deviceName = iobDevice.common.name;
306
317
 
307
- if (ieee_address != undefined) {
308
- this.adapter.setState(`${ieee_address}.available`, false, true);
309
- deviceName = this.createCache[ieee_address].name;
318
+ if (this.config.useEventInDesc == true) {
319
+ description = 'Device was removed!';
320
+ }
321
+ else {
322
+ deviceName = `[Removed] ${deviceName}`;
323
+ }
310
324
 
311
- if (this.config.useEventInDesc == true) {
312
- description = 'Device was removed!';
313
- }
314
- else {
315
- deviceName = `[Removed] ${deviceName}`;
325
+ this.adapter.extendObject(`${ieee_address}`, {
326
+ common: {
327
+ name: deviceName,
328
+ desc: description
329
+ },
330
+ native: {
331
+ deviceRemoved: true
332
+ }
333
+ });
334
+ this.adapter.setStateChangedAsync(`${ieee_address}.available`, false, true);
335
+
336
+ delete this.createCache[ieee_address];
316
337
  }
317
- this.adapter.extendObject(`${ieee_address}`, {
318
- common: {
319
- name: deviceName,
320
- desc: description
321
- }
322
- });
323
- delete this.createCache[ieee_address];
324
338
  }
325
339
  }
326
340
 
package/lib/exposes.js CHANGED
@@ -966,11 +966,24 @@ function createDeviceFromExposes(devicesMessag, config) {
966
966
 
967
967
  case 'composite':
968
968
  for (const prop of expose.features) {
969
- const st = genState(prop);
970
- st.prop = expose.property;
971
- st.inOptions = true;
969
+ // let state;
970
+ // if (prop.type == 'list' && prop.features) {
971
+ // const listName = prop.name;
972
+
973
+ // for (const feature of prop.features) {
974
+ // genState(feature, 'state', `${listName}_${feature.name}`, prop.description);
975
+ // }
976
+ // }
977
+
978
+ const state = genState(prop);
979
+ // Workaround for FP1 new state (region_upsert)
980
+ if (!state) {
981
+ break;
982
+ }
983
+ state.prop = expose.property;
984
+ state.inOptions = true;
972
985
  // I'm not fully sure, as it really needed, but
973
- st.setterOpt = (value, options) => {
986
+ state.setterOpt = (value, options) => {
974
987
  const result = {};
975
988
  options[prop.property] = value;
976
989
  result[expose.property] = options;
@@ -978,17 +991,17 @@ function createDeviceFromExposes(devicesMessag, config) {
978
991
  };
979
992
  // if we have a composite expose, the value have to be an object {expose.property : {prop.property: value}}
980
993
  if (prop.access & z2mAccess.SET) {
981
- st.setter = (value, options) => {
994
+ state.setter = (value, options) => {
982
995
  const result = {};
983
996
  options[prop.property] = value;
984
997
  result[expose.property] = options;
985
998
  return result;
986
999
  };
987
- st.setattr = expose.property;
1000
+ state.setattr = expose.property;
988
1001
  }
989
1002
  // if we have a composite expose, the payload will be an object {expose.property : {prop.property: value}}
990
1003
  if (prop.access & z2mAccess.STATE) {
991
- st.getter = payload => {
1004
+ state.getter = payload => {
992
1005
  if ((payload.hasOwnProperty(expose.property)) && (payload[expose.property] !== null) && payload[expose.property].hasOwnProperty(prop.property)) {
993
1006
  return !isNaN(payload[expose.property][prop.property]) ? payload[expose.property][prop.property] : undefined;
994
1007
  } else {
@@ -996,9 +1009,9 @@ function createDeviceFromExposes(devicesMessag, config) {
996
1009
  }
997
1010
  };
998
1011
  } else {
999
- st.getter = _payload => { return undefined; };
1012
+ state.getter = _payload => { return undefined; };
1000
1013
  }
1001
- pushToStates(st, prop.access);
1014
+ pushToStates(state, prop.access);
1002
1015
  }
1003
1016
  break;
1004
1017
  default:
@@ -133,12 +133,17 @@ class StatesController {
133
133
  }
134
134
 
135
135
  async setAllAvailableToFalse() {
136
- for (const device of this.deviceCache) {
137
- for (const state of device.states) {
138
- if (state.id == 'available') {
139
- await this.adapter.setStateChangedAsync(`${device.ieee_address}.${state.id}`, false, true);
140
- }
141
- }
136
+ // for (const device of this.deviceCache) {
137
+ // for (const state of device.states) {
138
+ // if (state.id == 'available') {
139
+ // await this.adapter.setStateChangedAsync(`${device.ieee_address}.${state.id}`, false, true);
140
+ // }
141
+ // }
142
+ // }
143
+
144
+ const availableStates = await this.adapter.getStatesAsync('*.available');
145
+ for (const availableState in availableStates) {
146
+ await this.adapter.setStateChangedAsync(availableState, false, true);
142
147
  }
143
148
  }
144
149
 
package/main.js CHANGED
@@ -153,6 +153,7 @@ class Zigbee2mqtt extends core.Adapter {
153
153
  case 'bridge/devices':
154
154
  await deviceController.createDeviceDefinitions(messageObj.payload);
155
155
  await deviceController.createOrUpdateDevices();
156
+ await deviceController.checkAndProgressDeviceRemove();
156
157
  await statesController.subscribeWritableStates();
157
158
  statesController.processQueue();
158
159
  break;
@@ -163,13 +164,13 @@ class Zigbee2mqtt extends core.Adapter {
163
164
  statesController.processQueue();
164
165
  break;
165
166
  case 'bridge/event':
166
- deviceController.processRemoveEvent(messageObj);
167
167
  break;
168
168
  case 'bridge/response/device/remove':
169
- deviceController.processRemoveEvent(messageObj);
170
169
  break;
171
170
  case 'bridge/response/device/options':
172
171
  break;
172
+ case 'bridge/response/permit_join':
173
+ break;
173
174
  case 'bridge/extensions':
174
175
  break;
175
176
  case 'bridge/logging':
@@ -177,6 +178,8 @@ class Zigbee2mqtt extends core.Adapter {
177
178
  z2mController.proxyZ2MLogs(messageObj);
178
179
  }
179
180
  break;
181
+ case 'bridge/response/device/configure':
182
+ break;
180
183
  case 'bridge/response/device/rename':
181
184
  await deviceController.renameDeviceInCache(messageObj);
182
185
  await deviceController.createOrUpdateDevices();
@@ -210,7 +213,6 @@ class Zigbee2mqtt extends core.Adapter {
210
213
  }
211
214
  // States
212
215
  } else {
213
- //console.log(JSON.stringify(messageObj));
214
216
  statesController.processDeviceMessage(messageObj);
215
217
  }
216
218
  }
@@ -219,33 +221,45 @@ class Zigbee2mqtt extends core.Adapter {
219
221
  }
220
222
 
221
223
  async onUnload(callback) {
222
- try {
224
+ // Close MQTT connections
225
+ if (['exmqtt', 'intmqtt'].includes(this.config.connectionType)) {
223
226
  if (mqttClient && !mqttClient.closed) {
224
- mqttClient.close();
227
+ try {
228
+ mqttClient.close();
229
+ } catch (e) {
230
+ this.log.error(e);
231
+ }
225
232
  }
226
- websocketController.closeConnection();
227
- } catch (e) {
228
- this.log.error(e);
229
233
  }
230
-
231
- try {
232
- mqttServerController.closeServer();
233
- } catch (e) {
234
- this.log.error(e);
234
+ // Internal or Dummy MQTT-Server
235
+ if (this.config.connectionType == 'intmqtt' || this.config.dummyMqtt == true) {
236
+ try {
237
+ mqttServerController.closeServer();
238
+ } catch (e) {
239
+ this.log.error(e);
240
+ }
235
241
  }
236
-
242
+ // Websocket
243
+ else if (this.config.connectionType == 'ws') {
244
+ try {
245
+ websocketController.closeConnection();
246
+ } catch (e) {
247
+ this.log.error(e);
248
+ }
249
+ }
250
+ // Set all device available states of false
237
251
  try {
238
252
  await statesController.setAllAvailableToFalse();
239
253
  } catch (e) {
240
254
  this.log.error(e);
241
255
  }
242
-
256
+ // Clear all websocket timers
243
257
  try {
244
258
  await websocketController.allTimerClear();
245
259
  } catch (e) {
246
260
  this.log.error(e);
247
261
  }
248
-
262
+ // Clear all state timers
249
263
  try {
250
264
  await statesController.allTimerClear();
251
265
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.zigbee2mqtt",
3
- "version": "2.7.1",
3
+ "version": "2.7.3",
4
4
  "description": "Zigbee2MQTT adapter for ioBroker",
5
5
  "author": {
6
6
  "name": "Dennis Rathjen",
@@ -36,21 +36,21 @@
36
36
  "@types/chai": "^4.3.4",
37
37
  "@types/chai-as-promised": "^7.1.5",
38
38
  "@types/mocha": "^10.0.1",
39
- "@types/node": "^18.11.18",
39
+ "@types/node": "^18.13.0",
40
40
  "@types/proxyquire": "^1.3.28",
41
41
  "@types/sinon": "^10.0.13",
42
42
  "@types/sinon-chai": "^3.2.9",
43
43
  "chai": "^4.3.7",
44
44
  "chai-as-promised": "^7.1.1",
45
- "eslint": "^8.32.0",
45
+ "eslint": "^8.34.0",
46
46
  "eslint-config-prettier": "^8.6.0",
47
47
  "eslint-plugin-prettier": "^4.2.1",
48
48
  "mocha": "^10.2.0",
49
- "prettier": "^2.8.3",
49
+ "prettier": "^2.8.4",
50
50
  "proxyquire": "^2.1.3",
51
51
  "sinon": "^15.0.1",
52
52
  "sinon-chai": "^3.7.0",
53
- "typescript": "~4.9.4"
53
+ "typescript": "~4.9.5"
54
54
  },
55
55
  "main": "main.js",
56
56
  "files": [