fix(mqtt): one Home-Assistant device per node — closes #898#904
Merged
Conversation
After the #872 MQTT wiring, the JSON->VitalsSnapshot bridge hard-coded a single node_id (the MQTT client id) and the publisher used one OwnedDiscoveryBuilder, so every physical node collapsed into a single Home-Assistant device (identifiers:["wifi_densepose_wifi-densepose-1"]), contradicting the one-device-per-node docs. - Bridge (main.rs): emit one VitalsSnapshot per node in the sensing update's nodes[] (each carries its own node_id + RSSI; shared aggregate presence/vitals), falling back to a single aggregate snapshot when there is no per-node data (wifi/simulate sources). - Publisher (publisher.rs): add OwnedDiscoveryBuilder::for_node(), and publish discovery + availability lazily on first sight of each node_id, routing state to per-node topics. Heartbeat/refresh/offline-LWT iterate all known nodes. Result: N distinct HA devices, one per node. 3 new unit tests (distinct nodes -> distinct wifi_densepose_<node> identifiers); full MQTT suite 71 passed, example builds.
…898 After the per-node discovery change, discovery configs are published the first time a snapshot for a node_id arrives (not eagerly at startup). The two discovery integration tests (discovery_topics_appear_on_broker, privacy_mode_suppresses_biometric_discovery) spawned the publisher with an empty broadcast channel and never sent a snapshot, so they collected [] and failed ("missing presence discovery topic in []"). Drive snapshots for the test node_id throughout the capture window (same pattern as state_messages_published_on_snapshot_broadcast) so the per-node device's discovery lands. Verified against a local mosquitto: 3 passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (#898)
After the #872 MQTT wiring shipped,
--mqttworks but every node collapses into a single Home-Assistant device (identifiers:["wifi_densepose_wifi-densepose-1"]), contradictingdocs/integrations/home-assistant.md("one device per RuView node"). Root cause: the JSON→VitalsSnapshotbridge hard-coded a singlenode_id(the MQTT client id), and the publisher used oneOwnedDiscoveryBuilder.Fix
main.rs): emit oneVitalsSnapshotper node in the sensing update'snodes[]— each with its ownnode_id+ RSSI (shared aggregate presence/vitals) — falling back to a single aggregate snapshot for wifi/simulate sources.publisher.rs): addOwnedDiscoveryBuilder::for_node(); publish discovery + availability lazily on first sight of eachnode_id, route state to per-node topics, and iterate all known nodes for heartbeat/refresh/offline-LWT → N distinct HA devices.Tests
3 new unit tests (distinct nodes → distinct
wifi_densepose_<node>identifiers; stable identity for repeat snapshots). Full MQTT suite 71 passed, example builds.🤖 Generated with claude-flow