iobroker.zigbee 1.10.14 → 2.0.1

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/lib/utils.js CHANGED
@@ -157,7 +157,7 @@ exports.decimalToHex = decimalToHex;
157
157
  exports.getZbId = getZbId;
158
158
  exports.getAdId = getAdId;
159
159
  exports.getModelRegEx = getModelRegEx;
160
- exports.isRouter = device => device.type === 'Router' && !forceEndDevice.includes(device.modelID);
160
+ exports.isRouter = device => (device.type === 'Router' || (typeof device.powerSource == 'string' && device.powerSource.startsWith('Mains'))) && !forceEndDevice.includes(device.modelID);
161
161
  exports.isBatteryPowered = device => device.powerSource && device.powerSource === 'Battery';
162
162
  exports.isXiaomiDevice = device =>
163
163
  device.modelID !== 'lumi.router' &&
@@ -49,9 +49,10 @@ class DeviceAvailability extends BaseExtension {
49
49
  });
50
50
  this.startDevicePingQueue = []; // simple fifo array for starting device pings
51
51
  this.startDevicePingTimeout = null; // handle for the timeout which empties the queue
52
- this.startDevicePingDelay = 200; // 200 ms delay between starting the ping timeout
52
+ this.startDevicePingDelay = 500; // 200 ms delay between starting the ping timeout
53
53
  this.name = 'DeviceAvailability';
54
54
  this.elevate_debug = false;
55
+ this.isStarted = false;
55
56
  }
56
57
 
57
58
  setOptions(options) {
@@ -74,6 +75,7 @@ class DeviceAvailability extends BaseExtension {
74
75
  }
75
76
 
76
77
  isPingable(device) {
78
+
77
79
  if (this.active_ping) {
78
80
  if (this.forced_ping && forcedPingable.find(d => d && d.hasOwnProperty('zigbeeModel') && d.zigbeeModel.includes(device.modelID))) {
79
81
  return true;
@@ -90,6 +92,7 @@ class DeviceAvailability extends BaseExtension {
90
92
  }
91
93
 
92
94
  async registerDevicePing(device, entity) {
95
+ if (!this.isStarted) return;
93
96
  this.debug(`register device Ping for ${JSON.stringify(device.ieeeAddr)}`);
94
97
  this.forcedNonPingable[device.ieeeAddr] = false;
95
98
  // this.warn(`Called registerDevicePing for '${device}' of '${entity}'`);
@@ -104,6 +107,7 @@ class DeviceAvailability extends BaseExtension {
104
107
  }
105
108
  });
106
109
  this.number_of_registered_devices++;
110
+ this.debug(`registering device Ping (${this.number_of_registered_devices}) for ${device.ieeeAddr} (${device.modelID})`);
107
111
  this.availability_timeout = Math.max(Math.min(this.number_of_registered_devices * AverageTimeBetweenPings, MaxAvailabilityTimeout), MinAvailabilityTimeout);
108
112
  this.startDevicePingQueue.push({device, entity});
109
113
  if (this.startDevicePingTimeout == null) {
@@ -113,7 +117,7 @@ class DeviceAvailability extends BaseExtension {
113
117
  }
114
118
 
115
119
  async deregisterDevicePing(device) {
116
- this.info(`deregister device Ping for deactivated device ${JSON.stringify(device.ieeeAddr)}`);
120
+ this.debug(`deregister device Ping for deactivated device ${JSON.stringify(device.ieeeAddr)}`);
117
121
  this.forcedNonPingable[device.ieeeAddr] = true;
118
122
  if (this.timers[device.ieeeAddr]) {
119
123
  clearTimeout(this.timers[device.ieeeAddr]);
@@ -122,6 +126,7 @@ class DeviceAvailability extends BaseExtension {
122
126
 
123
127
  async startDevicePing() {
124
128
  // this.warn(JSON.stringify(this));
129
+ if (!this.isStarted) return;
125
130
  this.startDevicePingTimeout = null;
126
131
  const item = this.startDevicePingQueue.shift();
127
132
  if (this.startDevicePingQueue.length > 0) {
@@ -140,6 +145,7 @@ class DeviceAvailability extends BaseExtension {
140
145
  // triggered by the 'new device' event to ensure that they are handled
141
146
  // identically on reconnect, disconnect and new pair (as)
142
147
  const clients = await this.zigbee.getClients();
148
+ this.isStarted = true;
143
149
  // this.warn('onZigbeeStarted called');
144
150
  for (const device of clients) {
145
151
  if (this.isPingable(device)) {
@@ -154,10 +160,11 @@ class DeviceAvailability extends BaseExtension {
154
160
  }
155
161
 
156
162
  async handleIntervalPingable(device, entity) {
163
+ if (!this.isStarted) return;
157
164
  const ieeeAddr = device.ieeeAddr;
158
165
  const resolvedEntity = entity ? entity : await this.zigbee.resolveEntity(ieeeAddr);
159
166
  if (!resolvedEntity) {
160
- this.debug(`Stop pinging '${ieeeAddr}' ${device.modelID}, device is not known anymore`);
167
+ this.warn(`Stop pinging '${ieeeAddr}' ${device.modelID}, device is not known anymore`);
161
168
  return;
162
169
  }
163
170
  if (this.isPingable(device)) {
@@ -166,29 +173,11 @@ class DeviceAvailability extends BaseExtension {
166
173
  this.ping_counters[device.ieeeAddr] = {failed: 0, reported: 0};
167
174
  pingCount = {failed: 0, reported: 0};
168
175
  }
169
-
170
- // first see if we can "ping" the device by reading a Status
171
- try {
172
- for (const key of toZigbeeCandidates) {
173
- const converter = resolvedEntity.mapped.toZigbee.find((tz) => tz.key.includes(key));
174
- if (converter) {
175
- await converter.convertGet(device.endpoints[0], key, {});
176
- this.debug(`Successful read state '${key}' of '${device.ieeeAddr}' in stead of pinging`);
177
- this.setTimerPingable(device, 1);
178
- this.ping_counters[device.ieeeAddr].failed = 0;
179
- return;
180
- }
181
- }
182
- } catch (error) {
183
- this.sendError(error);
184
- this.debug(`Exception in readState of '${device.ieeeAddr}' - error : '${error}'`);
185
- // intentionally empty: Just present to ensure we cause no harm
186
- // when reading the state fails. => fall back on standard Ping function
187
- }
188
176
  try {
177
+ //this.warn(`Pinging '${ieeeAddr}' (${device.modelID})`)
189
178
  await device.ping();
190
179
  this.publishAvailability(device, true);
191
- this.debug(`Successfully pinged ${ieeeAddr} ${device.modelID}`);
180
+ //this.warn(`Successfully pinged ${ieeeAddr} (${device.modelID})`);
192
181
  this.setTimerPingable(device, 1);
193
182
  this.ping_counters[device.ieeeAddr].failed = 0;
194
183
  } catch (error) {
@@ -210,6 +199,7 @@ class DeviceAvailability extends BaseExtension {
210
199
  }
211
200
 
212
201
  async handleIntervalNotPingable(device) {
202
+ if (!this.isStarted) return;
213
203
  const entity = await this.zigbee.resolveEntity(device.ieeeAddr);
214
204
  if (!entity || !device.lastSeen) {
215
205
  return;
@@ -224,6 +214,7 @@ class DeviceAvailability extends BaseExtension {
224
214
  }
225
215
 
226
216
  setTimerPingable(device, factor) {
217
+ if (!this.isStarted) return;
227
218
  if (factor === undefined || factor < 1) {
228
219
  factor = 1;
229
220
  }
@@ -235,6 +226,7 @@ class DeviceAvailability extends BaseExtension {
235
226
  }
236
227
 
237
228
  async stop() {
229
+ this.isStarted = false;
238
230
  for (const timer of Object.values(this.timers)) {
239
231
  clearTimeout(timer);
240
232
  }
File without changes