Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace decimals with suggested_display_precision + remove rounding #408

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

P-R-O-C-H-Y
Copy link
Contributor

No description provided.

Copy link

codecov bot commented Mar 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.68%. Comparing base (07197ac) to head (3e2a470).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #408      +/-   ##
==========================================
- Coverage   96.68%   96.68%   -0.01%     
==========================================
  Files          61       61              
  Lines        9834     9831       -3     
==========================================
- Hits         9508     9505       -3     
  Misses        326      326              

☔ 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.

@@ -658,7 +654,7 @@ def formatter(self, value: int) -> int | float:

value = float(value * multiplier) / divisor
if value < 100 and divisor > 1:
return round(value, self._decimals)
return round(value, self._attr_suggested_display_precision)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the ElectricalMeasurement sensor, we effectively set:

  • _attr_suggested_display_precision = 1 if divisor > 1 and value < 100
  • _attr_suggested_display_precision = 0 otherwise

Home Assistant caches suggested_display_precision so I don't think we can dynamically change it.

Should we globally set the decimals to 1?

CC @TheJulianJES @dmulcahey

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default _attr_suggested_display_precision is 1, so keeping the round here as is now will keep it working the same as it was before.

@P-R-O-C-H-Y P-R-O-C-H-Y marked this pull request as ready for review April 2, 2025 12:02
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.

2 participants