From fed18fe1425971963822294247985888f6efdd85 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Sun, 19 Dec 2021 15:02:51 -0700 Subject: [PATCH] Replace OpenUV logged errors with `HomeAssistantError` in service handlers (#62349) Co-authored-by: Martin Hjelmare --- homeassistant/components/openuv/__init__.py | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/openuv/__init__.py b/homeassistant/components/openuv/__init__.py index a60414e2872..7a9ef1785b7 100644 --- a/homeassistant/components/openuv/__init__.py +++ b/homeassistant/components/openuv/__init__.py @@ -18,7 +18,7 @@ from homeassistant.const import ( Platform, ) from homeassistant.core import HomeAssistant, ServiceCall, callback -from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError from homeassistant.helpers import aiohttp_client from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, @@ -147,7 +147,7 @@ class OpenUV: """Initialize.""" self._entry = entry self.client = client - self.data: dict[str, Any] = {} + self.data: dict[str, Any] = {DATA_PROTECTION_WINDOW: {}, DATA_UV: {}} async def async_update_protection_data(self) -> None: """Update binary sensor (protection window) data.""" @@ -155,20 +155,24 @@ class OpenUV: high = self._entry.options.get(CONF_TO_WINDOW, DEFAULT_TO_WINDOW) try: - resp = await self.client.uv_protection_window(low=low, high=high) - self.data[DATA_PROTECTION_WINDOW] = resp["result"] + data = await self.client.uv_protection_window(low=low, high=high) except OpenUvError as err: - LOGGER.error("Error during protection data update: %s", err) - self.data[DATA_PROTECTION_WINDOW] = {} + raise HomeAssistantError( + f"Error during protection data update: {err}" + ) from err + + self.data[DATA_PROTECTION_WINDOW] = data["result"] async def async_update_uv_index_data(self) -> None: """Update sensor (uv index, etc) data.""" try: data = await self.client.uv_index() - self.data[DATA_UV] = data except OpenUvError as err: - LOGGER.error("Error during uv index data update: %s", err) - self.data[DATA_UV] = {} + raise HomeAssistantError( + f"Error during UV index data update: {err}" + ) from err + + self.data[DATA_UV] = data async def async_update(self) -> None: """Update sensor/binary sensor data."""