Environment Canada: Fix for when temperature is zero (#69101)

This commit is contained in:
Glenn Waters 2022-04-02 03:44:40 -04:00 committed by GitHub
parent 538c8160f3
commit 912923f55d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,12 +80,16 @@ class ECWeather(CoordinatorEntity, WeatherEntity):
@property
def temperature(self):
"""Return the temperature."""
if self.ec_data.conditions.get("temperature", {}).get("value"):
return float(self.ec_data.conditions["temperature"]["value"])
if self.ec_data.hourly_forecasts and self.ec_data.hourly_forecasts[0].get(
"temperature"
if (
temperature := self.ec_data.conditions.get("temperature", {}).get("value")
) is not None:
return float(temperature)
if (
self.ec_data.hourly_forecasts
and (temperature := self.ec_data.hourly_forecasts[0].get("temperature"))
is not None
):
return float(self.ec_data.hourly_forecasts[0]["temperature"])
return float(temperature)
return None
@property