Skip to content

Commit 66d2757

Browse files
committed
Fix Baichuan DoorbellLightState
1 parent 51c6a82 commit 66d2757

2 files changed

Lines changed: 34 additions & 13 deletions

File tree

reolink_aio/api.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def __init__(
236236

237237
##############################################################################
238238
# API-versions and capabilities
239-
self._api_version: dict[str, int] = {}
239+
self._api_version: dict[str, int | dict[int | None, int]] = {}
240240
self._abilities: dict[str, Any] = {} # raw response from NVR/camera
241241
self._capabilities: dict[int | str, set[str]] = {"Host": set()} # processed by construct_capabilities
242242

@@ -791,19 +791,19 @@ def audio_alarm_enabled(self, channel: int) -> bool:
791791
return self._audio_alarm_settings[channel]["schedule"]["enable"] == 1
792792

793793
def ir_enabled(self, channel: int) -> bool:
794-
return self._ir_settings.get(channel, {}).get("IrLights", {}).get("state") == "Auto"
794+
return self._ir_settings.get(channel, {}).get("state") == "Auto"
795795

796796
def status_led_enabled(self, channel: int) -> bool:
797797
if channel not in self._status_led_settings:
798798
return False
799799

800-
return self._status_led_settings[channel]["PowerLed"].get("state", "Off") == "On"
800+
return self._status_led_settings[channel].get("state", "Off") == "On"
801801

802802
def doorbell_led(self, channel: int) -> str:
803803
if channel not in self._status_led_settings:
804804
return "Off"
805805

806-
return self._status_led_settings[channel]["PowerLed"].get("eDoorbellLightState", "Off")
806+
return self._status_led_settings[channel].get("eDoorbellLightState", "Off")
807807

808808
def doorbell_led_list(self, channel: int) -> list[str]:
809809
mode_values = []
@@ -812,7 +812,7 @@ def doorbell_led_list(self, channel: int) -> list[str]:
812812
mode_values.extend([StatusLedEnum.auto, StatusLedEnum.alwaysonatnight])
813813
ledCtrl = self.baichuan.api_version("ledCtrl", channel)
814814
if self.api_version("supportDoorbellLightKeepOn", channel) > 0 or (ledCtrl >> 15) & 1: # 16th bit (32768), shift 15:
815-
options = self._status_led_range.get(channel, {}).get("PowerLed", {}).get("eDoorbellLightState", [])
815+
options = self._status_led_range.get(channel, {}).get("eDoorbellLightState", [])
816816
if "KeepOn" in options or (ledCtrl >> 15) & 1:
817817
mode_values.append(StatusLedEnum.alwayson)
818818
else:
@@ -1631,7 +1631,7 @@ def capabilities(self) -> dict[int | str, set[str]]:
16311631
return self._capabilities
16321632

16331633
@property
1634-
def checked_api_versions(self) -> dict[str, int]:
1634+
def checked_api_versions(self) -> dict[str, int | dict[int | None, int]]:
16351635
return self._api_version
16361636

16371637
@property
@@ -1949,7 +1949,10 @@ def supported(self, channel: int | None, capability: str) -> bool:
19491949
def api_version(self, capability: str, channel: int | None = None, no_key_return: int = 0) -> int:
19501950
"""Return the api version of a capability, 0=not supported, >0 is supported"""
19511951
if capability in self._api_version:
1952-
return self._api_version[capability]
1952+
ver = self._api_version[capability]
1953+
if isinstance(ver, dict):
1954+
return ver.get(channel, no_key_return)
1955+
return ver
19531956

19541957
if channel is None:
19551958
return self._abilities.get(capability, {}).get("ver", 0)
@@ -4052,14 +4055,14 @@ def map_channel_json_response(self, json_data: typings.reolink_json, channel: in
40524055
self._image_settings[channel] = data["value"]
40534056

40544057
elif data["cmd"] == "GetIrLights":
4055-
self._ir_settings[channel] = data["value"]
4058+
self._ir_settings[channel] = data["value"]["IrLights"]
40564059

40574060
elif data["cmd"] == "GetPowerLed":
40584061
# GetPowerLed returns incorrect channel
40594062
# response_channel = data["value"]["PowerLed"]["channel"]
4060-
self._status_led_settings[channel] = data["value"]
4063+
self._status_led_settings[channel] = data["value"]["PowerLed"]
40614064
if "range" in data:
4062-
self._status_led_range[channel] = data["range"]
4065+
self._status_led_range[channel] = data["range"]["PowerLed"]
40634066

40644067
elif data["cmd"] == "GetWhiteLed":
40654068
value = data["value"]["WhiteLed"]

reolink_aio/baichuan/baichuan.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,7 +2775,14 @@ async def get_status_led(self, channel: int, **_kwargs) -> None:
27752775
"""Get the status led and IR light status"""
27762776
mess = await self.send(cmd_id=208, channel=channel)
27772777
data = get_keys_from_xml(
2778-
mess, {"IRLedBrightness": ("ir_brightness", int), "state": ("ir_state", str), "lightState": ("state", str), "doorbellLightState": ("eDoorbellLightState", str)}
2778+
mess,
2779+
{
2780+
"IRLedBrightness": ("ir_brightness", int),
2781+
"state": ("ir_state", str),
2782+
"lightState": ("state", str),
2783+
"doorbellLightState": ("eDoorbellLightState", str),
2784+
"doorbellAbility": ("doorbellAbility", int),
2785+
},
27792786
)
27802787

27812788
if (val := data.get("state")) is not None:
@@ -2784,12 +2791,23 @@ async def get_status_led(self, channel: int, **_kwargs) -> None:
27842791
else:
27852792
data["state"] = "Off"
27862793

2794+
if (val := data.get("eDoorbellLightState")) is not None:
2795+
val = val[:1].upper() + val[1:] # capitalize first letter.
2796+
if val == "Close":
2797+
val = "Off"
2798+
elif val == "Open":
2799+
val = "On"
2800+
data["eDoorbellLightState"] = val
2801+
if (abi := data.get("doorbellAbility")) is not None:
2802+
if (abi >> 3) & 1: # 4th bit (8), shift 3
2803+
self.http_api._api_version["supportDoorbellLightKeepOff"] = 1
2804+
27872805
if (ir_brightness := data.get("ir_brightness")) is not None:
27882806
self._ir_brightness[channel] = ir_brightness
27892807

2790-
self.http_api._status_led_settings.setdefault(channel, {}).setdefault("PowerLed", {}).update(data)
2808+
self.http_api._status_led_settings.setdefault(channel, {}).update(data)
27912809
if "ir_state" in data:
2792-
self.http_api._ir_settings.setdefault(channel, {}).setdefault("IrLights", {})["state"] = data["ir_state"].capitalize()
2810+
self.http_api._ir_settings.setdefault(channel, {})["state"] = data["ir_state"].capitalize()
27932811

27942812
@http_cmd(["SetPowerLed", "SetIrLights"])
27952813
async def set_status_led(self, channel: int | None = None, ir_brightness: int | None = None, **kwargs) -> None:

0 commit comments

Comments
 (0)