mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-10-23 14:22:38 +00:00
add Sengled E11-G13 bulbs to deviceAvailability.js (#860)
* add Sengled E11-G13 bulbs to deviceAvailability.js * Update deviceAvailability.js * Refactor and add tests * Fix linting issue
This commit is contained in:
1 parent
28e32884d9
commit
34a3e3c00b
2 files changed
+60
No files matched your search
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user