Skip to content

Commit

Permalink
Merge pull request #130 from BaQs/ezviz_retry_set_camera_defence
Browse files Browse the repository at this point in the history
Add retry to set camera defence, improve logging messages.
  • Loading branch information
RenierM26 authored Jul 10, 2023
2 parents 6847216 + 25f8c16 commit 27ac829
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
4 changes: 1 addition & 3 deletions pyezviz/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ def status(self) -> dict[Any, Any]:
"PIR_Status": self.fetch_key(["STATUS", "pirStatus"]),
"Motion_Trigger": self._alarmmotiontrigger["alarm_trigger_active"],
"Seconds_Last_Trigger": self._alarmmotiontrigger["timepassed"],
"last_alarm_time": self._last_alarm.get(
"alarmStartTimeStr", "2000-01-01 00:00:00"
),
"last_alarm_time": self._last_alarm.get("alarmStartTimeStr"),
"last_alarm_pic": self._last_alarm.get(
"picUrl",
"https://eustatics.ezvizlife.com/ovs_mall/web/img/index/EZVIZ_logo.png?ver=3007907502",
Expand Down
40 changes: 32 additions & 8 deletions pyezviz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,18 @@ def set_camera_defence(
) from err

if json_output["meta"]["code"] != 200:
raise PyEzvizError(f"Could not arm or disarm Camera: Got {json_output})")
if json_output["meta"]["code"] == 504:
_LOGGER.warning(
"Arm or disarm for camera %s timed out. Retrying %s of %s",
serial,
max_retries,
MAX_RETRIES,
)
return self.set_camera_defence(serial, enable, max_retries + 1)

raise PyEzvizError(
f"Could not arm or disarm Camera {serial}: Got {json_output})"
)

return True

Expand Down Expand Up @@ -735,9 +746,10 @@ def get_storage_status(self, serial: str, max_retries: int = 0) -> Any:
if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning(
"Can't get storage status from device %s, retrying %s",
"Can't get storage status from device %s, retrying %s of %s",
serial,
max_retries,
MAX_RETRIES,
)
return self.get_storage_status(serial, max_retries + 1)
raise PyEzvizError(
Expand Down Expand Up @@ -954,9 +966,10 @@ def reboot_camera(
if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning(
"Unable to reboot camera, camera %s is unreachable, retrying %s",
"Unable to reboot camera, camera %s is unreachable, retrying %s of %s",
serial,
max_retries,
MAX_RETRIES,
)
return self.reboot_camera(serial, delay, operation, max_retries + 1)
raise PyEzvizError(f"Could not reboot device {json_output})")
Expand Down Expand Up @@ -1225,9 +1238,10 @@ def get_cam_key(
if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning(
"Camera %s encryption key not found, retrying %s",
"Camera %s encryption key not found, retrying %s of %s",
serial,
max_retries,
MAX_RETRIES,
)
return self.get_cam_key(serial, smscode, max_retries + 1)
raise PyEzvizError(
Expand Down Expand Up @@ -1321,7 +1335,10 @@ def return_panoramic(self, serial: str, max_retries: int = 0) -> Any:
if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning(
"Camera %s busy or unreachable, retrying %s", serial, max_retries
"Camera %s busy or unreachable, retrying %s of %s",
serial,
max_retries,
MAX_RETRIES,
)
return self.return_panoramic(serial, max_retries + 1)
raise PyEzvizError(f"Could retrieve panoramic photo: Got {json_output})")
Expand Down Expand Up @@ -1528,7 +1545,10 @@ def api_set_defence_schedule(
if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning(
"Camara %s offline or unreachable, retrying %s", serial, max_retries
"Camara %s offline or unreachable, retrying %s of %s",
serial,
max_retries,
MAX_RETRIES,
)
return self.api_set_defence_schedule(
serial, schedule, enable, max_retries + 1
Expand Down Expand Up @@ -1727,9 +1747,10 @@ def detection_sensibility(
if response_json["resultCode"] != "0":
if response_json["resultCode"] == "-1":
_LOGGER.warning(
"Camera %s is offline, can't set sensitivity, retrying %s",
"Camera %s is offline or unreachable, can't set sensitivity, retrying %s of %s",
serial,
max_retries,
MAX_RETRIES,
)
return self.detection_sensibility(
serial, sensibility, type_value, max_retries + 1
Expand Down Expand Up @@ -1779,7 +1800,10 @@ def get_detection_sensibility(
if response_json["resultCode"] != "0":
if response_json["resultCode"] == "-1":
_LOGGER.warning(
"Camera %s is offline, retrying %s", serial, max_retries
"Camera %s is offline or unreachable, retrying %s of %s",
serial,
max_retries,
MAX_RETRIES,
)
return self.get_detection_sensibility(
serial, type_value, max_retries + 1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='pyezviz',
version="0.2.2.1",
version="0.2.2.2",
license='Apache Software License 2.0',
author='Pierre Ourdouille',
author_email='[email protected]',
Expand Down

0 comments on commit 27ac829

Please sign in to comment.