diff --git a/custom_components/coronavirus_hessen/__init__.py b/custom_components/coronavirus_hessen/__init__.py index a3ebc8e..adce436 100644 --- a/custom_components/coronavirus_hessen/__init__.py +++ b/custom_components/coronavirus_hessen/__init__.py @@ -75,23 +75,30 @@ async def async_get_data(): for row in rows[1:]: line = row.select("td") - if len(line) != 3: + if len(line) != 4: continue try: county = line[0].text.strip() 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 death_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] = cases + result[county] = dict(cases=cases, deaths=deaths) _LOGGER.debug("Corona Hessen: {!r}".format(result)) return result diff --git a/custom_components/coronavirus_hessen/sensor.py b/custom_components/coronavirus_hessen/sensor.py index d74ed39..b2a0ad0 100644 --- a/custom_components/coronavirus_hessen/sensor.py +++ b/custom_components/coronavirus_hessen/sensor.py @@ -11,6 +11,8 @@ _LOGGER = logging.getLogger(__name__) +ATTR_DEATHS = "deaths" + async def async_setup_entry(hass, config_entry, async_add_entities): """Defer sensor setup to the shared sensor module.""" coordinator = await get_coordinator(hass) @@ -48,11 +50,11 @@ def unit_of_measurement(self): @property def state(self): - return self.coordinator.data[self.county] + return self.coordinator.data[self.county]["cases"] @property def device_state_attributes(self): - return {ATTR_ATTRIBUTION: ATTRIBUTION} + 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."""