mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Allow null
/ None
value for non numeric mqtt sensor without warnings (#127032)
Allow `null` / `None` value for mqtt sensor without warnings
This commit is contained in:
parent
17c3e7b238
commit
b573e5a2b3
@ -260,14 +260,18 @@ class MqttSensor(MqttEntity, RestoreSensor):
|
||||
msg.topic,
|
||||
)
|
||||
return
|
||||
|
||||
if payload == PAYLOAD_NONE:
|
||||
self._attr_native_value = None
|
||||
return
|
||||
|
||||
if self._numeric_state_expected:
|
||||
if payload == "":
|
||||
_LOGGER.debug("Ignore empty state from '%s'", msg.topic)
|
||||
elif payload == PAYLOAD_NONE:
|
||||
self._attr_native_value = None
|
||||
else:
|
||||
self._attr_native_value = payload
|
||||
return
|
||||
|
||||
if self.options and payload not in self.options:
|
||||
_LOGGER.warning(
|
||||
"Ignoring invalid option received on topic '%s', got '%s', allowed: %s",
|
||||
|
@ -299,6 +299,17 @@ async def test_setting_sensor_to_long_state_via_mqtt_message(
|
||||
STATE_UNKNOWN,
|
||||
True,
|
||||
),
|
||||
(
|
||||
help_custom_config(
|
||||
sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
({"device_class": sensor.SensorDeviceClass.TIMESTAMP},),
|
||||
),
|
||||
sensor.SensorDeviceClass.TIMESTAMP,
|
||||
"None",
|
||||
STATE_UNKNOWN,
|
||||
False,
|
||||
),
|
||||
(
|
||||
help_custom_config(
|
||||
sensor.DOMAIN,
|
||||
|
Loading…
x
Reference in New Issue
Block a user