Skip to content

fix: normalize negative precision to sentinel in set_precision - #136

Draft
bluetoothbot wants to merge 2 commits into
Bluetooth-Devices:mainfrom
bluetoothbot:koan/fix-negative-precision
Draft

fix: normalize negative precision to sentinel in set_precision#136
bluetoothbot wants to merge 2 commits into
Bluetooth-Devices:mainfrom
bluetoothbot:koan/fix-negative-precision

Conversation

@bluetoothbot

@bluetoothbot bluetoothbot commented May 23, 2026

Copy link
Copy Markdown

What

SensorData.set_precision() now disables rounding for any negative precision, instead of silently storing the negative value.

Why

The precision < 0 guard set self._precision = _PRECISION_SENTINEL, but the next line unconditionally overwrote it with self._precision = precision. So set_precision(-2) stored -2, and update_sensor() then called round(value, -2) — rounding native float values to the nearest 100 (e.g. 30.32 → 0.0). Only the sentinel value -1 happened to behave correctly by coincidence.

How

Added an early return after 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_roundingset_precision(-2) leaves the value unrounded.
  • test_negative_precision_after_positive_precision — switching from 2 to -5 turns rounding back off and precision reports the sentinel.
  • Verified both tests fail on main and 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

bluetoothbot and others added 2 commits May 23, 2026 16:33
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

codecov Bot commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.80%. Comparing base (31bd826) to head (2843f26).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant