Skip to content

Commit

Permalink
Merge pull request #5 from Squixx/fix-errors-out-on-no-prognose
Browse files Browse the repository at this point in the history
fix: gracefully return 0 if no prognose is available
  • Loading branch information
nelbs authored Dec 11, 2021
2 parents 70318f5 + d2e00b7 commit 3294129
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions custom_components/mindergas/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,18 @@ def update(self):
n += 1

if URL_RESULT == URL_DASHBOARD:
# Scrape url
raw_html = session_requests.get(URL_DATA, headers=dict(referer=URL_DATA)).text
data = BeautifulSoup(raw_html, 'html.parser')

# Scrape prognose
div = data.find_all("div", class_="table_cell")[9]
result = round(eval(div.get_text().replace('m3','').replace(',' , '.').rstrip()))
self._attributes['last_update'] = dt.now().isoformat('T')
self._state = result
try:
# Scrape url
raw_html = session_requests.get(URL_DATA, headers=dict(referer=URL_DATA)).text
data = BeautifulSoup(raw_html, 'html.parser')

# Scrape prognose
div = data.find_all("div", class_="table_cell")[9]
result = round(eval(div.get_text().replace('m3','').replace(',' , '.').rstrip()))
self._attributes['last_update'] = dt.now().isoformat('T')
self._state = result
except:
self._state = 0
else:
pass

Expand Down

0 comments on commit 3294129

Please sign in to comment.