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 #34 from fwestenberg/AI-motion-detection
Browse files Browse the repository at this point in the history
AI motion detection
  • Loading branch information
fwestenberg authored May 26, 2021
2 parents 5fa1fb4 + 99a1797 commit fabe24a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
40 changes: 36 additions & 4 deletions reolink/camera_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(
self._token = None
self._lease_time = None
self._motion_state = False
self._ai_state = None
self._device_info = None
self._hdd_info = None
self._ftp_state = None
Expand Down Expand Up @@ -143,6 +144,11 @@ def motion_state(self):
"""Return the motion state (polling)."""
return self._motion_state

@property
def ai_state(self):
"""Return the AI state."""
return self._ai_state

@property
def ftp_state(self):
"""Return the FTP state."""
Expand Down Expand Up @@ -385,6 +391,29 @@ async def get_motion_state(self):

return self._motion_state

async def get_ai_state(self):
"""Fetch the AI state."""
body = [{"cmd": "GetAiState", "action": 0, "param": {"channel": self._channel}}]

response = await self.send(body)
if response is None:
return False

try:
json_data = json.loads(response)

if json_data is None:
_LOGGER.error(
"Unable to get AI detection state at IP %s", self._host
)
return self._ai_state

await self.map_json_response(json_data)
except (TypeError, json.JSONDecodeError):
await self.clear_token()

return self._ai_state

async def get_still_image(self):
"""Get the still image."""
param = {"cmd": "Snap", "channel": self._channel}
Expand Down Expand Up @@ -434,7 +463,13 @@ async def map_json_response(self, json_data): # pylint: disable=too-many-branch
if data["code"] == 1: # -->Error, like "ability error"
continue

if data["cmd"] == "GetDevInfo":
if data["cmd"] == "GetMdState":
self._motion_state = json_data[0]["value"]["state"] == 1

elif data["cmd"] == "GetAiState":
self._ai_state = json_data[0]["value"]

elif data["cmd"] == "GetDevInfo":
self._device_info = data
self._serial = data["value"]["DevInfo"]["serial"]
self._device_name = data["value"]["DevInfo"]["name"]
Expand Down Expand Up @@ -504,9 +539,6 @@ async def map_json_response(self, json_data): # pylint: disable=too-many-branch
self._motion_detection_state = data["value"]["Alarm"]["enable"] == 1
self._sensitivity_presets = data["value"]["Alarm"]["sens"]

elif data["cmd"] == "GetMdState":
self._motion_state = json_data[0]["value"]["state"] == 1

elif data["cmd"] == "GetAbility":
for ability in data["value"]["Ability"]["abilityChn"]:
self._ptz_support = ability["ptzCtrl"]["permit"] != 0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
setup(
name = 'reolink',
packages = ['reolink'],
version = '0.0.18',
version = '0.0.19',
license='MIT',
description = 'Reolink camera package',
author = 'fwestenberg',
Expand Down

0 comments on commit fabe24a

Please sign in to comment.