Skip to content

Commit

Permalink
Fixed a glitch in the flag_up_time
Browse files Browse the repository at this point in the history
To save request to the sunset api, I kind of forget to reset the flag_up_time variable.
  • Loading branch information
J-Lindvig authored Jan 23, 2022
1 parent 6fca42d commit 8772248
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion custom_components/flagdays_dk/flagdays.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _getFlagTimes(self, dateStr):
# If sunrise is before 08:00 use 08:00 else sunrise
flagTimes['flag_up_time'] = '08:00' if int(self._sun.get('sunrise').split(':')[0]) < 8 else self._sun.get('sunrise')
flagTimes['flag_down_time'] = self._sun.get('sunset')

return flagTimes

def _getNumOfTag(self, html, tag, parser = 'html.parser'):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/flagdays_dk/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"codeowners": ["J-Lindvig"],
"requirements": ["beautifulsoup4", "html.parser"],
"iot_class": "cloud_polling",
"version": "1.0"
"version": "1.1"
}
38 changes: 18 additions & 20 deletions custom_components/flagdays_dk/sun_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,24 @@ def __init__(self):
self._data = {}

def getFutureSun(self, lat = 55.395903819648304, lon = 10.388097722778282, dateStr = 'today'):
# If the data is empty, fetch some new
if not self._data:
self._session = requests.Session()
payload = {
'lat': lat,
'lng': lon,
'date': dateStr,
'formatted': 0
}
r = self._session.get(SUN_URL, params = payload)

if r.status_code == 200:
r = r.json()
if r['status'].lower() == 'ok':
for key in r['results']:
value = r['results'][key]
if key.lower() != 'day_length':
value = self._getLocalDatetime(value)
self._data[key] = value
self._data['date'] = self._getLocalDatetime(r['results']['sunrise'], '%d-%m-%Y')
self._session = requests.Session()
payload = {
'lat': lat,
'lng': lon,
'date': dateStr,
'formatted': 0
}
r = self._session.get(SUN_URL, params = payload)

if r.status_code == 200:
r = r.json()
if r['status'].lower() == 'ok':
for key in r['results']:
value = r['results'][key]
if key.lower() != 'day_length':
value = self._getLocalDatetime(value)
self._data[key] = value
self._data['date'] = self._getLocalDatetime(r['results']['sunrise'], '%d-%m-%Y')

def get(self, key):
return self._data[key]
Expand Down

0 comments on commit 8772248

Please sign in to comment.