From 42b012a8919e6b26a87ebf75d9d680deee5f73aa Mon Sep 17 00:00:00 2001 From: RenierM26 <66512715+RenierM26@users.noreply.github.com> Date: Fri, 19 Feb 2021 07:14:56 +0200 Subject: [PATCH] Fix empty ip on some cameras. --- pyezviz/__init__.py | 8 ++------ pyezviz/camera.py | 21 +++++++++++++++------ pyezviz/client.py | 17 ++++++++--------- setup.py | 2 +- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/pyezviz/__init__.py b/pyezviz/__init__.py index 77822ea..0fb087b 100644 --- a/pyezviz/__init__.py +++ b/pyezviz/__init__.py @@ -1,9 +1,5 @@ """init pyezviz.""" from pyezviz.camera import EzvizCamera from pyezviz.client import EzvizClient, PyEzvizError -from pyezviz.constants import ( - DefenseModeType, - DeviceCatagories, - DeviceSwitchType, - SoundMode, -) +from pyezviz.constants import (DefenseModeType, DeviceCatagories, + DeviceSwitchType, SoundMode) diff --git a/pyezviz/camera.py b/pyezviz/camera.py index af4c171..a4c3735 100644 --- a/pyezviz/camera.py +++ b/pyezviz/camera.py @@ -73,6 +73,17 @@ def alarm_list(self): self.alarmlist_time = alarmlist.get("alarms")[0].get("alarmStartTimeStr") self.alarmlist_pic = alarmlist.get("alarms")[0].get("picUrl") + def local_ip(self): + """"Fix empty ip value for certain cameras""" + if self._device.get("connectionInfos"): + if self._device.get("connectionInfos").get("localIp"): + return self._device.get("connectionInfos").get("localIp") + + if self._device.get("wifiInfos"): + return self._device.get("wifiInfos").get("address") + + return "0.0.0.0" + def motion_trigger(self): """Create motion sensor based on last alarm time.""" now = datetime.datetime.now().replace(microsecond=0) @@ -128,13 +139,11 @@ def status(self): "alarm_schedules_enabled": bool( self._device.get("timePlanInfos")[1].get("enable") ), - "alarm_sound_mod": str( - SoundMode(self._device.get("statusInfos").get("alarmSoundMode")) - ), + "alarm_sound_mod": SoundMode( + self._device.get("statusInfos").get("alarmSoundMode") + ).name, "encrypted": bool(self._device.get("statusInfos").get("isEncrypted")), - "local_ip": self._device.get("connectionInfos", {}).get( - "localIp", "0.0.0.0" - ), + "local_ip": self.local_ip(), "wan_ip": self._device.get("connectionInfos", {}).get("netIp", "0.0.0.0"), "local_rtsp_port": self._device.get("connectionInfos").get("localRtspPort"), "supported_channels": self._device.get("deviceInfos").get("channelNumber"), diff --git a/pyezviz/client.py b/pyezviz/client.py index 29f67bb..2a9d4ce 100644 --- a/pyezviz/client.py +++ b/pyezviz/client.py @@ -262,7 +262,7 @@ def _switch_status(self, serial, status_type, enable, max_retries=0): if json_output.get("meta").get("code") != 200: raise PyEzvizError( - f"Could not set the switch, maybe a permission issue ?: Got {req.status_code} : {req.text})" + f"Could not set the switch: Got {req.status_code} : {req.text})" ) return True @@ -309,7 +309,7 @@ def _sound_alarm(self, serial, enable=1, max_retries=0): if json_output.get("meta").get("code") != 200: raise PyEzvizError( - f"Could not set the switch, maybe a permission issue ?: Got {req.status_code} : {req.text})" + f"Could not set the alarm sound: Got {req.status_code} : {req.text})" ) return True @@ -317,7 +317,7 @@ def _sound_alarm(self, serial, enable=1, max_retries=0): def load_cameras(self): """Load and return all cameras objects.""" - devices = self.get_all_device_infos() + devices = self._get_all_device_infos() cameras = [] supported_categories = [ DeviceCatagories.COMMON_DEVICE_CATEGORY.value, @@ -353,7 +353,7 @@ def load_cameras(self): return cameras - def get_all_device_infos(self): + def _get_all_device_infos(self): """Load all devices and build dict per device serial""" devices = self.get_page_list() @@ -543,7 +543,7 @@ def data_report(self, serial, enable=1, max_retries=0): if json_output.get("resultCode") != "0": raise PyEzvizError( - f"Could not set the switch, maybe a permission issue ?: Got {req.status_code} : {req.text})" + f"Could not set detection sensibility level: Got {req.status_code} : {req.text})" ) return True @@ -598,7 +598,7 @@ def api_set_defence_schedule(self, serial, schedule, enable, max_retries=0): if json_output.get("resultCode") != 0: raise PyEzvizError( - f"Could not set the switch, maybe a permission issue ?: Got {req.status_code} : {req.text})" + f"Could not set the schedule: Got {req.status_code} : {req.text})" ) return True @@ -643,7 +643,7 @@ def api_set_defence_mode(self, serial, mode: DefenseModeType, max_retries=0): if json_output.get("meta").get("code") != 200: raise PyEzvizError( - f"Could not set the switch, maybe a permission issue ?: Got {req.status_code} : {req.text})" + f"Could not set defence mode: Got {req.status_code} : {req.text})" ) return True @@ -686,8 +686,7 @@ def detection_sensibility(self, serial, sensibility=3, type_value=3, max_retries response_json = req.json() if response_json["resultCode"] and response_json["resultCode"] != "0": - # raise PyEzvizError("Could not get detection sensibility: Got %s : %s)",str(req.status_code), str(req.text)) - return "Unknown error" + return "Unknown value" return True diff --git a/setup.py b/setup.py index c90c051..a3bfe6a 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name='pyezviz', - version="0.1.7.1", + version="0.1.7.2", license='Apache Software License 2.0', author='Pierre Ourdouille', author_email='baqs@users.github.com',