Set mqtt binary_sensor unavailable if expire_after specified (#34259)

* Set self._expired=True if expire_after specified

* Added test_expiration_on_discovery_and_discovery_update_of_binary_sensor to mqtt/test_binary_sensor.py

* Fixed flake8 error

* Fixed isort error
This commit is contained in:
Tom 2020-04-22 23:29:49 +02:00 committed by GitHub
parent a8cd7203df
commit d6ab36bf8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 98 additions and 6 deletions

View file

@ -119,7 +119,11 @@ class MqttBinarySensor(
self._sub_state = None
self._expiration_trigger = None
self._delay_listener = None
self._expired = None
expire_after = config.get(CONF_EXPIRE_AFTER)
if expire_after is not None and expire_after > 0:
self._expired = True
else:
self._expired = None
device_config = config.get(CONF_DEVICE)
MqttAttributes.__init__(self, config)