From bbbe1ddb78b1c1e7643fb711ca7fc1b8467b1740 Mon Sep 17 00:00:00 2001 From: Christophe Painchaud Date: Mon, 1 Nov 2021 09:22:43 +0100 Subject: [PATCH] fix for GetRec SetRec --- reolink/camera_api.py | 31 ++++++++++++++++++++++--------- setup.py | 2 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/reolink/camera_api.py b/reolink/camera_api.py index b788c1d..d98b12e 100644 --- a/reolink/camera_api.py +++ b/reolink/camera_api.py @@ -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): @@ -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 @@ -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: @@ -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"]: @@ -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"]} diff --git a/setup.py b/setup.py index 1662c7b..abce458 100644 --- a/setup.py +++ b/setup.py @@ -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',