Expose device and group configuration_url to Home Assistant. (#9214)

This commit is contained in:
Koen Kanters 2021-10-18 18:16:00 +02:00 committed by GitHub
parent ca255d3aa3
commit eaad39a199
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 0 deletions

View File

@ -1158,6 +1158,12 @@ export default class HomeAssistant extends Extension {
payload.manufacturer = entity.definition.vendor; payload.manufacturer = entity.definition.vendor;
} }
if (settings.get().frontend?.url) {
const url = settings.get().frontend?.url;
payload.configuration_url = entity.isDevice() ? `${url}/#/device/${entity.ieeeAddr}/info` :
`${url}/#/group/${entity.ID}`;
}
return payload; return payload;
} }

View File

@ -176,6 +176,7 @@ declare global {
auth_token?: string, auth_token?: string,
host?: string, host?: string,
port?: number, port?: number,
url?: string,
}, },
mqtt: { mqtt: {
base_topic: string, base_topic: string,

View File

@ -1696,4 +1696,41 @@ describe('HomeAssistant extension', () => {
expect.any(Function), expect.any(Function),
); );
}); });
it('Should discover devices with configuration url', async () => {
settings.set(['frontend', 'url'], 'http://zigbee.mqtt');
await resetExtension();
let payload;
await flushPromises();
payload = {
'unit_of_measurement': '°C',
'device_class': 'temperature',
'state_class': 'measurement',
'enabled_by_default': true,
'value_template': "{{ value_json.temperature }}",
'state_topic': 'zigbee2mqtt/weather_sensor',
'json_attributes_topic': 'zigbee2mqtt/weather_sensor',
'name': 'weather_sensor_temperature',
'unique_id': '0x0017880104e45522_temperature_zigbee2mqtt',
'device': {
'identifiers': ['zigbee2mqtt_0x0017880104e45522'],
'name': 'weather_sensor',
'sw_version': version,
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
'configuration_url': 'http://zigbee.mqtt/#/device/0x0017880104e45522/info'
},
'availability': [{topic: 'zigbee2mqtt/bridge/state'}],
};
expect(MQTT.publish).toHaveBeenCalledWith(
'homeassistant/sensor/0x0017880104e45522/temperature/config',
stringify(payload),
{ retain: true, qos: 0 },
expect.any(Function),
);
});
}); });