Migrate environment_canada to native_* (#74048)
This commit is contained in:
parent
7d709c074d
commit
f66fc65d0b
1 changed files with 25 additions and 20 deletions
|
@ -17,14 +17,19 @@ from homeassistant.components.weather import (
|
||||||
ATTR_CONDITION_SUNNY,
|
ATTR_CONDITION_SUNNY,
|
||||||
ATTR_CONDITION_WINDY,
|
ATTR_CONDITION_WINDY,
|
||||||
ATTR_FORECAST_CONDITION,
|
ATTR_FORECAST_CONDITION,
|
||||||
|
ATTR_FORECAST_NATIVE_TEMP,
|
||||||
|
ATTR_FORECAST_NATIVE_TEMP_LOW,
|
||||||
ATTR_FORECAST_PRECIPITATION_PROBABILITY,
|
ATTR_FORECAST_PRECIPITATION_PROBABILITY,
|
||||||
ATTR_FORECAST_TEMP,
|
|
||||||
ATTR_FORECAST_TEMP_LOW,
|
|
||||||
ATTR_FORECAST_TIME,
|
ATTR_FORECAST_TIME,
|
||||||
WeatherEntity,
|
WeatherEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
@ -63,6 +68,11 @@ async def async_setup_entry(
|
||||||
class ECWeather(CoordinatorEntity, WeatherEntity):
|
class ECWeather(CoordinatorEntity, WeatherEntity):
|
||||||
"""Representation of a weather condition."""
|
"""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):
|
def __init__(self, coordinator, hourly):
|
||||||
"""Initialize Environment Canada weather."""
|
"""Initialize Environment Canada weather."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
@ -78,7 +88,7 @@ class ECWeather(CoordinatorEntity, WeatherEntity):
|
||||||
self._hourly = hourly
|
self._hourly = hourly
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature(self):
|
def native_temperature(self):
|
||||||
"""Return the temperature."""
|
"""Return the temperature."""
|
||||||
if (
|
if (
|
||||||
temperature := self.ec_data.conditions.get("temperature", {}).get("value")
|
temperature := self.ec_data.conditions.get("temperature", {}).get("value")
|
||||||
|
@ -92,11 +102,6 @@ class ECWeather(CoordinatorEntity, WeatherEntity):
|
||||||
return float(temperature)
|
return float(temperature)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
|
||||||
def temperature_unit(self):
|
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return TEMP_CELSIUS
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def humidity(self):
|
def humidity(self):
|
||||||
"""Return the humidity."""
|
"""Return the humidity."""
|
||||||
|
@ -105,7 +110,7 @@ class ECWeather(CoordinatorEntity, WeatherEntity):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wind_speed(self):
|
def native_wind_speed(self):
|
||||||
"""Return the wind speed."""
|
"""Return the wind speed."""
|
||||||
if self.ec_data.conditions.get("wind_speed", {}).get("value"):
|
if self.ec_data.conditions.get("wind_speed", {}).get("value"):
|
||||||
return float(self.ec_data.conditions["wind_speed"]["value"])
|
return float(self.ec_data.conditions["wind_speed"]["value"])
|
||||||
|
@ -119,14 +124,14 @@ class ECWeather(CoordinatorEntity, WeatherEntity):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pressure(self):
|
def native_pressure(self):
|
||||||
"""Return the pressure."""
|
"""Return the pressure."""
|
||||||
if self.ec_data.conditions.get("pressure", {}).get("value"):
|
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
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def visibility(self):
|
def native_visibility(self):
|
||||||
"""Return the visibility."""
|
"""Return the visibility."""
|
||||||
if self.ec_data.conditions.get("visibility", {}).get("value"):
|
if self.ec_data.conditions.get("visibility", {}).get("value"):
|
||||||
return float(self.ec_data.conditions["visibility"]["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":
|
if half_days[0]["temperature_class"] == "high":
|
||||||
today.update(
|
today.update(
|
||||||
{
|
{
|
||||||
ATTR_FORECAST_TEMP: int(half_days[0]["temperature"]),
|
ATTR_FORECAST_NATIVE_TEMP: int(half_days[0]["temperature"]),
|
||||||
ATTR_FORECAST_TEMP_LOW: int(half_days[1]["temperature"]),
|
ATTR_FORECAST_NATIVE_TEMP_LOW: int(half_days[1]["temperature"]),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
half_days = half_days[2:]
|
half_days = half_days[2:]
|
||||||
else:
|
else:
|
||||||
today.update(
|
today.update(
|
||||||
{
|
{
|
||||||
ATTR_FORECAST_TEMP: None,
|
ATTR_FORECAST_NATIVE_TEMP: None,
|
||||||
ATTR_FORECAST_TEMP_LOW: int(half_days[0]["temperature"]),
|
ATTR_FORECAST_NATIVE_TEMP_LOW: int(half_days[0]["temperature"]),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
half_days = half_days[1:]
|
half_days = half_days[1:]
|
||||||
|
@ -197,8 +202,8 @@ def get_forecast(ec_data, hourly):
|
||||||
ATTR_FORECAST_TIME: (
|
ATTR_FORECAST_TIME: (
|
||||||
dt.now() + datetime.timedelta(days=day)
|
dt.now() + datetime.timedelta(days=day)
|
||||||
).isoformat(),
|
).isoformat(),
|
||||||
ATTR_FORECAST_TEMP: int(half_days[high]["temperature"]),
|
ATTR_FORECAST_NATIVE_TEMP: int(half_days[high]["temperature"]),
|
||||||
ATTR_FORECAST_TEMP_LOW: int(half_days[low]["temperature"]),
|
ATTR_FORECAST_NATIVE_TEMP_LOW: int(half_days[low]["temperature"]),
|
||||||
ATTR_FORECAST_CONDITION: icon_code_to_condition(
|
ATTR_FORECAST_CONDITION: icon_code_to_condition(
|
||||||
int(half_days[high]["icon_code"])
|
int(half_days[high]["icon_code"])
|
||||||
),
|
),
|
||||||
|
@ -213,7 +218,7 @@ def get_forecast(ec_data, hourly):
|
||||||
forecast_array.append(
|
forecast_array.append(
|
||||||
{
|
{
|
||||||
ATTR_FORECAST_TIME: hour["period"].isoformat(),
|
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(
|
ATTR_FORECAST_CONDITION: icon_code_to_condition(
|
||||||
int(hour["icon_code"])
|
int(hour["icon_code"])
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue