Skip to content

Commit bc8a17b

Browse files
Improve error handling in update_devices method (#387)
* Improve error handling in update_devices method Handle exceptions when updating devices and log errors. * Fix mypy type narrowing in update_devices exception handling (#388) * Initial plan * Fix mypy type error in update_devices by checking BaseException instead of Exception Co-authored-by: Danielhiversen <650502+Danielhiversen@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Danielhiversen <650502+Danielhiversen@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Danielhiversen <650502+Danielhiversen@users.noreply.github.com>
1 parent b71352d commit bc8a17b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tibber/data_api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,12 @@ async def get_all_devices(self) -> dict[str, TibberDevice]:
306306
async def update_devices(self) -> dict[str, TibberDevice]:
307307
"""Update the devices."""
308308
tasks = [self.get_device(device.home_id, device.id) for device in self._devices.values()]
309-
for device in await asyncio.gather(*tasks, return_exceptions=False):
310-
if device is not None:
311-
self._devices[device.id] = device
309+
for result in await asyncio.gather(*tasks, return_exceptions=True):
310+
if isinstance(result, BaseException):
311+
_LOGGER.error("Error getting device %s", result)
312+
raise result
313+
if result is not None:
314+
self._devices[result.id] = result
312315
return self._devices
313316

314317
async def get_userinfo(self) -> dict[str, Any]:

0 commit comments

Comments
 (0)