Skip to content

Commit

Permalink
Get_host_data incomplete response, retry by sending separately
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Nov 3, 2023
1 parent 87a96ad commit c6e46a0
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions reolink_aio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,14 @@ async def get_host_data(self) -> None:
except NoDataError as err:
raise NoDataError(f"Host: {self._host}:{self._port}: returned no data when obtaining initial channel-settings") from err

self.map_channels_json_response(json_data, channels)
try:
self.map_channels_json_response(json_data, channels)
except UnexpectedDataError as err:
_LOGGER.debug("get_host_data: %s, retrying by sending each command separately", err)
json_data = []
for command in body:
json_data.extend(await self.send([command], expected_response_type="json"))
self.map_channels_json_response(json_data, channels)

# Let's assume all channels of an NVR or multichannel-camera always have the same versions of commands... Not sure though...
def check_command_exists(cmd: str) -> int:
Expand Down Expand Up @@ -1607,7 +1614,12 @@ async def get_ai_state_all_ch(self) -> bool:
)
return False

self.map_channels_json_response(json_data, channels)
try:
self.map_channels_json_response(json_data, channels)
except UnexpectedDataError as err:
_LOGGER.error("Error in get_ai_state_all_ch: %s", err)
return False

return True

async def get_all_motion_states(self, channel: int) -> Optional[bool]:
Expand Down Expand Up @@ -1695,7 +1707,12 @@ async def get_motion_state_all_ch(self) -> bool:
self._ai_detection_states[channel] = {}
return False

self.map_channels_json_response(json_data, channels)
try:
self.map_channels_json_response(json_data, channels)
except UnexpectedDataError as err:
_LOGGER.error("Error in get_motion_state_all_ch: %s", err)
return False

return True

async def _check_reolink_firmware(self) -> NewSoftwareVersion:
Expand Down Expand Up @@ -2175,14 +2192,9 @@ def map_host_json_response(self, json_data: typings.reolink_json):

def map_channels_json_response(self, json_data, channels: list[int]):
if len(json_data) != len(channels):
_LOGGER.error(
"Host %s:%s error mapping response to channels, received %i responses while requesting %i responses",
self._host,
self._port,
len(json_data),
len(channels),
raise UnexpectedDataError(
f"Host {self._host}:{self._port} error mapping response to channels, received {len(json_data)} responses while requesting {len(channels)} responses",
)
return

for data, channel in zip(json_data, channels):
if channel == -1:
Expand Down

0 comments on commit c6e46a0

Please sign in to comment.