Fix check on non numeric custom sensor device classes#89052
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
|
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
|
I am not sure I agree with this.
I think the current check is correct - you should NOT be allowed to set a custom UOM or suggested_display_precision on a timestamp sensor. I am not sure how best to fix it - but IMO this is not the correct way. |
|
Can you maybe add some tests to make it clearer? |
It is about the empty uom , but I think the same applies to state_class |
|
@epenet the problem being fixed is not that the unit of measurement is the empty string. The problem being fixed is that the order of checks in If we think it adds value to again change the order of the checks in |
emontnemery
left a comment
There was a problem hiding this comment.
Looks good, but we should consider adding a test.
I think we should add a comment in the code to make the link explicit then. |
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Custom device classes are not numeric * Update homeassistant/components/sensor/__init__.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Add test * Update homeassistant/components/sensor/__init__.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --------- Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Proposed change
Update
SensorEntity._numeric_state_expectedto matchSensorEntity.stateThis fixes an issue a where an invalid
native_unit_of_measurementsetting,state_classorsuggested_display_precisionhas priority over a valid device class which is not numeric.If for example a sensor has a
timestampdevice class and a custom UOM (or "") the sensor should be treated as not numeric.Type of change
Additional information
Checklist
black --fast 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: