mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Ignore empty status update for mqtt number (#94800)
This commit is contained in:
parent
3e71b1daa4
commit
4def901ecc
@ -186,6 +186,9 @@ class MqttNumber(MqttEntity, RestoreNumber):
|
||||
"""Handle new MQTT messages."""
|
||||
num_value: int | float | None
|
||||
payload = str(self._value_template(msg.payload))
|
||||
if not payload.strip():
|
||||
_LOGGER.debug("Ignoring empty state update from '%s'", msg.topic)
|
||||
return
|
||||
try:
|
||||
if payload == self._config[CONF_PAYLOAD_RESET]:
|
||||
num_value = None
|
||||
|
@ -189,6 +189,14 @@ async def test_value_template(
|
||||
state = hass.states.get("number.test_number")
|
||||
assert state.state == "10"
|
||||
|
||||
# Assert an empty value from a template is ignored
|
||||
async_fire_mqtt_message(hass, topic, '{"other_val":12}')
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("number.test_number")
|
||||
assert state.state == "10"
|
||||
|
||||
async_fire_mqtt_message(hass, topic, '{"val":20.5}')
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
Loading…
x
Reference in New Issue
Block a user