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

Commit

Permalink
new function: get_all_motion_states
Browse files Browse the repository at this point in the history
  • Loading branch information
cpainchaud committed Oct 25, 2021
1 parent c0c30ae commit 81a6a82
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
27 changes: 22 additions & 5 deletions reolink/camera_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ async def get_states(self, cmd_list=None):

try:
json_data = json.loads(response)
await self.map_json_response(json_data)
self.map_json_response(json_data)
return True
except (TypeError, json.JSONDecodeError) as e:
_LOGGER.debug(
Expand Down Expand Up @@ -412,7 +412,7 @@ async def get_settings(self):

try:
json_data = json.loads(response)
await self.map_json_response(json_data)
self.map_json_response(json_data)
return True
except (TypeError, json.JSONDecodeError):
_LOGGER.debug(
Expand All @@ -439,7 +439,7 @@ async def get_motion_state(self):
self._motion_state = False
return self._motion_state

await self.map_json_response(json_data)
self.map_json_response(json_data)
except (TypeError, json.JSONDecodeError):
self.clear_token()
self._motion_state = False
Expand All @@ -463,12 +463,29 @@ async def get_ai_state(self):
)
return self._ai_state

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

return self._ai_state

async def get_all_motion_states(self):
"""Fetch All motions states at once (regular + AI)."""
body = [{"cmd": "GetMdState", "action": 0, "param": {"channel": self._channel}},
{"cmd": "GetAiState", "action": 0, "param": {"channel": self._channel}}]

response = await self.send(body)
json_data = json.loads(response)

if json_data is None:
_LOGGER.error(
"Unable to get All Motion States at IP %s", self._host
)
self._motion_state = False
return self._motion_state

self.map_json_response(json_data)

async def get_still_image(self):
"""Get the still image."""
param = {"cmd": "Snap", "channel": self._channel}
Expand Down Expand Up @@ -514,7 +531,7 @@ async def get_vod_source(self, filename: str):

return stream_source

async def map_json_response(self, json_data): # pylint: disable=too-many-branches
def map_json_response(self, json_data): # pylint: disable=too-many-branches
"""Map the JSON objects to internal objects and store for later use."""

push_data = None
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.36',
version='0.0.37',
license='MIT',
description='Reolink camera package',
author='fwestenberg',
Expand Down

0 comments on commit 81a6a82

Please sign in to comment.