From 20b54c22f7338f18e2022667d7776040f3ba3b8e Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Mon, 5 Aug 2019 09:50:48 -0400 Subject: [PATCH] don't mark devices unavailable without ping try (#25710) --- homeassistant/components/zha/core/device.py | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index 1fe2e1a5e6c..1c22b41ce86 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -39,6 +39,7 @@ from .const import ( ATTR_QUIRK_CLASS, ATTR_RSSI, ATTR_VALUE, + CHANNEL_BASIC, CHANNEL_POWER_CONFIGURATION, CHANNEL_ZDO, CLUSTER_COMMAND_SERVER, @@ -57,6 +58,7 @@ from .helpers import LogMixin _LOGGER = logging.getLogger(__name__) _KEEP_ALIVE_INTERVAL = 7200 _UPDATE_ALIVE_INTERVAL = timedelta(seconds=60) +_CHECKIN_GRACE_PERIODS = 2 class DeviceStatus(Enum): @@ -81,6 +83,7 @@ class ZHADevice(LogMixin): self._available_signal = "{}_{}_{}".format( self.name, self.ieee, SIGNAL_AVAILABLE ) + self._checkins_missed_count = 2 self._unsub = async_dispatcher_connect( self.hass, self._available_signal, self.async_initialize ) @@ -204,9 +207,26 @@ class ZHADevice(LogMixin): else: difference = time.time() - self.last_seen if difference > _KEEP_ALIVE_INTERVAL: - self.update_available(False) + if self._checkins_missed_count < _CHECKIN_GRACE_PERIODS: + self._checkins_missed_count += 1 + if ( + CHANNEL_BASIC in self.cluster_channels + and self.manufacturer != "LUMI" + ): + self.debug( + "Attempting to checkin with device - missed checkins: %s", + self._checkins_missed_count, + ) + self.hass.async_create_task( + self.cluster_channels[CHANNEL_BASIC].get_attribute_value( + ATTR_MANUFACTURER, from_cache=False + ) + ) + else: + self.update_available(False) else: self.update_available(True) + self._checkins_missed_count = 0 def update_available(self, available): """Set sensor availability."""