From 2c2041cad5bb794f3947ad75f6942cd90b2c18f4 Mon Sep 17 00:00:00 2001 From: Mat931 <49403702+Mat931@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:02:56 +0100 Subject: [PATCH] Handle exceptions when a switch does not support reading the targetValue --- custom_components/digitalstrom/switch.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/custom_components/digitalstrom/switch.py b/custom_components/digitalstrom/switch.py index beecbfc..0349aa5 100644 --- a/custom_components/digitalstrom/switch.py +++ b/custom_components/digitalstrom/switch.py @@ -9,6 +9,7 @@ from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback +from .api.exceptions import ServerError from .const import CONF_DSUID, DOMAIN from .entity import DigitalstromEntity @@ -78,6 +79,7 @@ def __init__(self, channel): self._attr_has_entity_name = False self.entity_id = f"{DOMAIN}.{self.device.dsuid}_{channel.index}" self._attr_name = self.device.name + self.supports_target_value = True @property def is_on(self) -> bool | None: @@ -99,10 +101,15 @@ async def async_turn_off(self, **kwargs: Any) -> None: ) async def async_update(self, **kwargs: Any): - result = await self.client.request( - f"property/getFloating?path=/apartment/zones/zone{self.device.zone_id}/devices/{self.device.dsuid}/status/outputs/powerState/targetValue" - ) - self.last_value = result.get("value", None) + if not self.supports_target_value: + return + try: + result = await self.client.request( + f"property/getFloating?path=/apartment/zones/zone{self.device.zone_id}/devices/{self.device.dsuid}/status/outputs/powerState/targetValue" + ) + self.last_value = result.get("value", None) + except ServerError: + self.supports_target_value = False class DigitalstromApartmentScene(SwitchEntity):