I noticed that when my MQTT broker restarts, nodejs-poolController reconnects successfully but doesn't re-publish the equipment state. Home Assistant shows all pool entities as "unavailable" until I resave the MQTT configuration or restart the pool controller.
Looking at mqttInterface.ts, I think I found the issue. The sentInitialMessages flag is set to true after the first connect and controls whether emitAllEquipmentChanges() runs. But the flag is never reset on disconnect or offline events, so when the broker restarts and the client reconnects, emitAllEquipmentChanges() doesn't get called again.
I have a fork with the following offline event handler working successfully:
this.client.on('offline', () => {
logger.info(`MQTT client offline ${this.cfg.name}`);
this.sentInitialMessages = false;
});
This way when the broker comes back and the client reconnects, it re-publishes all equipment state. Happy to submit a PR if this approach makes sense.
I noticed that when my MQTT broker restarts, nodejs-poolController reconnects successfully but doesn't re-publish the equipment state. Home Assistant shows all pool entities as "unavailable" until I resave the MQTT configuration or restart the pool controller.
Looking at
mqttInterface.ts, I think I found the issue. ThesentInitialMessagesflag is set totrueafter the first connect and controls whetheremitAllEquipmentChanges()runs. But the flag is never reset on disconnect or offline events, so when the broker restarts and the client reconnects,emitAllEquipmentChanges()doesn't get called again.I have a fork with the following
offlineevent handler working successfully:This way when the broker comes back and the client reconnects, it re-publishes all equipment state. Happy to submit a PR if this approach makes sense.