Hold sensor values per sensor instead of per connection - #80
Merged
Conversation
The hold that works around the invalid sensor values the bridge sends on subscription was a single timer, started when the connection was set up. Sensors that are registered later (Home Assistant registers them from async_added_to_hass, after connect() returned) were only covered when their setup happened to finish within the hold. On a cold boot that takes longer, so the bogus 0 that the bridge sends leaked through to the callback. Give every sensor its own hold, started when we subscribe to it, and raise the default delay to 5 seconds. Fixes #67 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
michaelarnauts
force-pushed
the
fix-sensor-hold
branch
from
August 2, 2026 16:15
88f52a6 to
95c3993
Compare
This was referenced Aug 2, 2026
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 workaround for the invalid sensor values that the bridge sends when we subscribe to a sensor used a single timer, started when the connection was set up.
_sensor_callbackdropped everything while that timer was pending and_unhold_sensorsflushed the last cached value per sensor.That only covers sensors that are already subscribed when the timer starts. Home Assistant registers its sensors from
async_added_to_hass(), soregister_sensor()runs afterconnect()returned, and each call sends a freshcmd_rpdo_requestthat the bridge answers with a bogus0before the real value. When entity setup finishes within the hold the garbage is swallowed (the usual case), but on a cold boot setup takes longer than the hold, so the0reached the callback and polluted statistics.Every sensor now gets its own hold, started when we subscribe to it:
_hold_sensor()/_unhold_sensor()replace the global handle with_sensor_holds, keyed by PDID._reconnect_loop()holds all known sensors before re-issuing their RPDO requests, as before.register_sensor()holds the sensor before subscribing — this is the case that was unprotected.deregister_sensor()cancels a pending hold so a removed sensor cannot emit a late value.sensor_delaygoes from 2 to 5 seconds, to give slower bridges more room.sensor_delay=0still disables the mechanism entirely.test_sensor_hold_when_registered_after_connectcovers the regression: it connects, waits past the connect-time hold, registers a sensor and feeds it0followed by69. Without the hold inregister_sensor()it fails on the0leaking through.Fixes #67
🤖 Generated with Claude Code