Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #95 from tchellomello/0.2.0
Browse files Browse the repository at this point in the history
Version 0.2.0
  • Loading branch information
tchellomello authored Jul 17, 2018
2 parents f55bf71 + 477447a commit 0b54d02
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ Night Light Usage (Arlo Baby Monitor)
# Set the brightness of the night light
base_station.set_night_light_brightness(200)
Supported Devices
-----------------
If you have a different model, please feel free to contribute by reporting your results.

+-------------------------+---------------+------------+-----------------+
| Model | Tested by | Status | Results/Issues |
+=========================+===============+============+=================+
| Arlo 1st Generation | @tchellomello | working/ok | N/A |
+-------------------------+---------------+------------+-----------------+
| Arlo 2st Generation | @tchellomello | working/ok | N/A |
+-------------------------+---------------+------------+-----------------+


Contributing
------------
See more at CONTRIBUTING.rst_.
17 changes: 13 additions & 4 deletions pyarlo/base_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def publish_and_get_event(self, resource):
while not this_event and i < 2:
self.__event_handle.wait(5.0)
self.__event_handle.clear()
_LOGGER.debug("Instance " + str(i) + " resource: " + resource)
_LOGGER.debug("Instance %s resource: %s", str(i), resource)
for event in self.__events:
if event['resource'] == resource:
this_event = event
Expand Down Expand Up @@ -319,6 +319,7 @@ def available_modes_with_ids(self):
modes = self.get_available_modes()
try:
if modes:
# pylint: disable=consider-using-dict-comprehension
simple_modes = dict(
[(m.get("type", m.get("name")), m.get("id"))
for m in modes]
Expand Down Expand Up @@ -390,7 +391,6 @@ def get_cameras_properties(self):
if resource_event:
self._last_refresh = int(time.time())
self._camera_properties = resource_event.get('properties')
return

def get_cameras_battery_level(self):
"""Return a list of battery levels of all cameras."""
Expand Down Expand Up @@ -478,6 +478,10 @@ def get_ambient_sensor_data(self):
"""Refresh ambient sensor history"""
resource = 'cameras/{}/ambientSensors/history'.format(self.device_id)
history_event = self.publish_and_get_event(resource)

if history_event is None:
return None

properties = history_event.get('properties')

self._ambient_sensor_data = \
Expand All @@ -490,6 +494,7 @@ def _decode_sensor_data(properties):
"""Decode, decompress, and parse the data from the history API"""
b64_input = ""
for s in properties.get('payload'):
# pylint: disable=consider-using-join
b64_input += s

decoded = base64.b64decode(b64_input)
Expand Down Expand Up @@ -521,7 +526,8 @@ def _parse_statistic(data, scale):

if i == 32768:
return None
elif scale == 0:

if scale == 0:
return i

return float(i) / (scale * 10)
Expand All @@ -530,6 +536,10 @@ def get_latest_ambient_sensor_statistic(self, statistic):
"""Gets the most recent ambient sensor history entry"""
if self._ambient_sensor_data is None:
self.get_ambient_sensor_data()

if self._ambient_sensor_data is None:
return None

return self._ambient_sensor_data[-1].get(statistic)

def get_audio_playback_status(self):
Expand Down Expand Up @@ -690,6 +700,5 @@ def update(self):
_LOGGER.debug("Called base station update of camera properties: "
"Scan Interval: %s, New Properties: %s",
self._refresh_rate, self.camera_properties)
return

# vim:sw=4:ts=4:et:
6 changes: 3 additions & 3 deletions pyarlo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def http_get(url, filename=None):

if filename is None:
return ret.content
else:
with open(filename, 'wb') as data:
data.write(ret.content)

with open(filename, 'wb') as data:
data.write(ret.content)
return True


Expand Down
3 changes: 2 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ disable=
too-many-statements,
too-many-lines,
too-few-public-methods,
abstract-method
abstract-method,
useless-object-inheritance

[EXCEPTIONS]
overgeneral-exceptions=Exception
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def readme():
setup(
name='pyarlo',
packages=['pyarlo'],
version='0.1.9',
version='0.2.0',
description='Python Arlo is a library written in Python 2.7/3x ' +
'that exposes the Netgear Arlo cameras as Python objects.',
long_description=readme(),
Expand Down
17 changes: 17 additions & 0 deletions tests/test_base_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ def test_ambient_sensor_data(self, mock):
self.assertEqual(base.ambient_humidity, 37.2)
self.assertEqual(base.ambient_air_quality, 11.2)

@requests_mock.Mocker()
@patch.object(ArloBaseStation, "publish_and_get_event", lambda x, y: None)
def test_ambient_sensor_data_none(self, mock):
"""Test ArloBaseStation.get_ambient_sensor_data HTTP error."""
base = self.load_base_station(mock)
result = base.get_ambient_sensor_data()
self.assertEqual(result, None)

@requests_mock.Mocker()
@patch.object(
ArloBaseStation, "publish_and_get_event", load_ambient_sensor_data)
Expand All @@ -151,6 +159,15 @@ def test_latest_sensor_statistic(self, mock):
temperature = base.get_latest_ambient_sensor_statistic("temperature")
self.assertEqual(temperature, 24.6)

@requests_mock.Mocker()
@patch.object(
ArloBaseStation, "publish_and_get_event", lambda x, y: None)
def test_latest_sensor_statistic_none(self, mock):
"""Test ArloBaseStation.get_latest_ambient_sensor_statistic None."""
base = self.load_base_station(mock)
temperature = base.get_latest_ambient_sensor_statistic("temperature")
self.assertEqual(temperature, None)

@requests_mock.Mocker()
@patch.object(
ArloBaseStation, "publish_and_get_event", load_audio_playback_status)
Expand Down

0 comments on commit 0b54d02

Please sign in to comment.