diff --git a/homeassistant/components/environment_canada/weather.py b/homeassistant/components/environment_canada/weather.py index b79323b0462..40706ffb6c1 100644 --- a/homeassistant/components/environment_canada/weather.py +++ b/homeassistant/components/environment_canada/weather.py @@ -17,14 +17,19 @@ from homeassistant.components.weather import ( ATTR_CONDITION_SUNNY, ATTR_CONDITION_WINDY, ATTR_FORECAST_CONDITION, + ATTR_FORECAST_NATIVE_TEMP, + ATTR_FORECAST_NATIVE_TEMP_LOW, ATTR_FORECAST_PRECIPITATION_PROBABILITY, - ATTR_FORECAST_TEMP, - ATTR_FORECAST_TEMP_LOW, ATTR_FORECAST_TIME, WeatherEntity, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import ( + LENGTH_KILOMETERS, + PRESSURE_KPA, + SPEED_KILOMETERS_PER_HOUR, + TEMP_CELSIUS, +) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -63,6 +68,11 @@ async def async_setup_entry( class ECWeather(CoordinatorEntity, WeatherEntity): """Representation of a weather condition.""" + _attr_native_pressure_unit = PRESSURE_KPA + _attr_native_temperature_unit = TEMP_CELSIUS + _attr_native_visibility_unit = LENGTH_KILOMETERS + _attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR + def __init__(self, coordinator, hourly): """Initialize Environment Canada weather.""" super().__init__(coordinator) @@ -78,7 +88,7 @@ class ECWeather(CoordinatorEntity, WeatherEntity): self._hourly = hourly @property - def temperature(self): + def native_temperature(self): """Return the temperature.""" if ( temperature := self.ec_data.conditions.get("temperature", {}).get("value") @@ -92,11 +102,6 @@ class ECWeather(CoordinatorEntity, WeatherEntity): return float(temperature) return None - @property - def temperature_unit(self): - """Return the unit of measurement.""" - return TEMP_CELSIUS - @property def humidity(self): """Return the humidity.""" @@ -105,7 +110,7 @@ class ECWeather(CoordinatorEntity, WeatherEntity): return None @property - def wind_speed(self): + def native_wind_speed(self): """Return the wind speed.""" if self.ec_data.conditions.get("wind_speed", {}).get("value"): return float(self.ec_data.conditions["wind_speed"]["value"]) @@ -119,14 +124,14 @@ class ECWeather(CoordinatorEntity, WeatherEntity): return None @property - def pressure(self): + def native_pressure(self): """Return the pressure.""" if self.ec_data.conditions.get("pressure", {}).get("value"): - return 10 * float(self.ec_data.conditions["pressure"]["value"]) + return float(self.ec_data.conditions["pressure"]["value"]) return None @property - def visibility(self): + def native_visibility(self): """Return the visibility.""" if self.ec_data.conditions.get("visibility", {}).get("value"): return float(self.ec_data.conditions["visibility"]["value"]) @@ -175,16 +180,16 @@ def get_forecast(ec_data, hourly): if half_days[0]["temperature_class"] == "high": today.update( { - ATTR_FORECAST_TEMP: int(half_days[0]["temperature"]), - ATTR_FORECAST_TEMP_LOW: int(half_days[1]["temperature"]), + ATTR_FORECAST_NATIVE_TEMP: int(half_days[0]["temperature"]), + ATTR_FORECAST_NATIVE_TEMP_LOW: int(half_days[1]["temperature"]), } ) half_days = half_days[2:] else: today.update( { - ATTR_FORECAST_TEMP: None, - ATTR_FORECAST_TEMP_LOW: int(half_days[0]["temperature"]), + ATTR_FORECAST_NATIVE_TEMP: None, + ATTR_FORECAST_NATIVE_TEMP_LOW: int(half_days[0]["temperature"]), } ) half_days = half_days[1:] @@ -197,8 +202,8 @@ def get_forecast(ec_data, hourly): ATTR_FORECAST_TIME: ( dt.now() + datetime.timedelta(days=day) ).isoformat(), - ATTR_FORECAST_TEMP: int(half_days[high]["temperature"]), - ATTR_FORECAST_TEMP_LOW: int(half_days[low]["temperature"]), + ATTR_FORECAST_NATIVE_TEMP: int(half_days[high]["temperature"]), + ATTR_FORECAST_NATIVE_TEMP_LOW: int(half_days[low]["temperature"]), ATTR_FORECAST_CONDITION: icon_code_to_condition( int(half_days[high]["icon_code"]) ), @@ -213,7 +218,7 @@ def get_forecast(ec_data, hourly): forecast_array.append( { ATTR_FORECAST_TIME: hour["period"].isoformat(), - ATTR_FORECAST_TEMP: int(hour["temperature"]), + ATTR_FORECAST_NATIVE_TEMP: int(hour["temperature"]), ATTR_FORECAST_CONDITION: icon_code_to_condition( int(hour["icon_code"]) ),