From 8ff950613879b4a1c00e138431a0ea3bbb64e067 Mon Sep 17 00:00:00 2001 From: pavoni Date: Thu, 19 May 2016 16:16:43 +0100 Subject: [PATCH] Ignore acc: 0 updates. --- .../components/device_tracker/owntracks.py | 6 +++++ .../device_tracker/test_owntracks.py | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/homeassistant/components/device_tracker/owntracks.py b/homeassistant/components/device_tracker/owntracks.py index 40cb19e05e7..f59fc06c59a 100644 --- a/homeassistant/components/device_tracker/owntracks.py +++ b/homeassistant/components/device_tracker/owntracks.py @@ -53,6 +53,12 @@ def setup_scanner(hass, config, see): 'accuracy %s is not met: %s', data_type, max_gps_accuracy, data) return None + if convert(data.get('acc'), float, 1.0) == 0.0: + _LOGGER.debug('Skipping %s update because GPS accuracy' + 'is zero', + data_type) + return None + return data def owntracks_location_update(topic, payload, qos): diff --git a/tests/components/device_tracker/test_owntracks.py b/tests/components/device_tracker/test_owntracks.py index e5fcd454835..756f6271e59 100644 --- a/tests/components/device_tracker/test_owntracks.py +++ b/tests/components/device_tracker/test_owntracks.py @@ -55,6 +55,21 @@ LOCATION_MESSAGE_INACCURATE = { 'tst': 1, 'vel': 0} +LOCATION_MESSAGE_ZERO_ACCURACY = { + 'batt': 92, + 'cog': 248, + 'tid': 'user', + 'lon': 2.0, + 't': 'u', + 'alt': 27, + 'acc': 0, + 'p': 101.3977584838867, + 'vac': 4, + 'lat': 6.0, + '_type': 'location', + 'tst': 1, + 'vel': 0} + REGION_ENTER_MESSAGE = { 'lon': 1.0, 'event': 'enter', @@ -204,6 +219,14 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase): self.assert_location_latitude(2.0) self.assert_location_longitude(1.0) + def test_location_zero_accuracy_gps(self): + """Ignore the location for zero accuracy GPS information.""" + self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE) + self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE_ZERO_ACCURACY) + + self.assert_location_latitude(2.0) + self.assert_location_longitude(1.0) + def test_event_entry_exit(self): """Test the entry event.""" self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)