88
99from homeassistant.config_entries import ConfigEntry
1010from homeassistant.core import HomeAssistant, callback
11+ from homeassistant.exceptions import PlatformNotReady
1112from homeassistant.helpers import device_registry as dr
1213from homeassistant.helpers.aiohttp_client import async_get_clientsession
1314from homeassistant.helpers.event import async_track_time_interval
@@ -36,9 +37,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
3637 )
3738
3839 try:
39- await api.connect()
40+ connected = await api.connect()
41+
42+ if not connected:
43+ _LOGGER.error("Unable to connect to Smile: %s",api.smile_status)
44+ raise PlatformNotReady
45+
46+ except Smile.PlugwiseError:
47+ _LOGGER.error("Error while communicating to device")
48+ raise PlatformNotReady
49+
4050 except asyncio.TimeoutError:
4151 _LOGGER.error("Timeout while connecting to Smile")
52+ raise PlatformNotReady
4253
4354 if api.smile_type == "power":
4455 update_interval = timedelta(seconds=10)
@@ -47,7 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
4758
4859 api.get_all_devices()
4960
50- _LOGGER.debug("Plugwise async update interval %s", update_interval)
61+ _LOGGER.debug("Async update interval %s", update_interval)
5162
5263 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
5364 "api": api,
@@ -56,7 +67,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
5667 ),
5768 }
5869
59- _LOGGER.debug("Plugwise gateway is %s", api.gateway_id)
70+ _LOGGER.debug("Gateway is %s", api.gateway_id)
6071 device_registry = await dr.async_get_registry(hass)
6172 device_registry.async_get_or_create(
6273 config_entry_id=entry.entry_id,
@@ -66,7 +77,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
6677 model=f"Smile {api.smile_name}",
6778 sw_version=api.smile_version[0],
6879 )
69- _LOGGER.debug("Plugwise device registry %s", result)
7080
7181 single_master_thermostat = api.single_master_thermostat()
7282 _LOGGER.debug("Single master thermostat = %s", single_master_thermostat)
@@ -148,14 +158,18 @@ def async_remove_listener(self, update_callback):
148158
149159 async def async_refresh_all(self, _now: Optional[int] = None) -> None:
150160 """Time to update."""
151- _LOGGER.debug("Plugwise Smile updating with interval: %s", self.update_interval)
161+ _LOGGER.debug("Smile updating with interval: %s", self.update_interval)
152162 if not self.listeners:
153- _LOGGER.error("Plugwise Smile has no listeners, not updating")
163+ _LOGGER.error("Smile has no listeners, not updating")
154164 return
155165
156- _LOGGER.debug("Plugwise Smile updating data using: %s", self.update_method)
166+ _LOGGER.debug("Smile updating data using: %s", self.update_method)
157167
158- await self.api.full_update_device()
168+ try:
169+ await self.api.full_update_device()
170+ except Smile.XMLDataMissingError as e:
171+ _LOGGER.error("Smile update failed")
172+ raise e
159173
160174 for update_callback in self.listeners:
161175 update_callback()
0 commit comments