diff --git a/homeassistant/components/environment_canada/weather.py b/homeassistant/components/environment_canada/weather.py index 4d226261b94..1b81750fb47 100644 --- a/homeassistant/components/environment_canada/weather.py +++ b/homeassistant/components/environment_canada/weather.py @@ -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