Option to set Home Assistant discovery topic. #1019

This commit is contained in:
Koen Kanters
2019-03-15 22:41:39 +01:00
parent b39e195763
commit fdcf2e8c3d
3 changed files with 41 additions and 1 deletions
+3 -1
View File
@@ -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;
+5
View File
@@ -65,6 +65,11 @@ const defaults = {
* Enables reporting feature
*/
report: false,
/**
* Home Assistant discovery topic
*/
homeassistant_discovery_topic: 'homeassistant',
},
};
+33
View File
@@ -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');
});
});