mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-29 07:08:56 +00:00
Option to set Home Assistant discovery topic. #1019
This commit is contained in:
@@ -638,6 +638,8 @@ class HomeAssistant {
|
||||
if (settings.get().experimental.output === 'attribute') {
|
||||
throw new Error('Home Assitant integration is not possible with attribute output!');
|
||||
}
|
||||
|
||||
this.discoveryTopic = settings.get().advanced.homeassistant_discovery_topic;
|
||||
}
|
||||
|
||||
onMQTTConnected() {
|
||||
@@ -757,7 +759,7 @@ class HomeAssistant {
|
||||
}
|
||||
}
|
||||
|
||||
this.mqtt.publish(topic, JSON.stringify(payload), {retain: true, qos: 0}, null, 'homeassistant');
|
||||
this.mqtt.publish(topic, JSON.stringify(payload), {retain: true, qos: 0}, null, this.discoveryTopic);
|
||||
});
|
||||
|
||||
this.discovered[entityID] = true;
|
||||
|
||||
@@ -65,6 +65,11 @@ const defaults = {
|
||||
* Enables reporting feature
|
||||
*/
|
||||
report: false,
|
||||
|
||||
/**
|
||||
* Home Assistant discovery topic
|
||||
*/
|
||||
homeassistant_discovery_topic: 'homeassistant',
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -557,4 +557,37 @@ describe('HomeAssistant extension', () => {
|
||||
expect(mqtt.publish.mock.calls[0][3]).toBeNull();
|
||||
expect(mqtt.publish.mock.calls[0][4]).toBe('homeassistant');
|
||||
});
|
||||
|
||||
it('Should discover devices with a custom discovery topic', () => {
|
||||
jest.spyOn(settings, 'get').mockReturnValue({
|
||||
mqtt: {
|
||||
base_topic: 'zigbee2mqtt',
|
||||
},
|
||||
experimental: {
|
||||
output: 'json',
|
||||
},
|
||||
advanced: {
|
||||
homeassistant_discovery_topic: 'my_custom_topic',
|
||||
},
|
||||
});
|
||||
|
||||
homeassistant = new HomeassistantExtension(null, mqtt, null, null);
|
||||
|
||||
jest.spyOn(settings, 'getDevice').mockReturnValue({
|
||||
friendly_name: 'my_device',
|
||||
homeassistant: {
|
||||
temperature: {
|
||||
expire_after: 90,
|
||||
device: {
|
||||
identifiers: 'test',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
|
||||
|
||||
expect(mqtt.publish).toHaveBeenCalledTimes(5);
|
||||
expect(mqtt.publish.mock.calls[0][4]).toBe('my_custom_topic');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user