fix(CommunicationRouter): republish status/playback on every MQTT (re)connect (F-066)

status/playback is retained but was only published on a Player transition.
After a power loss mid-melody the Player boots straight into STOPPED with no
transition, so the broker kept serving the old "playing" forever. The
MQTT on-connect callback now publishes Player::getPlaybackSnapshot() on
every CONNECT (not just the first after boot) — "idle" after a reboot, the
live state after a plain reconnect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 20:11:20 +03:00
co-authored by Claude Opus 5.5
parent fe5ab6223c
commit 92a0a8d5e8
4 changed files with 29 additions and 2 deletions
@@ -135,6 +135,12 @@ void CommunicationRouter::begin() {
_mqttClient.setOnConnectCallback([this](bool /*sessionPresent*/) {
reportBootOnce();
// status/playback is retained: if the board lost power (or the link)
// mid-melody, the broker would keep serving "playing" indefinitely.
// Overwrite it with the Player's real state on EVERY connect — normally
// "idle" after a reboot, the live state after a plain reconnect.
if (_player) publishPlayback(_player->getPlaybackSnapshot());
});
// Heartbeat state/ok derivation — independently derived per the topic spec,