Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions reolink/camera_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def __init__(
self._api_version_getrec: int = 0
self._api_version_getftp: int = 0
self._api_version_getpush: int = 0
self._api_version_getemail: int = 1
self._api_version_getalarm: int = 0

self.refresh_base_url()
Expand Down Expand Up @@ -452,6 +453,11 @@ async def get_states(self, cmd_list=None):
else:
body.append({"cmd": "GetAudioAlarmV20", "action": 1, "param": {"channel": self._channel}})

if self._api_version_getemail == 0:
body.append({"cmd": "GetEmail", "action": 1, "param": {"channel": self._channel}})
else:
body.append({"cmd": "GetEmailV20", "action": 1, "param": {"channel": self._channel}})

if cmd_list is not None:
for x, line in enumerate(body):
if line["cmd"] not in cmd_list:
Expand Down Expand Up @@ -517,6 +523,8 @@ async def get_settings(self):
body.append({"cmd": "GetRecV20", "action": 1, "param": {"channel": self._channel}})
if self._api_version_getalarm == 1:
body.append({"cmd": "GetAudioAlarmV20", "action": 1, "param": {"channel": self._channel}})
if self._api_version_getemail == 1:
body.append({"cmd": "GetEmailV20", "action": 1, "param": {"channel": self._channel}})

response = await self.send(body)
try:
Expand Down Expand Up @@ -550,6 +558,10 @@ def check_command_exists(cmd: str):
if not check_command_exists("GetAudioAlarmV20"):
self._api_version_getalarm = 0

if self._api_version_getemail == 1:
if not check_command_exists("GetEmailV20"):
self._api_version_getemail = 0

return True

async def get_motion_state(self):
Expand Down Expand Up @@ -769,9 +781,11 @@ def map_json_response(self, json_data): # pylint: disable=too-many-branches
elif data["cmd"] == "GetRec":
self._recording_settings = data
self._recording_state = (data["value"]["Rec"]["schedule"]["enable"] == 1)

elif data["cmd"] == "GetRecV20":
self._recording_settings = data
self._recording_state = (data["value"]["Rec"]["enable"] == 1)

elif data["cmd"] == "GetPtzPreset":
self._ptz_presets_settings = data
for preset in data["value"]["PtzPreset"]:
Expand Down Expand Up @@ -821,6 +835,12 @@ def map_json_response(self, json_data): # pylint: disable=too-many-branches
elif data["cmd"] == "GetZoomFocus":
self._zoom_focus_settings = data

elif data["cmd"] == "GetEmailV20":
self._email_settings = data
self._email_state = (
data["value"]["Email"]["enable"] == 1
)

except Exception as e: # pylint: disable=bare-except
_LOGGER.error(traceback.format_exc())
continue
Expand Down Expand Up @@ -1199,10 +1219,12 @@ async def set_email(self, enable):
else:
new_value = 0

body = [
{"cmd": "SetEmail", "action": 0, "param": self._email_settings["value"]}
]
body[0]["param"]["Email"]["schedule"]["enable"] = new_value
if self._api_version_getemail == 0:
body = [{"cmd": "SetEmail", "action": 0, "param": self._email_settings["value"]}]
body[0]["param"]["Email"]["schedule"]["enable"] = new_value
else:
body = [{"cmd": "SetEmailV20", "action": 0, "param": self._email_settings["value"]}]
body[0]["param"]["Email"]["enable"] = new_value

return await self.send_setting(body)

Expand Down