mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-10-22 14:01:20 +00:00
Update Birth & Will Topic for Home Assistant #3918
This commit is contained in:
1 parent
570985b877
commit
a845d35b8e
2 files changed
+31
-1
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user