Discover linkquality sensor for all devices. https://github.com/Koenkk/zigbee2mqtt/issues/757

This commit is contained in:
Koen Kanters 2019-02-20 20:10:38 +01:00
parent ec0ee53c7a
commit bdfabeb3da
2 changed files with 79 additions and 4 deletions

View File

@ -317,7 +317,7 @@ const mapping = {
'F7C033': [configurations.light_brightness],
'JTYJ-GD-01LM/BW': [configurations.binary_sensor_smoke, configurations.sensor_battery],
'PLUG EDP RE:DY': [configurations.switch, configurations.sensor_power],
'CC2530.ROUTER': [configurations.binary_sensor_router, configurations.sensor_linkquality],
'CC2530.ROUTER': [configurations.binary_sensor_router],
'AA70155': [configurations.light_brightness_colortemp],
'4058075816718': [configurations.light_brightness_colortemp_colorxy],
'AA69697': [configurations.light_brightness_colortemp_colorxy],
@ -511,6 +511,10 @@ const mapping = {
'RB 265': [configurations.light_brightness],
};
Object.keys(mapping).forEach((key) => {
mapping[key].push(configurations.sensor_linkquality);
});
/**
* This extensions handles integration with HomeAssistant
*/

View File

@ -43,7 +43,7 @@ describe('HomeAssistant extension', () => {
});
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
chai.assert.equal(mqtt.publish.callCount, 4);
chai.assert.equal(mqtt.publish.callCount, 5);
// 1
payload = {
@ -140,6 +140,29 @@ describe('HomeAssistant extension', () => {
chai.assert.deepEqual(mqtt.publish.getCall(3).args[2], {retain: true, qos: 0});
chai.assert.equal(mqtt.publish.getCall(3).args[3], null);
chai.assert.equal(mqtt.publish.getCall(3).args[4], 'homeassistant');
// 5
payload = {
'unit_of_measurement': '-',
'value_template': '{{ value_json.linkquality }}',
'state_topic': 'zigbee2mqtt/my_device',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_linkquality',
'unique_id': '0x12345678_linkquality_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
chai.assert.deepEqual(JSON.parse(mqtt.publish.getCall(4).args[1]), payload);
chai.assert.deepEqual(mqtt.publish.getCall(4).args[2], {retain: true, qos: 0});
chai.assert.equal(mqtt.publish.getCall(4).args[3], null);
chai.assert.equal(mqtt.publish.getCall(4).args[4], 'homeassistant');
});
it('Should discover devices with precision', () => {
@ -154,7 +177,7 @@ describe('HomeAssistant extension', () => {
});
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
chai.assert.equal(mqtt.publish.callCount, 4);
chai.assert.equal(mqtt.publish.callCount, 5);
// 1
payload = {
@ -251,6 +274,29 @@ describe('HomeAssistant extension', () => {
chai.assert.deepEqual(mqtt.publish.getCall(3).args[2], {retain: true, qos: 0});
chai.assert.equal(mqtt.publish.getCall(3).args[3], null);
chai.assert.equal(mqtt.publish.getCall(3).args[4], 'homeassistant');
// 5
payload = {
'unit_of_measurement': '-',
'value_template': '{{ value_json.linkquality }}',
'state_topic': 'zigbee2mqtt/my_device',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_linkquality',
'unique_id': '0x12345678_linkquality_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
chai.assert.deepEqual(JSON.parse(mqtt.publish.getCall(4).args[1]), payload);
chai.assert.deepEqual(mqtt.publish.getCall(4).args[2], {retain: true, qos: 0});
chai.assert.equal(mqtt.publish.getCall(4).args[3], null);
chai.assert.equal(mqtt.publish.getCall(4).args[4], 'homeassistant');
});
it('Should discover devices with overriden user configuration', () => {
@ -269,7 +315,7 @@ describe('HomeAssistant extension', () => {
});
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
chai.assert.equal(mqtt.publish.callCount, 4);
chai.assert.equal(mqtt.publish.callCount, 5);
// 1
payload = {
@ -374,5 +420,30 @@ describe('HomeAssistant extension', () => {
chai.assert.deepEqual(mqtt.publish.getCall(3).args[2], {retain: true, qos: 0});
chai.assert.equal(mqtt.publish.getCall(3).args[3], null);
chai.assert.equal(mqtt.publish.getCall(3).args[4], 'homeassistant');
// 5
payload = {
'unit_of_measurement': '-',
'value_template': '{{ value_json.linkquality }}',
'state_topic': 'zigbee2mqtt/my_device',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_linkquality',
'unique_id': '0x12345678_linkquality_zigbee2mqtt',
'expire_after': 30,
'icon': 'mdi:test',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
chai.assert.deepEqual(JSON.parse(mqtt.publish.getCall(4).args[1]), payload);
chai.assert.deepEqual(mqtt.publish.getCall(4).args[2], {retain: true, qos: 0});
chai.assert.equal(mqtt.publish.getCall(4).args[3], null);
chai.assert.equal(mqtt.publish.getCall(4).args[4], 'homeassistant');
});
});