Release the sensor hold as soon as a valid value arrives - #84
Merged
Conversation
The bridge sends invalid (zero) sensor values right after we subscribe, so we hold every value for `sensor_delay` seconds. That also delayed the correct values that arrive quickly. Keep holding zero values, but treat the first non-zero value as a real one: cancel the hold and emit it immediately. Subsequent values for that sensor (including zero) pass straight through. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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 bridge sends invalid (zero) sensor values right after we subscribe to a sensor, so we hold every value back for
sensor_delayseconds. That also delays the correct values that arrive quickly — all sensors stay silent for the full delay even when the bridge has already reported real data.Now we only hold zero values. The first non-zero value for a held sensor is treated as a real one: the hold timer is cancelled and the value is emitted immediately. Any later value for that sensor — including zero — passes straight through.
A sensor that only ever reports zero still behaves as before: the cached value is emitted when the hold expires. The timer is cancelled rather than left to fire, so
_unhold_sensordoesn't re-emit the value a second time.Tests
test_sensor_holdnow uses a zero value (it previously asserted that100was held, which is exactly the case that changed).test_sensor_hold_when_registered_after_connectreworded for the now-immediate emit.test_sensor_hold_released_on_valid_valuecovers the early release, pass-through of later zeros, and the absence of a duplicate emit on expiry.Full suite: 89 passed.
🤖 Generated with Claude Code