fix(mqtt): per-node HA devices use each node's own presence/motion (#872)#918
Merged
Conversation
) The MQTT bridge fanned out one Home-Assistant device per node (#898) but applied the *room-level aggregate* classification to every node — so in a multi-node setup a node in an empty corner inherited another node's "present", and `motion_level: "absent"` was mis-mapped to full motion (the aggregate match fell through `Some(_) => 1.0`). Each node in the sensing broadcast's `nodes` array already carries its own `classification` (`motion_level`/`presence`/`confidence`, see PerNodeFeatureInfo) and RSSI. Now each per-node snapshot reads that node's own classification, deferring to the room aggregate only for fields a node omits. Vitals (breathing/heart rate) and person count stay room-level. Extracted the JSON→VitalsSnapshot mapping into a pure, testable function (`vitals_snapshots_from_sensing_json`) and added 4 unit tests covering per-node divergence, partial-field fallback, the no-nodes aggregate path, and the absent→zero-motion fix. Supersedes #899, which targeted the right bug but read non-existent fields (`node["motion_level"]` / `node["status"]` instead of the nested `node["classification"]` + `stale`). Verified: builds with `--features mqtt`; new tests pass; full crate unit suite 432 + 114 passed, 0 failed. Co-Authored-By: claude-flow <ruv@ruv.net>
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.
The bug
#898 made the MQTT bridge emit one Home-Assistant device per node, but it applied the room-level aggregate
classificationto every node:So on a multi-node deployment:
motion_level: "absent"was mis-mapped to full motion (the aggregate match had no"absent"arm, so it hitSome(_) => 1.0).The per-node data was already available — each entry in the broadcast
nodesarray is aPerNodeFeatureInfocarrying its ownclassification(motion_level/presence/confidence) andrssi_dbm.The fix
Extracted the JSON→
VitalsSnapshotmapping into a pure, testable functionvitals_snapshots_from_sensing_json(v, base_id)that:classification, deferring to the room aggregate only for fields a node omits;"absent"/"none"/"still"/"idle"→ zero motion;nodesarray (wifi/simulate).Tests (new)
4 unit tests under
mqtt_bridge_tests:per_node_presence_uses_each_nodes_own_classification— node 1 present+moving, node 2 absent → node 2 does not inherit the aggregateper_node_missing_fields_fall_back_to_aggregatefalls_back_to_single_aggregate_when_no_nodesabsent_motion_level_is_zero_motionVerification
cargo build -p wifi-densepose-sensing-server --no-default-features --features mqtt✓Supersedes #899
#899 targeted the same bug but read non-existent fields (
node["motion_level"],node["status"] == "active") instead of the nestednode["classification"]+stale, so it would have forced every node to "absent". Recommend closing #899 in favor of this.🤖 Generated with claude-flow