fix: normalize negative precision to sentinel in set_precision - #136
Draft
bluetoothbot wants to merge 2 commits into
Draft
fix: normalize negative precision to sentinel in set_precision#136bluetoothbot wants to merge 2 commits into
bluetoothbot wants to merge 2 commits into
Conversation
set_precision() guarded `precision < 0` to fall back to the _PRECISION_SENTINEL, but the assignment was immediately overwritten by the unconditional `self._precision = precision`. A negative precision other than -1 (e.g. -2) was therefore stored verbatim, and update_sensor later called round(value, -2), rounding native float values to the nearest hundred instead of disabling rounding. Add an early return so any negative precision normalizes to the sentinel and float values pass through unrounded. Covered by two regression tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #136 +/- ##
==========================================
+ Coverage 94.37% 94.80% +0.42%
==========================================
Files 12 12
Lines 480 481 +1
Branches 5 5
==========================================
+ Hits 453 456 +3
+ Misses 26 25 -1
+ Partials 1 0 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
What
SensorData.set_precision()now disables rounding for any negative precision, instead of silently storing the negative value.Why
The
precision < 0guard setself._precision = _PRECISION_SENTINEL, but the next line unconditionally overwrote it withself._precision = precision. Soset_precision(-2)stored-2, andupdate_sensor()then calledround(value, -2)— rounding native float values to the nearest 100 (e.g.30.32 → 0.0). Only the sentinel value-1happened to behave correctly by coincidence.How
Added an early
returnafter assigning the sentinel, so the unconditional assignment is only reached for non-negative precision. One-line fix; intent of the existing guard preserved.Testing
test_negative_precision_disables_rounding—set_precision(-2)leaves the value unrounded.test_negative_precision_after_positive_precision— switching from2to-5turns rounding back off andprecisionreports the sentinel.mainand pass with the fix. Full suite: 10 passed.🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 56 insertions(+)
Code scan: clean
Tests: passed (10 passed)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline