Update Birth & Will Topic for Home Assistant #3918

This commit is contained in:
Koen Kanters committed 2020-07-16 23:16:59 +02:00
1 parent 570985b877
commit a845d35b8e
2 files changed
+31 -1

No files matched your search

+4 -1
View File
@@ -1784,6 +1784,8 @@ const mapping = {
'TYZS1L': [cfg.light_brightness_colortemp_colorxy],
};
const defaultStatusTopic = 'homeassistant/status';
/**
* This extensions handles integration with HomeAssistant
*/
@@ -1940,6 +1942,7 @@ class HomeAssistant extends Extension {
async onMQTTConnected() {
this.mqtt.subscribe(this.statusTopic);
this.mqtt.subscribe(defaultStatusTopic);
// MQTT discovery of all paired devices on startup.
for (const device of this.zigbee.getClients()) {
@@ -2132,7 +2135,7 @@ class HomeAssistant extends Extension {
}
onMQTTMessage(topic, message) {
if (topic !== this.statusTopic) {
if (topic !== this.statusTopic && topic !== defaultStatusTopic) {
return false;
}
+27
View File
@@ -573,12 +573,39 @@ describe('HomeAssistant extension', () => {
expect(MQTT.publish).toHaveBeenCalledTimes(1);
});
it('Should send all status when home assistant comes online (default topic)', async () => {
jest.useFakeTimers();
data.writeDefaultState();
controller = new Controller();
await controller.start();
expect(MQTT.subscribe).toHaveBeenCalledWith('homeassistant/status');
await flushPromises();
MQTT.publish.mockClear();
await MQTT.events.message('homeassistant/status', 'online');
await flushPromises();
jest.runOnlyPendingTimers();
await flushPromises();
expect(MQTT.publish).toHaveBeenCalledWith(
'zigbee2mqtt/bulb',
'{"state":"ON","brightness":50,"color_temp":370,"linkquality":99,"update_available":false}',
{ retain: true, qos: 0 },
expect.any(Function)
);
expect(MQTT.publish).toHaveBeenCalledWith(
'zigbee2mqtt/remote',
'{"brightness":255,"update_available":false}',
{ retain: true, qos: 0 },
expect.any(Function)
);
});
it('Should send all status when home assistant comes online', async () => {
jest.useFakeTimers();
data.writeDefaultState();
controller = new Controller();
await controller.start();
await flushPromises();
expect(MQTT.subscribe).toHaveBeenCalledWith('hass/status');
MQTT.publish.mockClear();
await MQTT.events.message('hass/status', 'online');
await flushPromises();