Fix conflict between illuminance and illuminance_lux (#3275)

* Fix conflict between illuminance and illuminance_lux

On certain devices, e.g. GZCGQ01LM, 9290012607, 9290019758, TERNCY-PP01 etc, both
cfg.sensor_illuminance and cfg.sensor_illuminance_lux are applied. As both of these
had the same object_id, only one would show in Home Assistant. Oddly, a mix of both
would apply - e.g. I would get the illuminance value, with the illuminance_lux unit
of 'lx'.

* Add a test for duplicated type/object_id in HA discovery configs
This commit is contained in:
Kiall Mac Innes 2020-04-03 10:12:58 +01:00 committed by GitHub
parent 496c5329a2
commit 1abb5b6a48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -157,7 +157,7 @@ const cfg = {
},
'sensor_illuminance_lux': {
type: 'sensor',
object_id: 'illuminance',
object_id: 'illuminance_lux',
discovery_payload: {
unit_of_measurement: 'lx',
device_class: 'illuminance',

View File

@ -32,6 +32,27 @@ describe('HomeAssistant extension', () => {
expect(missing).toHaveLength(0);
});
it('Should not have duplicate type/object_ids in a mapping', () => {
const duplicated = [];
const HomeAssistant = require('../lib/extension/homeassistant');
const ha = new HomeAssistant(null, null, null, null, {on: () => {}});
require('zigbee-herdsman-converters').devices.forEach((d) => {
const mapping = ha._getMapping()[d.model];
const cfg_type_object_ids = [];
mapping.forEach((c) => {
if (cfg_type_object_ids.includes(c['type'] + '/' + c['object_id'])) {
duplicated.push(d.model);
} else {
cfg_type_object_ids.push(c['type'] + '/' + c['object_id']);
}
});
});
expect(duplicated).toHaveLength(0);
});
it('Should discover devices', async () => {
controller = new Controller(false);
await controller.start();