Skip to content

Commit

Permalink
Only setup reporting for non battery powered routers. Koenkk#1064
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Apr 16, 2019
1 parent 5e48ee6 commit 8dd8155
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/extension/deviceReport.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
const logger = require('../util/logger');
const CC2530Router = zigbeeShepherdConverters.devices.find((d) => d.model === 'CC2530.ROUTER');
const utils = require('../util/utils');

const candidates = {
'genOnOff': {
Expand Down Expand Up @@ -82,14 +83,20 @@ class DeviceReport {
});
}

shouldSetupReporting(device) {
return utils.isRouter(device) && !utils.isBatteryPowered(device);
}

onZigbeeStarted() {
this.zigbee.getAllClients().forEach((device) => {
const mappedDevice = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
this.zigbee.getAllClients()
.filter((d) => this.shouldSetupReporting(d))
.forEach((device) => {
const mappedDevice = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);

if (mappedDevice) {
this.setupReporting(mappedDevice, device);
}
});
if (mappedDevice) {
this.setupReporting(mappedDevice, device);
}
});
}

onZigbeeMessage(message, device, mappedDevice) {
Expand All @@ -98,7 +105,8 @@ class DeviceReport {
// Ikea TRADFRI tend to forget their reporting after powered off.
// Re-setup reporting.
// https://github.com/Koenkk/zigbee2mqtt/issues/966
if (device && mappedDevice && ['endDeviceAnnce', 'devIncoming'].includes(message.type)) {
if (device && mappedDevice && ['endDeviceAnnce', 'devIncoming'].includes(message.type) &&
this.shouldSetupReporting(device)) {
this.setupReporting(mappedDevice, device);
}
}
Expand Down

0 comments on commit 8dd8155

Please sign in to comment.