Skip to content

Commit

Permalink
fix: handle and log errors while fetching serial number (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
EuleMitKeule authored Jan 13, 2024
1 parent 934df0a commit 3e67ef5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions custom_components/dbuezas_eq3btsmart/sensor.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down Expand Up @@ -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)},
Expand Down

0 comments on commit 3e67ef5

Please sign in to comment.