Skip to content

Commit

Permalink
Improve AI polling when ONVIF push does not include AI
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Mar 16, 2023
1 parent 2ec9604 commit 2362257
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions reolink_aio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,11 +1342,19 @@ async def get_ai_state_all_ch(self) -> bool:
ch_body = [{"cmd": "GetEvents", "action": 0, "param": {"channel": channel}}]
else:
if not self.ai_supported(channel):
return False
continue
ch_body = [{"cmd": "GetAiState", "action": 0, "param": {"channel": channel}}]
body.extend(ch_body)
channels.extend([channel] * len(ch_body))

if not body:
_LOGGER.warning(
"Host %s:%s: get_ai_state_all_ch called while none of the channels support AI detection",
self._host,
self._port,
)
return False

try:
json_data = await self.send(body, expected_response_type="json")
except InvalidContentTypeError as err:
Expand Down Expand Up @@ -3628,7 +3636,7 @@ async def ONVIF_event_callback(self, data: str) -> list[int] | None:
_LOGGER.error("Could not poll motion state after receiving ONVIF event without any known events")
return None

if self._onvif_only_motion and all(self.ai_supported(ch) for ch in event_channels):
if self._onvif_only_motion and any(self.ai_supported(ch) for ch in event_channels):
# Poll all other states since not all cameras have rich notifications including the specific events
if "ONVIF_only_motion" not in self._log_once:
self._log_once.append("ONVIF_only_motion")
Expand Down

0 comments on commit 2362257

Please sign in to comment.