-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
Fix removing suggested_display_precision from entity registry #110671
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
|
Why is it supposed to be removed? |
Well, strictly speaking, I don't think it absolutely needs to be removed in this case, but the registry does need to be updated to be consistent with the entity's suggested_display_precision. Currently, if the entity changes its suggested_display_precision from None to something other than None, the code will add it to the registry, and if it changes between two different non-None values, it updates the registry accordingly. However, if it changes from a non-None value to None, the bug is preventing it from updating the registry accordingly. That is what this PR fixes. I.e., it fixes the test that checks if the registry needs to be updated, not what the update does. As far as removing as opposed to just setting it to None (i.e., null in the JSON file), since this value is optional, it does make more sense to remove it rather than simply changing it. That is how the function is currently coded. This PR does not change that aspect of the code. It just allows it to run when it should. That is my interpretation. Maybe the original author, @emontnemery, has a different take on it. And, FWIW, although this bug has existed since it was originally added a year ago in #87614, it probably has not been noticed because 1) most sensor entities probably don't change their suggested_display_precision from a non-None value to None, and 2) the effect of the bug is really only now apparent due to a recent frontend change (home-assistant/frontend#19396) that was released w/ 2024.2. I noticed the bug when one of my custom sensor entities, which has a device_class of duration, changed its suggested_display_precision from 3 to None to compensate for the noted frontend change, yet the displayed value still wasn't formatted as HH:MM:SS. That's when I noticed core.entity_registry still had a suggested_display_precision of 3 for the entity instead of it being changed to null or removed. |
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
I still believe this is valid and would appreciate a review. |
e4eba8f
to
161dbda
Compare
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, @pnbruckner 👍
Proposed change
When a sensor entity's
suggested_display_precision
is changed toNone
from something else, it is supposed to be removed fromoptions
of the corresponding entry in the entity registry. However, the code that is supposed to do this (SensorEntity._update_suggested_precision
) has a bug that prevents it from doing so. This change fixes that bug.Some background can be found here: pnbruckner/ha-sun2#109
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: