diff --git a/reolinkapi/handlers/api_handler.py b/reolinkapi/handlers/api_handler.py index 501ceb7..2971d05 100644 --- a/reolinkapi/handlers/api_handler.py +++ b/reolinkapi/handlers/api_handler.py @@ -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: diff --git a/reolinkapi/mixins/display.py b/reolinkapi/mixins/display.py index c44c04b..6558c8d 100644 --- a/reolinkapi/mixins/display.py +++ b/reolinkapi/mixins/display.py @@ -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), "channel": channel, "osdChannel": { - "enable": osd_channel_enabled, "name": osd_channel_name, + "enable": int(osd_channel_enabled), "name": osd_channel_name, "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), }}}] r_data = self._execute_command('SetOsd', body)[0] if 'value' in r_data and r_data["value"]["rspCode"] == 200: diff --git a/reolinkapi/mixins/network.py b/reolinkapi/mixins/network.py index f4fe4a6..9a7ceb9 100644 --- a/reolinkapi/mixins/network.py +++ b/reolinkapi/mixins/network.py @@ -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 @@ -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 }}}] - 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": { diff --git a/reolinkapi/mixins/record.py b/reolinkapi/mixins/record.py index 375b5ca..9e905e3 100644 --- a/reolinkapi/mixins/record.py +++ b/reolinkapi/mixins/record.py @@ -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', @@ -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 @@ -51,7 +51,7 @@ def set_recording_encoding(self, "action": 0, "param": { "Enc": { - "audio": audio, + "audio": int(audio), "channel": 0, "mainStream": { "bitRate": main_bit_rate, diff --git a/reolinkapi/mixins/user.py b/reolinkapi/mixins/user.py index c382c2d..833a150 100644 --- a/reolinkapi/mixins/user.py +++ b/reolinkapi/mixins/user.py @@ -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