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
This repository was archived by the owner on Nov 19, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +15
-16
lines changed
custom_components/coronavirus_hessen Expand file tree Collapse file tree 2 files changed +15
-16
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1212_LOGGER = logging .getLogger (__name__ )
1313
1414ATTR_DEATHS = "deaths"
15- ATTR_INCIDENCE = "incidence"
1615
1716async 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."""
You can’t perform that action at this time.
0 commit comments