Add missing exception handlers to radiotherm (#73349)

This commit is contained in:
J. Nick Koston 2022-06-11 09:31:25 -10:00 committed by GitHub
parent cb1011156d
commit 8c96845135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from collections.abc import Coroutine from collections.abc import Coroutine
from socket import timeout from socket import timeout
from typing import Any, TypeVar from typing import Any, TypeVar
from urllib.error import URLError
from radiotherm.validate import RadiothermTstatError from radiotherm.validate import RadiothermTstatError
@ -31,6 +32,9 @@ async def _async_call_or_raise_not_ready(
except RadiothermTstatError as ex: except RadiothermTstatError as ex:
msg = f"{host} was busy (invalid value returned): {ex}" msg = f"{host} was busy (invalid value returned): {ex}"
raise ConfigEntryNotReady(msg) from ex raise ConfigEntryNotReady(msg) from ex
except (OSError, URLError) as ex:
msg = f"{host} connection error: {ex}"
raise ConfigEntryNotReady(msg) from ex
except timeout as ex: except timeout as ex:
msg = f"{host} timed out waiting for a response: {ex}" msg = f"{host} timed out waiting for a response: {ex}"
raise ConfigEntryNotReady(msg) from ex raise ConfigEntryNotReady(msg) from ex

View File

@ -4,6 +4,7 @@ from __future__ import annotations
import logging import logging
from socket import timeout from socket import timeout
from typing import Any from typing import Any
from urllib.error import URLError
from radiotherm.validate import RadiothermTstatError from radiotherm.validate import RadiothermTstatError
import voluptuous as vol import voluptuous as vol
@ -29,7 +30,7 @@ async def validate_connection(hass: HomeAssistant, host: str) -> RadioThermInitD
"""Validate the connection.""" """Validate the connection."""
try: try:
return await async_get_init_data(hass, host) return await async_get_init_data(hass, host)
except (timeout, RadiothermTstatError) as ex: except (timeout, RadiothermTstatError, URLError, OSError) as ex:
raise CannotConnect(f"Failed to connect to {host}: {ex}") from ex raise CannotConnect(f"Failed to connect to {host}: {ex}") from ex

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta from datetime import timedelta
import logging import logging
from socket import timeout from socket import timeout
from urllib.error import URLError
from radiotherm.validate import RadiothermTstatError from radiotherm.validate import RadiothermTstatError
@ -38,6 +39,9 @@ class RadioThermUpdateCoordinator(DataUpdateCoordinator[RadioThermUpdate]):
except RadiothermTstatError as ex: except RadiothermTstatError as ex:
msg = f"{self._description} was busy (invalid value returned): {ex}" msg = f"{self._description} was busy (invalid value returned): {ex}"
raise UpdateFailed(msg) from ex raise UpdateFailed(msg) from ex
except (OSError, URLError) as ex:
msg = f"{self._description} connection error: {ex}"
raise UpdateFailed(msg) from ex
except timeout as ex: except timeout as ex:
msg = f"{self._description}) timed out waiting for a response: {ex}" msg = f"{self._description}) timed out waiting for a response: {ex}"
raise UpdateFailed(msg) from ex raise UpdateFailed(msg) from ex