Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Revert "Fix parsing of numbers > 1000, add incidence"
Browse files Browse the repository at this point in the history
This reverts commit 1e8a0bc.
  • Loading branch information
foosel committed Mar 21, 2020
1 parent 2c2ce2b commit 05a0a36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
26 changes: 14 additions & 12 deletions custom_components/coronavirus_hessen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,25 @@ async def async_get_data():

try:
county = line[0].text.strip()
cases = parse_num(line[1].text.strip())
deaths = parse_num(line[2].text.strip())
incidence = parse_num(line[3].text.strip(), t=float)
except:
cases_str = line[1].text.strip()
deaths_str = line[3].text.strip()

if len(cases_str) and cases_str != "-":
cases = int(cases_str)
else:
cases = 0

if len(deaths_str) and deaths_str != "-":
deaths = int(deaths_str)
else:
deaths = 0
except ValueError:
_LOGGER.error("Error processing line {}, skipping".format(line))
continue

if county == "Gesamt":
county = OPTION_TOTAL
result[county] = dict(cases=cases, deaths=deaths, incidence=incidence)
result[county] = dict(cases=cases, deaths=deaths)

_LOGGER.debug("Corona Hessen: {!r}".format(result))
return result
Expand All @@ -103,10 +112,3 @@ async def async_get_data():
)
await hass.data[DOMAIN].async_refresh()
return hass.data[DOMAIN]


def parse_num(s, t=int):
if len(s) and s != "-":
return t(s.replace(".", "").replace(",", "."))
else:
return 0
5 changes: 1 addition & 4 deletions custom_components/coronavirus_hessen/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
_LOGGER = logging.getLogger(__name__)

ATTR_DEATHS = "deaths"
ATTR_INCIDENCE = "incidence"

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

@property
def device_state_attributes(self):
return {ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_DEATHS: self.coordinator.data[self.county]["deaths"],
ATTR_INCIDENCE: self.coordinator.data[self.county]["incidence"]}
return {ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_DEATHS: self.coordinator.data[self.county]["deaths"]}

async def async_added_to_hass(self):
"""When entity is added to hass."""
Expand Down

0 comments on commit 05a0a36

Please sign in to comment.