WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
This repository was archived by the owner on Nov 19, 2021. It is now read-only.

Commit 056d9a4

Browse files
committed
Fix parsing of values > 1000
1 parent 05a0a36 commit 056d9a4

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

custom_components/coronavirus_hessen/__init__.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,10 @@ async def async_get_data():
8080

8181
try:
8282
county = line[0].text.strip()
83-
cases_str = line[1].text.strip()
84-
deaths_str = line[3].text.strip()
85-
86-
if len(cases_str) and cases_str != "-":
87-
cases = int(cases_str)
88-
else:
89-
cases = 0
90-
91-
if len(deaths_str) and deaths_str != "-":
92-
deaths = int(deaths_str)
93-
else:
94-
deaths = 0
95-
except ValueError:
96-
_LOGGER.error("Error processing line {}, skipping".format(line))
83+
cases = parse_num(line[1].text.strip())
84+
deaths = parse_num(line[3].text.strip())
85+
except:
86+
_LOGGER.exception("Error processing line {}, skipping".format(line))
9787
continue
9888

9989
if county == "Gesamt":
@@ -112,3 +102,9 @@ async def async_get_data():
112102
)
113103
await hass.data[DOMAIN].async_refresh()
114104
return hass.data[DOMAIN]
105+
106+
107+
def parse_num(s, t=int):
108+
if len(s) and s != "-":
109+
return t(s.replace(".", "").replace(",", "."))
110+
return 0

0 commit comments

Comments
 (0)