Skip to content

Commit

Permalink
Add cry detection support
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Dec 30, 2024
1 parent 75fda9d commit 8205713
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 13 additions & 4 deletions reolink_aio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2355,6 +2355,15 @@ async def get_host_data(self) -> None:

# Baichuan fallbacks
for channel in self._channels:
try:
if await self.baichuan.get_cry_detection_supported(channel):
self._ai_detection_support.setdefault(channel, {})
self._ai_detection_states.setdefault(channel, {})
self._ai_detection_support[channel]["cry"] = True
self._ai_detection_states[channel]["cry"] = False
except ReolinkError:
pass

if self.camera_hardware_version(channel) == "Unknown":
try:
await self.baichuan.get_info(channel)
Expand Down Expand Up @@ -3623,8 +3632,8 @@ def map_channel_json_response(self, json_data, channel: int, chime_id: int = -1)
_LOGGER.error("Host %s:%s: GetEvents response channel %s does not equal requested channel %s", self._host, self._port, response_channel, channel)
continue
if "ai" in data["value"]:
self._ai_detection_states[channel] = {}
self._ai_detection_support[channel] = {}
self._ai_detection_states.setdefault(channel, {})
self._ai_detection_support.setdefault(channel, {})
for key, value in data["value"]["ai"].items():
supported: bool = value.get("support", 0) == 1
self._ai_detection_states[channel][key] = supported and value.get("alarm_state", 0) == 1
Expand Down Expand Up @@ -3657,8 +3666,8 @@ def map_channel_json_response(self, json_data, channel: int, chime_id: int = -1)
self._ai_alarm_settings[channel][ai_type] = data["value"]["AiAlarm"]

elif data["cmd"] == "GetAiState":
self._ai_detection_states[channel] = {}
self._ai_detection_support[channel] = {}
self._ai_detection_states.setdefault(channel, {})
self._ai_detection_support.setdefault(channel, {})
response_channel = data["value"].get("channel", channel)
if response_channel != channel:
_LOGGER.error("Host %s:%s: GetAiState response channel %s does not equal requested channel %s", self._host, self._port, response_channel, channel)
Expand Down
5 changes: 5 additions & 0 deletions reolink_aio/baichuan/baichuan.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@ async def get_ptz_position(self, channel: int) -> None:
mess = await self.send(cmd_id=433, channel=channel)
self._ptz_position[channel] = self._get_keys_from_xml(mess, ["pPos", "tPos"])

async def get_cry_detection_supported(self, channel: int) -> bool:
"""Check if cry detection is supported"""
mess = await self.send(cmd_id=299, channel=channel)
return self._get_value_from_xml(mess, "cryDetectAbility") == "1"

@http_cmd("GetDingDongList")
async def GetDingDongList(self, channel: int, **_kwargs) -> None:
"""Get the DingDongList info"""
Expand Down

0 comments on commit 8205713

Please sign in to comment.