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

Commit

Permalink
Adjusted for table changes again
Browse files Browse the repository at this point in the history
  • Loading branch information
foosel committed Mar 20, 2020
1 parent 8abaafa commit 2aca199
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 9 additions & 2 deletions custom_components/coronavirus_hessen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions custom_components/coronavirus_hessen/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 2aca199

Please sign in to comment.