Poll state when Tasmota device becomes available (#41401)

This commit is contained in:
Erik Montnemery authored and GitHub committed 2020-10-08 11:17:23 +02:00
1 parent b51a160cce
commit 35287828bc
6 files changed
+163 -4

No files matched your search

+4 -2
View File
@@ -96,6 +96,8 @@ class TasmotaAvailability(TasmotaEntity):
@callback
def availability_updated(self, available: bool) -> None:
"""Handle updated availability."""
if available and not self._available:
self._tasmota_entity.poll_status()
self._available = available
self.async_write_ha_state()
@@ -103,13 +105,13 @@ class TasmotaAvailability(TasmotaEntity):
def async_mqtt_connected(self, _):
"""Update state on connection/disconnection to MQTT broker."""
if not self.hass.is_stopping:
if not mqtt_connected(self.hass):
self._available = False
self.async_write_ha_state()
@property
def available(self) -> bool:
"""Return if the device is available."""
if not mqtt_connected(self.hass) and not self.hass.is_stopping:
return False
return self._available