Clean ezviz error handling in services (#51945)

This commit is contained in:
RenierM26 2021-06-17 08:30:19 +02:00 committed by GitHub
parent c8329032b2
commit fe26c34e87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -290,8 +290,7 @@ class EzvizCamera(CoordinatorEntity, Camera, RestoreEntity):
self.coordinator.ezviz_client.set_camera_defence(self._serial, 1) self.coordinator.ezviz_client.set_camera_defence(self._serial, 1)
except InvalidHost as err: except InvalidHost as err:
_LOGGER.error("Error enabling motion detection") raise InvalidHost("Error enabling motion detection") from err
raise InvalidHost from err
def disable_motion_detection(self): def disable_motion_detection(self):
"""Disable motion detection.""" """Disable motion detection."""
@ -299,8 +298,7 @@ class EzvizCamera(CoordinatorEntity, Camera, RestoreEntity):
self.coordinator.ezviz_client.set_camera_defence(self._serial, 0) self.coordinator.ezviz_client.set_camera_defence(self._serial, 0)
except InvalidHost as err: except InvalidHost as err:
_LOGGER.error("Error disabling motion detection") raise InvalidHost("Error disabling motion detection") from err
raise InvalidHost from err
@property @property
def unique_id(self): def unique_id(self):
@ -354,32 +352,30 @@ class EzvizCamera(CoordinatorEntity, Camera, RestoreEntity):
) )
except HTTPError as err: except HTTPError as err:
_LOGGER.error("Cannot perform PTZ") raise HTTPError("Cannot perform PTZ") from err
raise HTTPError from err
def perform_sound_alarm(self, enable): def perform_sound_alarm(self, enable):
"""Sound the alarm on a camera.""" """Sound the alarm on a camera."""
try: try:
self.coordinator.ezviz_client.sound_alarm(self._serial, enable) self.coordinator.ezviz_client.sound_alarm(self._serial, enable)
except HTTPError as err: except HTTPError as err:
_LOGGER.debug("Cannot sound alarm") raise HTTPError("Cannot sound alarm") from err
raise HTTPError from err
def perform_wake_device(self): def perform_wake_device(self):
"""Basically wakes the camera by querying the device.""" """Basically wakes the camera by querying the device."""
try: try:
self.coordinator.ezviz_client.get_detection_sensibility(self._serial) self.coordinator.ezviz_client.get_detection_sensibility(self._serial)
except (HTTPError, PyEzvizError) as err: except (HTTPError, PyEzvizError) as err:
_LOGGER.error("Cannot wake device") raise PyEzvizError("Cannot wake device") from err
raise PyEzvizError from err
def perform_alarm_sound(self, level): def perform_alarm_sound(self, level):
"""Enable/Disable movement sound alarm.""" """Enable/Disable movement sound alarm."""
try: try:
self.coordinator.ezviz_client.alarm_sound(self._serial, level, 1) self.coordinator.ezviz_client.alarm_sound(self._serial, level, 1)
except HTTPError as err: except HTTPError as err:
_LOGGER.error("Cannot set alarm sound level for on movement detected") raise HTTPError(
raise HTTPError from err "Cannot set alarm sound level for on movement detected"
) from err
def perform_set_alarm_detection_sensibility(self, level, type_value): def perform_set_alarm_detection_sensibility(self, level, type_value):
"""Set camera detection sensibility level service.""" """Set camera detection sensibility level service."""
@ -388,5 +384,4 @@ class EzvizCamera(CoordinatorEntity, Camera, RestoreEntity):
self._serial, level, type_value self._serial, level, type_value
) )
except (HTTPError, PyEzvizError) as err: except (HTTPError, PyEzvizError) as err:
_LOGGER.error("Cannot set detection sensitivity level") raise PyEzvizError("Cannot set detection sensitivity level") from err
raise PyEzvizError from err