diff --git a/lib/extension/deviceAvailability.js b/lib/extension/deviceAvailability.js index 19123c973..81d575674 100644 --- a/lib/extension/deviceAvailability.js +++ b/lib/extension/deviceAvailability.js @@ -2,6 +2,13 @@ const logger = require('../util/logger'); const settings = require('../util/settings'); const utils = require('../util/utils'); const Queue = require('queue'); +const zigbeeShepherdConverters = require('zigbee-shepherd-converters'); + +// Some EndDevices should be pinged +// e.g. E11-G13 https://github.com/Koenkk/zigbee2mqtt/issues/775#issuecomment-453683846 +const pingableDevices = [ + zigbeeShepherdConverters.devices.find((d) => d.model === 'E11-G13'), +]; /** * This extensions set availability based on optionally polling router devices @@ -26,6 +33,10 @@ class DeviceAvailabilityHandler { } isPingable(device) { + if (pingableDevices.find((d) => d.zigbeeModel.includes(device.modelId))) { + return true; + } + return device.type === 'Router' && (device.powerSource && device.powerSource !== 'Battery'); } diff --git a/test/deviceAvailability.test.js b/test/deviceAvailability.test.js new file mode 100644 index 000000000..aa4f2b577 --- /dev/null +++ b/test/deviceAvailability.test.js @@ -0,0 +1,49 @@ +const chai = require('chai'); +const sinon = require('sinon'); +const DeviceAvailability = require('../lib/extension/deviceAvailability'); +const utils = require('./utils'); +const sandbox = sinon.createSandbox(); + +describe('DeviceAvailability', () => { + let deviceAvailability; + + beforeEach(() => { + utils.stubLogger(sandbox); + deviceAvailability = new DeviceAvailability(null, null, null, () => {}); + }); + + afterEach(() => { + sandbox.restore(); + }); + + describe('Determine pingable devices', () => { + it('Router device should be a pingable device', () => { + const device = { + powerSource: 'Mains (single phase)', + type: 'Router', + }; + + chai.assert.isTrue(deviceAvailability.isPingable(device)); + }); + + it('Battery device should not be a pingable device', () => { + const device = { + powerSource: 'Battery', + type: 'EndDevice', + }; + + chai.assert.isFalse(deviceAvailability.isPingable(device)); + }); + + it('E11-G13 should be a pingable device', () => { + const device = { + powerSource: 'Mains (single phase)', + type: 'EndDevice', + modelId: 'E11-G13', + manufId: 4448, + }; + + chai.assert.isTrue(deviceAvailability.isPingable(device)); + }); + }); +});