Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #63 from cpainchaud/main
Browse files Browse the repository at this point in the history
fix for GetRec SetRec
  • Loading branch information
cpainchaud authored Nov 1, 2021
2 parents 1c7c176 + bbbe1dd commit 140a9fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
31 changes: 22 additions & 9 deletions reolink/camera_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def __init__(
self._aiohttp_session: aiohttp.ClientSession = aiohttp.ClientSession(timeout=self._timeout,
connector=aiohttp.TCPConnector(verify_ssl=False))

self._api_version_getrec: int = 0

self.refresh_base_url()

def enable_https(self, enable: bool):
Expand Down Expand Up @@ -300,6 +302,10 @@ def session_active(self):
self._lease_time = None
return False

@property
def api_version_getrec(self):
return self._api_version_getrec

def clear_token(self):
"""Initialize the token and lease time."""
self._token = None
Expand Down Expand Up @@ -537,6 +543,8 @@ def map_json_response(self, json_data): # pylint: disable=too-many-branches

push_data = None
pushv20_data = None
rec_data = None
recv20_data = None

for data in json_data:
try:
Expand Down Expand Up @@ -610,15 +618,19 @@ def map_json_response(self, json_data): # pylint: disable=too-many-branches
self._ir_state = data["value"]["IrLights"]["state"] == "Auto"

elif data["cmd"] == "GetRec":
self._recording_settings = data
self._recording_state = (
data["value"]["Rec"]["schedule"]["enable"] == 1
)
if self._api_version_getrec <= 1:
self._api_version_getrec = 1
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
)
if self._api_version_getrec <= 20:
self._api_version_getrec = 20
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 @@ -883,11 +895,12 @@ async def set_recording(self, enable):
else:
new_value = 0

if self._recording_settings["value"]["Rec"].get("enable") is not None:
if self._api_version_getrec <= 1:
body = [
{"cmd": "SetRecV20", "action": 0, "param": self._recording_settings["value"]}
]
body[0]["param"]["Rec"]["enable"] = new_value

else:
body = [
{"cmd": "SetRec", "action": 0, "param": self._recording_settings["value"]}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='reolink',
packages=['reolink'],
version='0.0.39',
version='0.0.40',
license='MIT',
description='Reolink camera package',
author='fwestenberg',
Expand Down

0 comments on commit 140a9fa

Please sign in to comment.