Fix coronavirus worldwide sum (#36737)
Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>pull/37017/head
parent
82058f0b50
commit
149a3165e6
|
@ -51,9 +51,14 @@ class CoronavirusSensor(Entity):
|
||||||
def state(self):
|
def state(self):
|
||||||
"""State of the sensor."""
|
"""State of the sensor."""
|
||||||
if self.country == OPTION_WORLDWIDE:
|
if self.country == OPTION_WORLDWIDE:
|
||||||
return sum(
|
sum_cases = 0
|
||||||
getattr(case, self.info_type) for case in self.coordinator.data.values()
|
for case in self.coordinator.data.values():
|
||||||
)
|
value = getattr(case, self.info_type)
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
sum_cases += value
|
||||||
|
|
||||||
|
return sum_cases
|
||||||
|
|
||||||
return getattr(self.coordinator.data[self.country], self.info_type)
|
return getattr(self.coordinator.data[self.country], self.info_type)
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,13 @@ def mock_cases():
|
||||||
return_value=[
|
return_value=[
|
||||||
Mock(country="Netherlands", confirmed=10, recovered=8, deaths=1, current=1),
|
Mock(country="Netherlands", confirmed=10, recovered=8, deaths=1, current=1),
|
||||||
Mock(country="Germany", confirmed=1, recovered=0, deaths=0, current=0),
|
Mock(country="Germany", confirmed=1, recovered=0, deaths=0, current=0),
|
||||||
|
Mock(
|
||||||
|
country="Sweden",
|
||||||
|
confirmed=None,
|
||||||
|
recovered=None,
|
||||||
|
deaths=None,
|
||||||
|
current=None,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
) as mock_get_cases:
|
) as mock_get_cases:
|
||||||
yield mock_get_cases
|
yield mock_get_cases
|
||||||
|
|
Loading…
Reference in New Issue