Skip to content

Commit

Permalink
Fix empty ip on some cameras.
Browse files Browse the repository at this point in the history
  • Loading branch information
RenierM26 committed Feb 19, 2021
1 parent 1af449e commit 42b012a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
8 changes: 2 additions & 6 deletions pyezviz/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 15 additions & 6 deletions pyezviz/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"),
Expand Down
17 changes: 8 additions & 9 deletions pyezviz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -309,15 +309,15 @@ 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

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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
Expand Down

0 comments on commit 42b012a

Please sign in to comment.