Fix handling None or empty value for numeric MQTT sensor#87004
Conversation
|
Hey there @emontnemery, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
None for numeric MQTT sensor, ignore empty valuesNone or empty value for numeric MQTT sensor
|
Note: it is a breaking change, but should it be considered for 2023.2 or are we too close to release? |
|
|
|
@epenet We will not add this to 2023.2, that allows us up update the sensor base class first as you suggested. Will set this PR to draft for now. |
d112266 to
e304566
Compare
81f9af9 to
7220ec7
Compare
|
|
7220ec7 to
45908ec
Compare
emontnemery
left a comment
There was a problem hiding this comment.
LGTM, thanks @jbouwh 👍
Breaking change
The behavior for receiving value on sensors that expect numeric* values has changed.
'None'value or a value rendered to'None'will set such a sensor sensor to anunknownstate.'') are ignored and will not effect the state of the sensor.Integrations need to be corrected to send the correct values if an update is published and no valid update value is available for the sensor.
* Sensors expect numeric values if at least one of the following applies:
device_classis set but is not aDATE,TIMESTAMP,ENUMor any custom device class.state_classis set.unit_of_measurementis set.suggested_display_precisionis set (Addsuggested_display_precisionconfig option for MQTT sensor #87129)Proposed change
MQTT sensors can accept string or numeric values. When
device_classis set a numeric value is expected. Many configurations usevalue_templateswhen getting a sensor value from a published JSON.When a sensor has no value, and the
device_classis set, this would give warnings in the log indicating an invalid non-numeric value was received.This PR will change the behavior for MQTT sensors that have a
device_classset and receive a value in two ways:''is returned from thevalue_templatefor a numeric sensor.unknown statewhenNoneas value us returned from thevalue template.This is needed to allow maintainers get rid of warnings about invalid non-numeric in values in the logs asking people to open an issue.
example log for value rendering to an empty state:
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: