Allow unknown state to be set (#65183)

This commit is contained in:
Jan Bouwhuis 2022-01-31 10:25:08 +01:00 committed by GitHub
parent f6b0f26783
commit bfaada34e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -49,6 +49,7 @@ DEFAULT_PAYLOAD_OFF = "OFF"
DEFAULT_PAYLOAD_ON = "ON"
DEFAULT_FORCE_UPDATE = False
CONF_EXPIRE_AFTER = "expire_after"
PAYLOAD_NONE = "None"
PLATFORM_SCHEMA = mqtt.MQTT_RO_PLATFORM_SCHEMA.extend(
{
@ -174,6 +175,8 @@ class MqttBinarySensor(MqttEntity, BinarySensorEntity):
self._state = True
elif payload == self._config[CONF_PAYLOAD_OFF]:
self._state = False
elif payload == PAYLOAD_NONE:
self._state = None
else: # Payload is not for this entity
template_info = ""
if self._config.get(CONF_VALUE_TEMPLATE) is not None:
@ -221,7 +224,7 @@ class MqttBinarySensor(MqttEntity, BinarySensorEntity):
self.async_write_ha_state()
@property
def is_on(self):
def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
return self._state