diff --git a/README.rst b/README.rst index b690e4e..c91ea4d 100644 --- a/README.rst +++ b/README.rst @@ -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_. diff --git a/pyarlo/base_station.py b/pyarlo/base_station.py index f2b461c..c67360d 100644 --- a/pyarlo/base_station.py +++ b/pyarlo/base_station.py @@ -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 @@ -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] @@ -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.""" @@ -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 = \ @@ -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) @@ -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) @@ -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): @@ -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: diff --git a/pyarlo/utils.py b/pyarlo/utils.py index f2a44a9..191b7c4 100644 --- a/pyarlo/utils.py +++ b/pyarlo/utils.py @@ -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 diff --git a/pylintrc b/pylintrc index 34f9568..6f0de71 100644 --- a/pylintrc +++ b/pylintrc @@ -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 diff --git a/setup.py b/setup.py index 0ad1bce..8da8511 100644 --- a/setup.py +++ b/setup.py @@ -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(), diff --git a/tests/test_base_station.py b/tests/test_base_station.py index 05da763..b90522f 100644 --- a/tests/test_base_station.py +++ b/tests/test_base_station.py @@ -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) @@ -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)