Skip to content

Commit

Permalink
Fix elevation sensor that fails in some locations sometimes (#10)
Browse files Browse the repository at this point in the history
_get_nxt_time method was not handling the case properly if the next time estimate (nxt_time) was between time0 & time1. Also test for elev1 == elev0, and nxt_time being either time0 or time1.
  • Loading branch information
pnbruckner authored Dec 2, 2019
1 parent 73ab367 commit 8dbaf43
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions custom_components/sun2/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,25 @@ def _get_nxt_time(self, time1, elev1, trg_elev, max_time):
elev0 = self._prv_elev
nxt_elev = trg_elev + 1.5 * _ELEV_MAX_ERR
while abs(nxt_elev - trg_elev) >= _ELEV_MAX_ERR:
if elev1 == elev0:
return None
nxt_time = _calc_nxt_time(time0, elev0, time1, elev1, trg_elev)
if nxt_time in (time0, time1):
break
if nxt_time > max_time:
return None
nxt_elev = self._loc.solar_elevation(nxt_time)
time0 = time1
elev0 = elev1
time1 = nxt_time
elev1 = nxt_elev
if nxt_time > time1:
time0 = time1
elev0 = elev1
time1 = nxt_time
elev1 = nxt_elev
elif elev0 < trg_elev < nxt_elev or elev0 > trg_elev > nxt_elev:
time1 = nxt_time
elev1 = nxt_elev
else:
time0 = nxt_time
elev0 = nxt_elev
return nxt_time

def _update(self):
Expand Down

0 comments on commit 8dbaf43

Please sign in to comment.