Only republish retained messages when none are received. #9629

This commit is contained in:
Koen Kanters
2022-07-25 19:37:33 +02:00
parent 316daee49d
commit 343ef7fd9f
2 changed files with 30 additions and 6 deletions
+12 -1
View File
@@ -650,10 +650,21 @@ describe('Controller', () => {
MQTT.publish.mockClear();
MQTT.events['connect']();
await flushPromises();
expect(MQTT.publish).toHaveBeenCalledTimes(13);
jest.runOnlyPendingTimers();
expect(MQTT.publish).toHaveBeenCalledTimes(12);
expect(MQTT.publish).toHaveBeenCalledWith('zigbee2mqtt/bridge/info', expect.any(String), { retain: true, qos: 0 }, expect.any(Function));
});
it('Should not republish retained messages on MQTT reconnect when retained message are sent', async () => {
await controller.start();
MQTT.publish.mockClear();
MQTT.events['connect']();
await flushPromises();
await MQTT.events.message('zigbee2mqtt/bridge/state', 'online');
jest.runOnlyPendingTimers();
expect(MQTT.publish).toHaveBeenCalledTimes(0);
});
it('Should prevent any message being published with retain flag when force_disable_retain is set', async () => {
settings.set(['mqtt', 'force_disable_retain'], true);
await controller.mqtt.connect()