From d3deaa6a82ce96618a25cc0b868d7f957f116a72 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 20 Aug 2024 10:33:02 +0200 Subject: [PATCH] Improve otbr error handling (#124277) --- homeassistant/components/otbr/config_flow.py | 6 +++++- homeassistant/components/otbr/util.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/otbr/config_flow.py b/homeassistant/components/otbr/config_flow.py index c13a3f36f99..8cffc0a99e6 100644 --- a/homeassistant/components/otbr/config_flow.py +++ b/homeassistant/components/otbr/config_flow.py @@ -168,7 +168,11 @@ class OTBRConfigFlow(ConfigFlow, domain=DOMAIN): try: await self._connect_and_set_dataset(url) - except python_otbr_api.OTBRError as exc: + except ( + python_otbr_api.OTBRError, + aiohttp.ClientError, + TimeoutError, + ) as exc: _LOGGER.warning("Failed to communicate with OTBR@%s: %s", url, exc) return self.async_abort(reason="unknown") diff --git a/homeassistant/components/otbr/util.py b/homeassistant/components/otbr/util.py index 16cf3b60e37..d426ca9ba17 100644 --- a/homeassistant/components/otbr/util.py +++ b/homeassistant/components/otbr/util.py @@ -9,6 +9,7 @@ import logging import random from typing import Any, Concatenate, cast +import aiohttp import python_otbr_api from python_otbr_api import PENDING_DATASET_DELAY_TIMER, tlv_parser from python_otbr_api.pskc import compute_pskc @@ -67,7 +68,7 @@ def _handle_otbr_error[**_P, _R]( async def _func(self: OTBRData, *args: _P.args, **kwargs: _P.kwargs) -> _R: try: return await func(self, *args, **kwargs) - except python_otbr_api.OTBRError as exc: + except (python_otbr_api.OTBRError, aiohttp.ClientError, TimeoutError) as exc: raise HomeAssistantError("Failed to call OTBR API") from exc return _func