mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-15 18:08:32 -07:00
Expose device and group configuration_url to Home Assistant. (#9214)
This commit is contained in:
parent
ca255d3aa3
commit
eaad39a199
@ -1158,6 +1158,12 @@ export default class HomeAssistant extends Extension {
|
||||
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;
|
||||
}
|
||||
|
||||
|
1
lib/types/types.d.ts
vendored
1
lib/types/types.d.ts
vendored
@ -176,6 +176,7 @@ declare global {
|
||||
auth_token?: string,
|
||||
host?: string,
|
||||
port?: number,
|
||||
url?: string,
|
||||
},
|
||||
mqtt: {
|
||||
base_topic: string,
|
||||
|
@ -1696,4 +1696,41 @@ describe('HomeAssistant extension', () => {
|
||||
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),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user