Replace OpenUV logged errors with HomeAssistantError in service handlers (#62349)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Aaron Bach 2021-12-19 15:02:51 -07:00 committed by GitHub
parent dbb4c1b5f0
commit fed18fe142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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."""