Implement entity merge strategy for Meshtastic mesh nodes#78
Merged
Conversation
… and position Meshtastic sends position, nodeinfo, and telemetry as separate MQTT messages. Because publish_entity did a full Redis SET and the DB ON CONFLICT clause fully replaced display_name and identity, a position update would overwrite the human name set by nodeinfo (e.g. "K5ABC" → "!12345678"), and nodeinfo would wipe the lat/lon set by position. - bus.py: add merge=True option to publish_entity; performs a Redis GET+merge before writing, deep-merging the identity dict so partial updates only update the fields they provide - db.py: use COALESCE for display_name (NULL doesn't overwrite a good name) and the PostgreSQL || operator to merge the identity JSONB column instead of replacing it wholesale - meshtastic_mqtt.py: position and telemetry handlers drop display_name (not authoritative for names) and use merge=True; nodeinfo uses merge=True so it preserves existing lat/lon while setting the human name - meshcore_pymc.py: add altitude, status, and last_seen fields to entity dict for consistency with the other two mesh sources https://claude.ai/code/session_01C1LWuAM16EChKffhfZvAWd
… sources - mesh_node.py: add shared snr_to_quality() export so the formula is defined once; fix hw_model to emit None instead of "" when the model is unknown - meshtastic_mqtt.py: import snr_to_quality from the shared normalizer, removing the duplicate private copy - meshcore.py: import snr_to_quality; stamp signal_quality on the sending node's entity on every throttled packet event (merge=True so only that field changes); replace the hardcoded "local" node_a sentinel with the actual local node entity_id from _local_node_ids https://claude.ai/code/session_01C1LWuAM16EChKffhfZvAWd
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.
Summary
Adds a merge mode to entity publishing that preserves existing entity data while selectively updating fields with new values. This enables incremental updates to mesh node entities from multiple Meshtastic message types (position, nodeinfo, telemetry) without losing previously-observed attributes.
Key Changes
poller/bus.py: Addedmergeparameter topublish_entity()that performs intelligent field merging:Nonevalues (only non-null fields update)identitydicts (new non-None keys win, existing keys preserved)poller/normalizers/meshtastic_mqtt.py: Updated all three mesh node handlers to usemerge=True:_handle_position(): Removed hardcodeddisplay_namefield; now merges position data_handle_nodeinfo(): Enabled merge mode for identity updates_handle_telemetry(): Removed redundantdisplay_name,lat,lonfields; enabled merge modepoller/db.py: Updatedwrite_entity_observation()SQL to preserve existing data:display_name: UsesCOALESCE()to keep existing value if new is NULLidentity: Uses PostgreSQL||operator for JSONB merge instead of replacementpoller/pollers/meshcore_pymc.py: Addedaltitudeandstatusfields to contact entity template for consistency with other mesh node sourcesImplementation Details
The merge strategy allows Meshtastic handlers to publish partial entity updates without clobbering data from other message types. For example:
All updates flow through the same entity_id, and the merge logic ensures each handler's contribution is preserved across multiple publishes.
https://claude.ai/code/session_01C1LWuAM16EChKffhfZvAWd