Skip to content

Commit

Permalink
V2.0.6
Browse files Browse the repository at this point in the history
Fix issue when API call fails. First request fails, then backload fails
  • Loading branch information
petergridge authored Jun 8, 2023
1 parent d79e59f commit 1aa295a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions custom_components/openweathermaphistory/weatherhistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async def get_historydata(self,historydata):
lastdt = max(data)
except ValueError:
#no data yet just get this hours dataaset
lastdt = int(thishour - 3600)
lastdt = int(thishour)
#iterate until caught up to current hour
#or exceeded the call limit
target = min(thishour,thishour+CONST_CALLS*3600)
Expand All @@ -331,10 +331,18 @@ async def get_historydata(self,historydata):
async def async_backload(self,historydata):
"""backload data from the oldest data backward"""
data = historydata

#there can be more entries than required for intial load
self._backlog = max(0,(self._initdays*24) - len(historydata))
#the most recent data avaialble less on hour
startdp = min(data) - 3600
try:
startdp = min(data) - 3600
except ValueError:
hour = datetime(date.today().year, date.today().month, date.today().day,datetime.now().hour)
thishour = int(datetime.timestamp(hour))
#no data yet just get this hours dataaset
startdp = int(thishour - 3600)

#the time required to back load until
targetdp = max(data) - (self._initdays*3600*24)

Expand Down

0 comments on commit 1aa295a

Please sign in to comment.