From a687c7715d24ce5052f9b27d85826973b210b2a0 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 10 Jul 2023 00:22:40 +0200 Subject: [PATCH] Set switches unavailable if not changable --- custom_components/hon/switch.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/custom_components/hon/switch.py b/custom_components/hon/switch.py index c37e299..bb93475 100644 --- a/custom_components/hon/switch.py +++ b/custom_components/hon/switch.py @@ -405,11 +405,16 @@ class HonSwitchEntity(HonEntity, SwitchEntity): @property def available(self) -> bool: """Return True if entity is available.""" - return ( - super().available - and int(self._device.get("remoteCtrValid", 1)) == 1 - and self._device.get("attributes.lastConnEvent.category") != "DISCONNECTED" - ) + if not super().available: + return False + if not self._device.get("remoteCtrValid", 1) == 1: + return False + if self._device.get("attributes.lastConnEvent.category") == "DISCONNECTED": + return False + setting = self._device.settings[f"settings.{self.entity_description.key}"] + if isinstance(setting, HonParameterRange) and len(setting.values) < 2: + return False + return True @callback def _handle_coordinator_update(self, update=True) -> None: