Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #77 from badabing2005/IRFix-patch-1
Browse files Browse the repository at this point in the history
Fix GetIrLights / SetIrLights
  • Loading branch information
fwestenberg authored Oct 12, 2020
2 parents 02895c8 + 9e7fa89 commit 3ceee2c
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions custom_components/reolink_dev/ReolinkPyPi/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ async def get_settings(self):
return

param_channel = {"channel": self._channel}
body = [{"cmd": "GetDevInfo", "action":1, "param": param_channel},
{"cmd": "GetNetPort", "action": 1, "param": param_channel},
{"cmd": "GetFtp", "action": 1, "param": param_channel},
{"cmd": "GetEmail", "action": 1, "param": param_channel},
{"cmd": "GetIrLights", "action": 1, "param": param_channel},
{"cmd": "GetRec", "action": 1, "param": param_channel},
{"cmd": "GetPtzPreset", "action": 1, "param": param_channel},
body = [{"cmd": "GetDevInfo", "action":1, "param": {"channel": self._channel}},
{"cmd": "GetNetPort", "action": 1, "param": {"channel": self._channel}},
{"cmd": "GetFtp", "action": 1, "param": {"channel": self._channel}},
{"cmd": "GetEmail", "action": 1, "param": {"channel": self._channel}},
{"cmd": "GetIsp", "action": 1, "param": {"channel": self._channel}},
{"cmd": "GetRec", "action": 1, "param": {"channel": self._channel}},
{"cmd": "GetPtzPreset", "action": 1, "param": {"channel": self._channel}},
{"cmd": "GetAlarm","action":1,"param":{"Alarm":{"channel": self._channel ,"type":"md"}}}]
# the call must be like this:
#[{"cmd":"GetAlarm","action":1,"param":{"Alarm":{"channel":0,"type":"md"}}}]
Expand All @@ -60,15 +60,15 @@ async def get_settings(self):

for data in json_data:
try:
if data["cmd"] == "GetDevInfo":
if data["cmd"] == "GetDevInfo":
self._device_info = data

elif data["cmd"] == "GetNetPort":
self._netport_settings = data
self._rtspport = data["value"]["NetPort"]["rtspPort"]
self._rtmpport = data["value"]["NetPort"]["rtmpPort"]

elif data["cmd"] == "GetFtp":
elif data["cmd"] == "GetFtp":
self._ftp_settings = data
if (data["value"]["Ftp"]["schedule"]["enable"] == 1):
self._ftp_state = True
Expand All @@ -81,10 +81,10 @@ async def get_settings(self):
self._email_state = True
else:
self._email_state = False
elif data["cmd"] == "GetIrLights":

elif data["cmd"] == "GetIsp":
self._ir_settings = data
if (data["value"]["IrLights"]["state"] == "Auto"):
if (data["value"]["Isp"]["dayNight"] == "Auto"):
self._ir_state = True
else:
self._ir_state = False
Expand All @@ -106,7 +106,7 @@ async def get_settings(self):
_LOGGER.debug(f"Got preset {preset_name} with ID {preset_id}")
else:
_LOGGER.debug(f"Preset is not enabled: {preset}")

elif data["cmd"] == "GetAlarm":
self._motion_detection_settings = data
self._pippo = data
Expand All @@ -115,12 +115,12 @@ async def get_settings(self):
else:
self._motion_detection_state = False
except:
continue
continue

async def get_motion_state(self):
body = [{"cmd": "GetMdState", "action": 0, "param":{"channel":self._channel}}]
param = {"token": self._token}

response = await self.send(body, param)

try:
Expand All @@ -132,15 +132,15 @@ async def get_motion_state(self):
return self._motion_state

if json_data[0]["value"]["state"] == 1:
self._motion_state = True
self._motion_state = True
self._last_motion = datetime.datetime.now()
else:
self._motion_state = False
except:
self._motion_state = False

return self._motion_state

@property
async def still_image(self):
response = await self.send(None, f"?cmd=Snap&channel={self._channel}&token={self._token}", stream=True)
Expand Down Expand Up @@ -202,7 +202,7 @@ def motion_detection_state(self):
async def login(self, username, password):
body = [{"cmd": "Login", "action": 0, "param": {"User": {"userName": username, "password": password}}}]
param = {"cmd": "Login", "token": "null"}

response = await self.send(body, param)

try:
Expand Down Expand Up @@ -288,10 +288,10 @@ async def set_ir_lights(self, enabled):
if enabled == True:
newValue = "Auto"
else:
newValue = "Off"
newValue = "Color"

body = [{"cmd":"SetIrLights","action":0,"param": self._ir_settings["value"] }]
body[0]["param"]["IrLights"]["state"] = newValue
body = [{"cmd":"SetIsp","action":0,"param": self._ir_settings["value"] }]
body[0]["param"]["Isp"]["dayNight"] = newValue

response = await self.send(body, {"cmd": "SetIrLights", "token": self._token} )
try:
Expand Down Expand Up @@ -356,10 +356,10 @@ async def set_motion_detection(self, enabled):
return False

async def send(self, body, param, stream=False):
if (self._token is None and
if (self._token is None and
(body is None or body[0]["cmd"] != "Login")):
_LOGGER.info(f"Reolink camera at IP {self._ip} is not logged in")
return
return

timeout = aiohttp.ClientTimeout(total=10)

Expand All @@ -374,4 +374,4 @@ async def send(self, body, param, stream=False):
return json_data

def clear_token(self):
self._token = None
self._token = None

0 comments on commit 3ceee2c

Please sign in to comment.