From 2362257923badb708543643a2f1e3c7bcb07cdb5 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Thu, 16 Mar 2023 09:29:43 +0100 Subject: [PATCH] Improve AI polling when ONVIF push does not include AI --- reolink_aio/api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/reolink_aio/api.py b/reolink_aio/api.py index ed283b1..173173b 100644 --- a/reolink_aio/api.py +++ b/reolink_aio/api.py @@ -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: @@ -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")