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 #47 from cpainchaud/main
Browse files Browse the repository at this point in the history
fix NVR crash with GetPush
  • Loading branch information
cpainchaud authored Oct 6, 2021
2 parents 97a6c90 + ca80bb3 commit b210518
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions reolink/camera_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def __init__(
self._local_link = None
self._ptz_support = False

self._is_nvr = False

@property
def host(self):
"""Return the host."""
Expand Down Expand Up @@ -335,9 +337,12 @@ async def get_states(self, cmd_list=None):
"param": {"Alarm": {"channel": self._channel, "type": "md"}},
},
{"cmd": "GetPushV20", "action": 1, "param": {"channel": self._channel}},
{"cmd": "GetPush", "action": 1, "param": {"channel": self._channel}},
]

if not self._is_nvr:
# NVR would crash without this
body.append({"cmd": "GetPush", "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 @@ -506,6 +511,7 @@ async def map_json_response(self, json_data): # pylint: disable=too-many-branch
self._model = data["value"]["DevInfo"]["model"]
self._channels = data["value"]["DevInfo"]["channelNum"]
self._sw_version_object = SoftwareVersion(self._sw_version)
self._is_nvr = data["value"]["DevInfo"].get("exactType", "CAM") == "NVR"

elif data["cmd"] == "GetHddInfo":
self._hdd_info = data["value"]["HddInfo"]
Expand Down Expand Up @@ -1024,6 +1030,9 @@ async def send_setting(self, body):
)
return False

def is_nvr(self):
return self._is_nvr

async def send(self, body, param=None):
"""Generic send method."""
if body is None or (body[0]["cmd"] != "Login" and body[0]["cmd"] != "Logout"):
Expand All @@ -1042,7 +1051,10 @@ async def send(self, body, param=None):
_LOGGER.debug("send()= HTTP Request params =%s", str(param).replace(self._password, "<password>"))
json_data = await response.read()
_LOGGER.debug("send HTTP Response status=%s", str(response.status))
_LOGGER_DATA.debug("send() HTTP Response data: %s", str(json_data))
if param.get("cmd") == "Snap":
_LOGGER_DATA.debug("send() HTTP Response data scrapped because it's too large")
else:
_LOGGER_DATA.debug("send() HTTP Response data: %s", json_data)

return json_data
else:
Expand All @@ -1054,7 +1066,10 @@ async def send(self, body, param=None):
_LOGGER.debug("send() HTTP Request body =%s", str(body).replace(self._password, "<password>"))
json_data = await response.text()
_LOGGER.debug("send() HTTP Response status=%s", str(response.status))
_LOGGER_DATA.debug("send() HTTP Response data: %s", str(json_data))
if param.get("cmd") == "Search" and len(json_data) > 500:
_LOGGER_DATA.debug("send() HTTP Response data scrapped because it's too large")
else:
_LOGGER_DATA.debug("send() HTTP Response data: %s", json_data)
return json_data

except aiohttp.ClientConnectorError as conn_err:
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.25',
version='0.0.26',
license='MIT',
description='Reolink camera package',
author='fwestenberg',
Expand Down

0 comments on commit b210518

Please sign in to comment.