From 3d75befe0a986d3905aaee5032964f9f9523c94d Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Mon, 20 Dec 2021 05:35:45 -0700 Subject: [PATCH] Replace SimpliSafe logged errors with `HomeAssistantError` in service handlers (#62352) --- .../components/simplisafe/__init__.py | 13 ++++++++---- .../simplisafe/alarm_control_panel.py | 20 +++++++++---------- homeassistant/components/simplisafe/lock.py | 11 ++++++---- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index 025c3a3ae49..b188b7309d8 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -55,7 +55,11 @@ from homeassistant.const import ( Platform, ) from homeassistant.core import CoreState, Event, HomeAssistant, ServiceCall, callback -from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady +from homeassistant.exceptions import ( + ConfigEntryAuthFailed, + ConfigEntryNotReady, + HomeAssistantError, +) from homeassistant.helpers import ( aiohttp_client, config_validation as cv, @@ -368,7 +372,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: try: await func(call, system) except SimplipyError as err: - LOGGER.error("Error while executing %s: %s", func.__name__, err) + raise HomeAssistantError( + f'Error while executing "{call.service}": {err}' + ) from err return wrapper @@ -397,8 +403,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ) -> None: """Set one or more system parameters.""" if not isinstance(system, SystemV3): - LOGGER.error("Can only set system properties on V3 systems") - return + raise HomeAssistantError("Can only set system properties on V3 systems") await system.async_set_properties( {prop: value for prop, value in call.data.items() if prop != ATTR_DEVICE_ID} diff --git a/homeassistant/components/simplisafe/alarm_control_panel.py b/homeassistant/components/simplisafe/alarm_control_panel.py index ac3d4721ccb..43bcaee2059 100644 --- a/homeassistant/components/simplisafe/alarm_control_panel.py +++ b/homeassistant/components/simplisafe/alarm_control_panel.py @@ -41,6 +41,7 @@ from homeassistant.const import ( STATE_ALARM_TRIGGERED, ) from homeassistant.core import HomeAssistant, callback +from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import SimpliSafe, SimpliSafeEntity @@ -173,8 +174,9 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity): try: await self._system.async_set_off() except SimplipyError as err: - LOGGER.error('Error while disarming "%s": %s', self._system.system_id, err) - return + raise HomeAssistantError( + f'Error while disarming "{self._system.system_id}": {err}' + ) from err self._attr_state = STATE_ALARM_DISARMED self.async_write_ha_state() @@ -187,10 +189,9 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity): try: await self._system.async_set_home() except SimplipyError as err: - LOGGER.error( - 'Error while arming "%s" (home): %s', self._system.system_id, err - ) - return + raise HomeAssistantError( + f'Error while arming (home) "{self._system.system_id}": {err}' + ) from err self._attr_state = STATE_ALARM_ARMED_HOME self.async_write_ha_state() @@ -203,10 +204,9 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity): try: await self._system.async_set_away() except SimplipyError as err: - LOGGER.error( - 'Error while arming "%s" (away): %s', self._system.system_id, err - ) - return + raise HomeAssistantError( + f'Error while arming (away) "{self._system.system_id}": {err}' + ) from err self._attr_state = STATE_ALARM_ARMING self.async_write_ha_state() diff --git a/homeassistant/components/simplisafe/lock.py b/homeassistant/components/simplisafe/lock.py index 435b60af44b..14816cdd579 100644 --- a/homeassistant/components/simplisafe/lock.py +++ b/homeassistant/components/simplisafe/lock.py @@ -11,6 +11,7 @@ from simplipy.websocket import EVENT_LOCK_LOCKED, EVENT_LOCK_UNLOCKED, Websocket from homeassistant.components.lock import LockEntity 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 . import SimpliSafe, SimpliSafeEntity @@ -64,8 +65,9 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity): try: await self._device.async_lock() except SimplipyError as err: - LOGGER.error('Error while locking "%s": %s', self._device.name, err) - return + raise HomeAssistantError( + f'Error while locking "{self._device.name}": {err}' + ) from err self._attr_is_locked = True self.async_write_ha_state() @@ -75,8 +77,9 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity): try: await self._device.async_unlock() except SimplipyError as err: - LOGGER.error('Error while unlocking "%s": %s', self._device.name, err) - return + raise HomeAssistantError( + f'Error while unlocking "{self._device.name}": {err}' + ) from err self._attr_is_locked = False self.async_write_ha_state()