Skip to content

Commit

Permalink
Add battery commands
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed May 11, 2024
1 parent 5763180 commit 7a033a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions reolink_aio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def __init__(
self._ir_settings: dict[int, dict] = {}
self._status_led_settings: dict[int, dict] = {}
self._whiteled_settings: dict[int, dict] = {}
self._battery: dict[int, dict] = {}
self._recording_settings: dict[int, dict] = {}
self._md_alarm_settings: dict[int, dict] = {}
self._ai_alarm_settings: dict[int, dict] = {}
Expand Down Expand Up @@ -734,6 +735,24 @@ def whiteled_settings(self, channel: int) -> Optional[dict]:

return None

def battery_percentage(self, channel: int) -> Optional[int]:
if channel not in self._battery:
return None

return self._battery[channel]["batteryPercent"]

def battery_temperature(self, channel: int) -> Optional[int]:
if channel not in self._battery:
return None

return self._battery[channel]["temperature"]

def battery_status(self, channel: int) -> Optional[int]:
if channel not in self._battery:
return None

return self._battery[channel]["chargeStatus"]

def daynight_state(self, channel: int) -> Optional[str]:
if channel not in self._isp_settings:
return None
Expand Down Expand Up @@ -1217,6 +1236,9 @@ def construct_capabilities(self, warnings=True) -> None:
if self.api_version("supportAiStayTime", channel) > 0:
self._capabilities[channel].append("ai_delay")

if self.api_version("battery", channel) > 0:
self._capabilities[channel].append("battery")

if self.api_version("ispHue", channel) > 0:
self._capabilities[channel].append("isp_hue")
if self.api_version("ispSatruation", channel) > 0:
Expand Down Expand Up @@ -1289,6 +1311,8 @@ async def get_state(self, cmd: str) -> None:
ch_body = [{"cmd": "GetPowerLed", "action": 0, "param": {"channel": channel}}]
elif cmd == "GetWhiteLed":
ch_body = [{"cmd": "GetWhiteLed", "action": 0, "param": {"channel": channel}}]
elif cmd == "GetBatteryInfo":
ch_body = [{"cmd": "GetBatteryInfo", "action": 0, "param": {"channel": channel}}]
elif cmd == "GetWebHook":
ch_body = [{"cmd": "GetWebHook", "action": 0, "param": {"channel": channel}}]
elif cmd == "GetPtzPreset":
Expand Down Expand Up @@ -1424,6 +1448,9 @@ async def get_states(self, cmd_list: list[str] | None = None) -> None:
if self.supported(channel, "floodLight") and ("GetWhiteLed" in cmd_list or not cmd_list):
ch_body.append({"cmd": "GetWhiteLed", "action": 0, "param": {"channel": channel}})

if self.supported(channel, "battery") and ("GetBatteryInfo" in cmd_list or not cmd_list):
ch_body.append({"cmd": "GetBatteryInfo", "action": 0, "param": {"channel": channel}})

if self.supported(channel, "status_led") and ("GetPowerLed" in cmd_list or not cmd_list):
ch_body.append({"cmd": "GetPowerLed", "action": 0, "param": {"channel": channel}})

Expand Down Expand Up @@ -2694,6 +2721,9 @@ def map_channel_json_response(self, json_data, channel: int):
response_channel = data["value"]["WhiteLed"]["channel"]
self._whiteled_settings[channel] = data["value"]

elif data["cmd"] == "GetBatteryInfo":
self._battery[channel] = data["value"]["Battery"]

elif data["cmd"] == "GetRec":
self._recording_settings[channel] = data["value"]

Expand Down
8 changes: 8 additions & 0 deletions reolink_aio/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,11 @@ class TrackMethodEnum(Enum):
digital = 2
digitalfirst = 3
pantiltfirst = 4


class BatteryEnum(Enum):
"""Battery status"""

discharging = 0
charging = 1
chargecomplete = 2

0 comments on commit 7a033a7

Please sign in to comment.