From 3e67ef5f2df9e597a9de4e3b9dc8e5b289c0e292 Mon Sep 17 00:00:00 2001 From: Lennard Beers Date: Sat, 13 Jan 2024 22:51:18 +0100 Subject: [PATCH] fix: handle and log errors while fetching serial number (#85) --- custom_components/dbuezas_eq3btsmart/sensor.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/custom_components/dbuezas_eq3btsmart/sensor.py b/custom_components/dbuezas_eq3btsmart/sensor.py index 274f692..3e172c2 100644 --- a/custom_components/dbuezas_eq3btsmart/sensor.py +++ b/custom_components/dbuezas_eq3btsmart/sensor.py @@ -1,16 +1,17 @@ -from .const import CONF_DEBUG_MODE, DOMAIN import asyncio import json import logging -from homeassistant.helpers.device_registry import format_mac -from .python_eq3bt.eq3bt.eq3btsmart import Thermostat -from homeassistant.helpers.entity import DeviceInfo, EntityCategory from homeassistant.components.sensor import SensorEntity -from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr +from homeassistant.helpers.device_registry import format_mac +from homeassistant.helpers.entity import DeviceInfo, EntityCategory +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from .const import CONF_DEBUG_MODE, DOMAIN +from .python_eq3bt.eq3bt.eq3btsmart import Thermostat _LOGGER = logging.getLogger(__name__) @@ -119,7 +120,12 @@ async def async_added_to_hass(self) -> None: asyncio.get_event_loop().create_task(self.fetch_serial()) async def fetch_serial(self): - await self._thermostat.async_query_id() + try: + await self._thermostat.async_query_id() + except Exception as e: + _LOGGER.error(f"[{self._thermostat.name}] Error fetching serial number: {e}") + return + device_registry = dr.async_get(self.hass) device = device_registry.async_get_device( identifiers={(DOMAIN, self._thermostat.mac)},