From 05a0a36a254a2bb14a08373556c8a10f7edfa763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sat, 21 Mar 2020 23:11:03 +0100 Subject: [PATCH] Revert "Fix parsing of numbers > 1000, add incidence" This reverts commit 1e8a0bc4d47402da5b9f6719cd5d8650d70a18f4. --- .../coronavirus_hessen/__init__.py | 26 ++++++++++--------- .../coronavirus_hessen/sensor.py | 5 +--- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/custom_components/coronavirus_hessen/__init__.py b/custom_components/coronavirus_hessen/__init__.py index 49f56f3..ba179df 100644 --- a/custom_components/coronavirus_hessen/__init__.py +++ b/custom_components/coronavirus_hessen/__init__.py @@ -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 @@ -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 \ No newline at end of file diff --git a/custom_components/coronavirus_hessen/sensor.py b/custom_components/coronavirus_hessen/sensor.py index 626dc47..b2a0ad0 100644 --- a/custom_components/coronavirus_hessen/sensor.py +++ b/custom_components/coronavirus_hessen/sensor.py @@ -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.""" @@ -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."""