Skip to content

Commit

Permalink
Add quick_reply_dict, quick_reply_enabled, quick_reply_file and quick…
Browse files Browse the repository at this point in the history
…_reply_time
  • Loading branch information
starkillerOG committed Mar 13, 2023
1 parent 495e601 commit e100a5a
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions reolink_aio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ def __init__(
self._audio_alarm_settings: dict[int, dict] = {}
self._buzzer_settings: dict[int, dict] = {}
self._auto_track_settings: dict[int, dict] = {}
self._audio_file_list: dict[int, dict] = {}
self._auto_reply_settings: dict[int, dict] = {}

##############################################################################
# States
Expand Down Expand Up @@ -612,6 +614,37 @@ def volume(self, channel: int) -> int:

return self._audio_settings[channel]["AudioCfg"]["volume"]

def quick_reply_dict(self, channel: int) -> dict[int, str]:
if channel not in self._audio_settings:
return {}

audio_dict = {}
for audio_file in self._audio_file_list[channel]["AudioFileList"]:
audio_dict[audio_file["id"]] = audio_file["fileName"]
return audio_dict

def quick_reply_enabled(self, channel: int) -> bool:
if channel not in self._auto_reply_settings:
return False

return self._auto_reply_settings[channel]["AutoReply"]["enable"] == 1

def quick_reply_file(self, channel: int) -> int | None:
if channel not in self._auto_reply_settings:
return None

file_id = self._auto_reply_settings[channel]["AutoReply"]["fileId"]
if file_id == -1:
return None

return file_id

def quick_reply_time(self, channel: int) -> int:
if channel not in self._auto_reply_settings:
return 0

return self._auto_reply_settings[channel]["AutoReply"]["timeout"]

def audio_alarm_settings(self, channel: int) -> dict:
if channel in self._audio_alarm_settings:
return self._audio_alarm_settings[channel]
Expand Down Expand Up @@ -840,6 +873,9 @@ def construct_capabilities(self, warnings=True) -> None:
if self.api_version("GetAudioCfg") > 0:
self._capabilities[channel].append("volume")

if self.is_doorbell(channel) and self.api_version("GetAudioFileList") > 0 and self.api_version("GetAutoReply") > 0:
self._capabilities[channel].append("quick_reply")

if channel in self._audio_alarm_settings:
self._capabilities[channel].append("siren")

Expand Down Expand Up @@ -946,6 +982,10 @@ async def get_state(self, cmd: str) -> None:
ch_body = [{"cmd": "GetAiCfg", "action": 0, "param": {"channel": channel}}]
elif cmd == "GetAudioCfg":
ch_body = [{"cmd": "GetAudioCfg", "action": 0, "param": {"channel": channel}}]
elif cmd == "GetAudioFileList":
ch_body = [{"cmd": "GetAudioFileList", "action": 0, "param": {"channel": channel}}]
elif cmd == "GetAutoReply":
ch_body = [{"cmd": "GetAutoReply", "action": 0, "param": {"channel": channel}}]
elif cmd == "GetOsd":
ch_body = [{"cmd": "GetOsd", "action": 0, "param": {"channel": channel}}]
elif cmd == "GetBuzzerAlarmV20":
Expand Down Expand Up @@ -1063,6 +1103,9 @@ async def get_states(self) -> None:
if self.supported(channel, "volume"):
ch_body.append({"cmd": "GetAudioCfg", "action": 0, "param": {"channel": channel}})

if self.supported(channel, "quick_reply"):
ch_body.append({"cmd": "GetAutoReply", "action": 0, "param": {"channel": channel}})

if self.supported(channel, "buzzer"):
ch_body.append({"cmd": "GetBuzzerAlarmV20", "action": 0, "param": {"channel": channel}})

Expand Down Expand Up @@ -1161,6 +1204,9 @@ async def get_host_data(self) -> None:
{"cmd": "GetIrLights", "action": 0, "param": {"channel": channel}},
{"cmd": "GetAudioCfg", "action": 0, "param": {"channel": channel}},
]
if self.is_doorbell(channel):
ch_body.append({"cmd": "GetAudioFileList", "action": 0, "param": {"channel": channel}})
ch_body.append({"cmd": "GetAutoReply", "action": 0, "param": {"channel": channel}})
# one time values
ch_body.append({"cmd": "GetOsd", "action": 0, "param": {"channel": channel}})
# checking range
Expand Down Expand Up @@ -1205,6 +1251,8 @@ def check_command_exists(cmd: str) -> int:
self._api_version["GetWhiteLed"] = check_command_exists("GetWhiteLed")
self._api_version["GetAudioCfg"] = check_command_exists("GetAudioCfg")
self._api_version["GetPtzGuard"] = check_command_exists("GetPtzGuard")
self._api_version["GetAudioFileList"] = check_command_exists("GetAudioFileList")
self._api_version["GetAutoReply"] = check_command_exists("GetAutoReply")
if self.api_version("scheduleVersion") >= 1:
self._api_version["GetEmail"] = check_command_exists("GetEmailV20")
self._api_version["GetPush"] = check_command_exists("GetPushV20")
Expand Down Expand Up @@ -1971,6 +2019,12 @@ def map_channel_json_response(self, json_data, channel: int):
elif data["cmd"] == "GetAudioAlarmV20":
self._audio_alarm_settings[channel] = data["value"]

elif data["cmd"] == "GetAudioFileList":
self._audio_file_list[channel] = data["value"]

elif data["cmd"] == "GetAutoReply":
self._auto_reply_settings[channel] = data["value"]

elif data["cmd"] == "GetAutoFocus":
self._auto_focus_settings[channel] = data["value"]

Expand Down

0 comments on commit e100a5a

Please sign in to comment.