From fe8207bbecbbe9a70b26b57301602d2c91fc48a9 Mon Sep 17 00:00:00 2001 From: Xaldimo Date: Tue, 19 Nov 2019 22:31:31 +0000 Subject: [PATCH] Update sensor.py Correct GPS deviation implementation --- custom_components/places/sensor.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/custom_components/places/sensor.py b/custom_components/places/sensor.py index 1c26ff1e..1e339765 100644 --- a/custom_components/places/sensor.py +++ b/custom_components/places/sensor.py @@ -432,9 +432,9 @@ def update(self): """ Call the do_update function based on scan interval and throttle """ self.do_update("Scan Interval") - def haversine(lon1, lat1, lon2, lat2): + def haversine(self, lon1, lat1, lon2, lat2): """ - Calculate the great circle distance between two points + Calculate the great circle distance between two points on the earth (specified in decimal degrees) """ # convert decimal degrees to radians @@ -483,11 +483,11 @@ def do_update(self, reason): distance_km = round(distance_m / 1000, 2) distance_from_home = str(distance_km)+' km' - deviation = haversine(old_latitude, old_longitude, new_latitude, new_longitude) - if deviation <= '0.2': # in kilometers - direction = "stationary" - elif last_distance_m > distance_m: - direction = "towards home" + deviation = self.haversine(float(old_latitude), float(old_longitude), float(new_latitude), float(new_longitude)) + if deviation <= 0.2: # in kilometers + direction = "stationary" + elif last_distance_m > distance_m: + direction = "towards home" elif last_distance_m < distance_m: direction = "away from home" else: