From 443003795bd4b3342c6a62162a104f554f15ee59 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Sun, 19 Dec 2021 14:14:08 -0700 Subject: [PATCH] Replace Guardian logged errors with HomeAssistantError in service handlers (#62342) --- homeassistant/components/guardian/__init__.py | 5 ++++- homeassistant/components/guardian/switch.py | 9 ++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/guardian/__init__.py b/homeassistant/components/guardian/__init__.py index f91c667bfbd..55af1619da5 100644 --- a/homeassistant/components/guardian/__init__.py +++ b/homeassistant/components/guardian/__init__.py @@ -21,6 +21,7 @@ from homeassistant.const import ( Platform, ) from homeassistant.core import HomeAssistant, ServiceCall, callback +from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import ( config_validation as cv, device_registry as dr, @@ -203,7 +204,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async with client: await func(call, client) except GuardianError as err: - LOGGER.error("Error while executing %s: %s", func.__name__, err) + raise HomeAssistantError( + f"Error while executing {func.__name__}: {err}" + ) from err return wrapper diff --git a/homeassistant/components/guardian/switch.py b/homeassistant/components/guardian/switch.py index 17e28c1901a..9a4f70fd3d2 100644 --- a/homeassistant/components/guardian/switch.py +++ b/homeassistant/components/guardian/switch.py @@ -9,11 +9,12 @@ from aioguardian.errors import GuardianError from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback +from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from . import ValveControllerEntity -from .const import API_VALVE_STATUS, DATA_CLIENT, DATA_COORDINATOR, DOMAIN, LOGGER +from .const import API_VALVE_STATUS, DATA_CLIENT, DATA_COORDINATOR, DOMAIN ATTR_AVG_CURRENT = "average_current" ATTR_INST_CURRENT = "instantaneous_current" @@ -97,8 +98,7 @@ class ValveControllerSwitch(ValveControllerEntity, SwitchEntity): async with self._client: await self._client.valve.close() except GuardianError as err: - LOGGER.error("Error while closing the valve: %s", err) - return + raise HomeAssistantError(f"Error while closing the valve: {err}") from err self._attr_is_on = False self.async_write_ha_state() @@ -109,8 +109,7 @@ class ValveControllerSwitch(ValveControllerEntity, SwitchEntity): async with self._client: await self._client.valve.open() except GuardianError as err: - LOGGER.error("Error while opening the valve: %s", err) - return + raise HomeAssistantError(f"Error while opening the valve: {err}") from err self._attr_is_on = True self.async_write_ha_state()