Centralize wemo exception handling (#46705)

This commit is contained in:
Eric Severance 2021-02-17 14:36:39 -08:00 committed by GitHub
parent b2df9aaaf1
commit 8bee3cda37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 92 deletions

View file

@ -4,7 +4,6 @@ from datetime import timedelta
import logging
import math
from pywemo.ouimeaux_device.api.service import ActionException
import voluptuous as vol
from homeassistant.components.fan import SUPPORT_SET_SPEED, FanEntity
@ -138,7 +137,7 @@ class WemoHumidifier(WemoSubscriptionEntity, FanEntity):
def _update(self, force_update=True):
"""Update the device state."""
try:
with self._wemo_exception_handler("update status"):
self._state = self.wemo.get_state(force_update)
self._fan_mode = self.wemo.fan_mode
@ -152,13 +151,6 @@ class WemoHumidifier(WemoSubscriptionEntity, FanEntity):
if self.wemo.fan_mode != WEMO_FAN_OFF:
self._last_fan_on_mode = self.wemo.fan_mode
if not self._available:
_LOGGER.info("Reconnected to %s", self.name)
self._available = True
except ActionException as err:
_LOGGER.warning("Could not update status for %s (%s)", self.name, err)
self._available = False
def turn_on(
self,
speed: str = None,
@ -171,11 +163,8 @@ class WemoHumidifier(WemoSubscriptionEntity, FanEntity):
def turn_off(self, **kwargs) -> None:
"""Turn the switch off."""
try:
with self._wemo_exception_handler("turn off"):
self.wemo.set_state(WEMO_FAN_OFF)
except ActionException as err:
_LOGGER.warning("Error while turning off device %s (%s)", self.name, err)
self._available = False
self.schedule_update_ha_state()
@ -188,13 +177,8 @@ class WemoHumidifier(WemoSubscriptionEntity, FanEntity):
else:
named_speed = math.ceil(percentage_to_ranged_value(SPEED_RANGE, percentage))
try:
with self._wemo_exception_handler("set speed"):
self.wemo.set_state(named_speed)
except ActionException as err:
_LOGGER.warning(
"Error while setting speed of device %s (%s)", self.name, err
)
self._available = False
self.schedule_update_ha_state()
@ -211,24 +195,14 @@ class WemoHumidifier(WemoSubscriptionEntity, FanEntity):
elif target_humidity >= 100:
pywemo_humidity = WEMO_HUMIDITY_100
try:
with self._wemo_exception_handler("set humidity"):
self.wemo.set_humidity(pywemo_humidity)
except ActionException as err:
_LOGGER.warning(
"Error while setting humidity of device: %s (%s)", self.name, err
)
self._available = False
self.schedule_update_ha_state()
def reset_filter_life(self) -> None:
"""Reset the filter life to 100%."""
try:
with self._wemo_exception_handler("reset filter life"):
self.wemo.reset_filter_life()
except ActionException as err:
_LOGGER.warning(
"Error while resetting filter life on device: %s (%s)", self.name, err
)
self._available = False
self.schedule_update_ha_state()