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 05a0a36

Browse files
committed
Revert "Fix parsing of numbers > 1000, add incidence"
This reverts commit 1e8a0bc.
1 parent 2c2ce2b commit 05a0a36

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

custom_components/coronavirus_hessen/__init__.py

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

8181
try:
8282
county = line[0].text.strip()
83-
cases = parse_num(line[1].text.strip())
84-
deaths = parse_num(line[2].text.strip())
85-
incidence = parse_num(line[3].text.strip(), t=float)
86-
except:
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:
8796
_LOGGER.error("Error processing line {}, skipping".format(line))
8897
continue
8998

9099
if county == "Gesamt":
91100
county = OPTION_TOTAL
92-
result[county] = dict(cases=cases, deaths=deaths, incidence=incidence)
101+
result[county] = dict(cases=cases, deaths=deaths)
93102

94103
_LOGGER.debug("Corona Hessen: {!r}".format(result))
95104
return result
@@ -103,10 +112,3 @@ async def async_get_data():
103112
)
104113
await hass.data[DOMAIN].async_refresh()
105114
return hass.data[DOMAIN]
106-
107-
108-
def parse_num(s, t=int):
109-
if len(s) and s != "-":
110-
return t(s.replace(".", "").replace(",", "."))
111-
else:
112-
return 0

custom_components/coronavirus_hessen/sensor.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
_LOGGER = logging.getLogger(__name__)
1313

1414
ATTR_DEATHS = "deaths"
15-
ATTR_INCIDENCE = "incidence"
1615

1716
async def async_setup_entry(hass, config_entry, async_add_entities):
1817
"""Defer sensor setup to the shared sensor module."""
@@ -55,9 +54,7 @@ def state(self):
5554

5655
@property
5756
def device_state_attributes(self):
58-
return {ATTR_ATTRIBUTION: ATTRIBUTION,
59-
ATTR_DEATHS: self.coordinator.data[self.county]["deaths"],
60-
ATTR_INCIDENCE: self.coordinator.data[self.county]["incidence"]}
57+
return {ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_DEATHS: self.coordinator.data[self.county]["deaths"]}
6158

6259
async def async_added_to_hass(self):
6360
"""When entity is added to hass."""

0 commit comments

Comments
 (0)