From 4af2854724dc5a621ac434af0e3759041aeec4a1 Mon Sep 17 00:00:00 2001 From: TheYOSH Date: Mon, 6 Jan 2025 23:13:53 +0100 Subject: [PATCH] Continue loading when Kasa relay fails. #977 --- hardware/relay/kasa_relay.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hardware/relay/kasa_relay.py b/hardware/relay/kasa_relay.py index 7c2960aff..bd8b9c71e 100644 --- a/hardware/relay/kasa_relay.py +++ b/hardware/relay/kasa_relay.py @@ -16,6 +16,7 @@ class terrariumRelayTPLinkKasa(terrariumRelay): URL = "^\d{1,3}\.\d{1,3}\.\d{1,3}(,\d{1,3})?$" def _load_hardware(self): + self._device["device"] = None # Input format should be either: # - [IP],[POWER_SWITCH_NR] @@ -24,12 +25,15 @@ def _load_hardware(self): self.__asyncio = terrariumAsync() address = self._address - if len(address) == 1: - self._device["device"] = SmartPlug(address[0]) - self._device["switch"] = 0 - else: - self._device["device"] = SmartStrip(address[0]) - self._device["switch"] = int(address[1]) - 1 + try: + if len(address) == 1: + self._device["device"] = SmartPlug(address[0]) + self._device["switch"] = 0 + else: + self._device["device"] = SmartStrip(address[0]) + self._device["switch"] = int(address[1]) - 1 + except Exception as ex: + logger.error(f"Error loading {self} at address {address[0]}: {ex}") return self._device["device"]