From 17d4d14eada45f4f1a86ef816b4168fccb04acbb Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sat, 13 May 2023 22:09:41 +0200 Subject: [PATCH] Show controls always unavailable when diconnected #43 --- custom_components/hon/button.py | 6 +++++- custom_components/hon/switch.py | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/custom_components/hon/button.py b/custom_components/hon/button.py index 1d4e85f..ce8f9d4 100644 --- a/custom_components/hon/button.py +++ b/custom_components/hon/button.py @@ -67,7 +67,11 @@ class HonButtonEntity(HonEntity, ButtonEntity): @property def available(self) -> bool: """Return True if entity is available.""" - return super().available and self._device.get("remoteCtrValid") == "1" + return ( + super().available + and self._device.get("remoteCtrValid") == "1" + and self._device.get("attributes.lastConnEvent.category") != "DISCONNECTED" + ) class HonFeatureRequestButton(HonEntity, ButtonEntity): diff --git a/custom_components/hon/switch.py b/custom_components/hon/switch.py index 2240491..af554cc 100644 --- a/custom_components/hon/switch.py +++ b/custom_components/hon/switch.py @@ -410,4 +410,9 @@ class HonSwitchEntity(HonEntity, SwitchEntity): if self.entity_category == EntityCategory.CONFIG: return super().available else: - return super().available and self._device.get("remoteCtrValid") == "1" + return ( + super().available + and self._device.get("remoteCtrValid") == "1" + and self._device.get("attributes.lastConnEvent.category") + != "DISCONNECTED" + )