-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
Use display_precision if suggested_display_precision is None #110270
Use display_precision if suggested_display_precision is None #110270
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @rikroe 👍
Thanks for looking into it! I can look into that only later tonight if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rikroe @emontnemery
Proposed change
This PR fixes unit conversion behavior for sensors if
display_precision
is set (by the user) butsuggested_display_precision
(set by the integration) isNone
.Before, a
suggested_display_precision
ofNone
would always cause the converted value to be rounded to 0 decimal places.A
suggested_display_precision
of 0 does not show this behaviour.Example
native_value: 6
native_unit_of_measurement: L
display_precision: 2 (set in the entity settings via UI)
Converted to gallons:
value: 2.0 - but should be 1.59
native_unit_of_measurement: gal
Cause
This happens due to https://github.com/home-assistant/core/blob/dev/homeassistant/components/sensor/__init__.py#L702-L724 which falls back to deducing the required precision if no suggested precision or sensor option for display precision is set.
_sensor_option_display_precision
itself is set by_suggested_precision_or_none()
which until now only read the suggested precision and not what the user had stored.The added test case would fail without the changes to
components/sensor/__init__.py
as entity's state would be621.0
.Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: