Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reolink api v7 #65

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions reolinkapi/handlers/api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def login(self) -> bool:
self.token = data["value"]["Token"]["name"]
print("Login success")
return True
print("Logged in failure data: ", response.json())
print(self.token)
return False
else:
Expand Down
8 changes: 4 additions & 4 deletions reolinkapi/mixins/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def set_osd(self, bg_color: bool = 0, channel: float = 0, osd_channel_enabled: b
body = [{"cmd": "SetOsd", "action": 1,
"param": {
"Osd": {
"bgcolor": bg_color,
"bgcolor": int(bg_color),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if one needs to convert bool explicitly here to int since requests will convert this for us when sending the request.

"channel": channel,
"osdChannel": {
"enable": osd_channel_enabled, "name": osd_channel_name,
"enable": int(osd_channel_enabled), "name": osd_channel_name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

"pos": osd_channel_pos
},
"osdTime": {"enable": osd_time_enabled, "pos": osd_time_pos},
"watermark": osd_watermark_enabled,
"osdTime": {"enable": int(osd_time_enabled), "pos": osd_time_pos},
"watermark": int(osd_watermark_enabled),
Comment on lines +50 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and same here

}}}]
r_data = self._execute_command('SetOsd', body)[0]
if 'value' in r_data and r_data["value"]["rspCode"] == 200:
Expand Down
41 changes: 36 additions & 5 deletions reolinkapi/mixins/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

class NetworkAPIMixin:
"""API calls for network settings."""
def set_net_port(self, http_port: float = 80, https_port: float = 443, media_port: float = 9000,
onvif_port: float = 8000, rtmp_port: float = 1935, rtsp_port: float = 554) -> bool:
def set_net_port(self, http_enable: bool = False, http_port: float = 80,
https_enable: bool = True, https_port: float = 443, media_port: float = 9000,
onvif_enable: bool = True, onvif_port: float = 8000,
rtmp_enable: bool = False, rtmp_port: float = 1935, rtsp_enable: bool = True, rtsp_port: float = 554) -> bool:
"""
Set network ports
If nothing is specified, the default values will be used
Expand All @@ -16,17 +18,46 @@ def set_net_port(self, http_port: float = 80, https_port: float = 443, media_por
:type http_port: int
:return: bool
"""
if http_enable:
http_enable = 1
else:
http_enable = 0
if https_enable:
https_enable = 1
else:
https_enable = 0
if onvif_enable:
onvif_enable = 1
else:
onvif_enable = 0
if rtmp_enable:
rtmp_enable = 1
else:
rtmp_enable = 0
if rtsp_enable:
rtsp_enable = 1
else:
rtsp_enable = 0

body = [{"cmd": "SetNetPort", "action": 0, "param": {"NetPort": {
"httpEnable": http_enable,
"httpPort": http_port,
"httpsEnable": https_enable,
"httpsPort": https_port,
"mediaPort": media_port,
"onvifEnable": onvif_enable,
"onvifPort": onvif_port,
"rtmpEnable": rtmp_enable,
"rtmpPort": rtmp_port,
"rtspEnable": rtsp_enable,
"rtspPort": rtsp_port
Comment on lines +21 to 53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could rather use int() to convert the boolean instead of writing an if statement to map the boolean values to an integer.

~ ⟩ python3
Python 3.11.2 (main, Feb  7 2023, 13:52:42) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print(int(True))
1
>>> print(int(False))
0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably don't even need to convert from bool to int so the variable can be passed along directly

}}}]
self._execute_command('SetNetPort', body, multi=True)
print("Successfully Set Network Ports")
return True
response = self._execute_command('SetNetPort', body, multi=True)
if response[0]["code"] == 0:
print("Successfully Set Network Ports")
return True
else:
raise Exception(f"Failure to set network ports: {response}")

def set_wifi(self, ssid: str, password: str) -> Dict:
body = [{"cmd": "SetWifi", "action": 0, "param": {
Expand Down
6 changes: 3 additions & 3 deletions reolinkapi/mixins/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_recording_advanced(self) -> Dict:
return self._execute_command('GetRec', body)

def set_recording_encoding(self,
audio: float = 0,
audio: bool = 0,
main_bit_rate: float = 8192,
main_frame_rate: float = 8,
main_profile: str = 'High',
Expand All @@ -34,7 +34,7 @@ def set_recording_encoding(self,
sub_size: str = '640*480') -> Dict:
"""
Sets the current camera encoding settings for "Clear" and "Fluent" profiles.
:param audio: int Audio on or off
:param audio: bool Audio on or off
:param main_bit_rate: int Clear Bit Rate
:param main_frame_rate: int Clear Frame Rate
:param main_profile: string Clear Profile
Expand All @@ -51,7 +51,7 @@ def set_recording_encoding(self,
"action": 0,
"param": {
"Enc": {
"audio": audio,
"audio": int(audio),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

"channel": 0,
"mainStream": {
"bitRate": main_bit_rate,
Expand Down
7 changes: 4 additions & 3 deletions reolinkapi/mixins/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ def add_user(self, username: str, password: str, level: str = "guest") -> bool:
print("Could not add user. Camera responded with:", r_data["value"])
return False

def modify_user(self, username: str, password: str) -> bool:
def modify_user(self, username: str, oldPassword: str, newPassword: str) -> bool:
"""
Modify the user's password by specifying their username
:param username: The user which would want to be modified
:param password: The new password
:param oldPassword: The old password
:param newPassword: The new password
:return: whether the user was modified successfully
"""
body = [{"cmd": "ModifyUser", "action": 0, "param": {"User": {"userName": username, "password": password}}}]
body = [{"cmd": "ModifyUser", "action": 0, "param": {"User": {"userName": username, "oldPassword": oldPassword, "newPassword": newPassword}}}]
r_data = self._execute_command('ModifyUser', body)[0]
if r_data["value"]["rspCode"] == 200:
return True
Expand Down