Skip to content

Commit

Permalink
Merge pull request #14 from Xaldimo/pr/1
Browse files Browse the repository at this point in the history
Correct GPS deviation implementation
  • Loading branch information
iantrich authored Nov 20, 2019
2 parents 44c1e4a + fe8207b commit 2325f23
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions custom_components/places/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2325f23

Please sign in to comment.