From c092f2be049d61b97cbfc6a97113d02166c1139b Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 29 Nov 2022 18:13:05 +0100 Subject: [PATCH] Use new unit enums in weather integrations (#82938) --- .../components/accuweather/weather.py | 35 ++++++++----------- homeassistant/components/aemet/weather.py | 16 ++++----- .../components/buienradar/weather.py | 20 +++++------ homeassistant/components/darksky/weather.py | 20 +++++------ homeassistant/components/ecobee/weather.py | 16 ++++----- .../components/environment_canada/weather.py | 16 ++++----- .../components/homematicip_cloud/weather.py | 10 +++--- homeassistant/components/ipma/weather.py | 12 +++---- homeassistant/components/knx/weather.py | 12 +++---- homeassistant/components/met/weather.py | 16 ++++----- .../components/met_eireann/weather.py | 16 ++++----- .../components/meteo_france/weather.py | 16 ++++----- .../components/meteoclimatic/weather.py | 8 ++--- homeassistant/components/metoffice/weather.py | 8 ++--- homeassistant/components/nws/weather.py | 24 ++++++------- .../components/open_meteo/weather.py | 12 +++---- .../components/openweathermap/weather.py | 16 ++++----- homeassistant/components/smhi/weather.py | 22 ++++++------ homeassistant/components/zamg/weather.py | 16 ++++----- 19 files changed, 151 insertions(+), 160 deletions(-) diff --git a/homeassistant/components/accuweather/weather.py b/homeassistant/components/accuweather/weather.py index 82db25288b8..5c5ba303ad5 100644 --- a/homeassistant/components/accuweather/weather.py +++ b/homeassistant/components/accuweather/weather.py @@ -18,16 +18,11 @@ from homeassistant.components.weather import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - LENGTH_INCHES, - LENGTH_KILOMETERS, - LENGTH_MILES, - LENGTH_MILLIMETERS, - PRESSURE_HPA, - PRESSURE_INHG, - SPEED_KILOMETERS_PER_HOUR, - SPEED_MILES_PER_HOUR, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfLength, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -72,19 +67,19 @@ class AccuWeatherEntity( # converted, hence the weather entity's native units follow the configured unit # system if coordinator.hass.config.units is METRIC_SYSTEM: - self._attr_native_precipitation_unit = LENGTH_MILLIMETERS - self._attr_native_pressure_unit = PRESSURE_HPA - self._attr_native_temperature_unit = TEMP_CELSIUS - self._attr_native_visibility_unit = LENGTH_KILOMETERS - self._attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR + self._attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS + self._attr_native_pressure_unit = UnitOfPressure.HPA + self._attr_native_temperature_unit = UnitOfTemperature.CELSIUS + self._attr_native_visibility_unit = UnitOfLength.KILOMETERS + self._attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR self._unit_system = API_METRIC else: self._unit_system = API_IMPERIAL - self._attr_native_precipitation_unit = LENGTH_INCHES - self._attr_native_pressure_unit = PRESSURE_INHG - self._attr_native_temperature_unit = TEMP_FAHRENHEIT - self._attr_native_visibility_unit = LENGTH_MILES - self._attr_native_wind_speed_unit = SPEED_MILES_PER_HOUR + self._attr_native_precipitation_unit = UnitOfPrecipitationDepth.INCHES + self._attr_native_pressure_unit = UnitOfPressure.INHG + self._attr_native_temperature_unit = UnitOfTemperature.FAHRENHEIT + self._attr_native_visibility_unit = UnitOfLength.MILES + self._attr_native_wind_speed_unit = UnitOfSpeed.MILES_PER_HOUR self._attr_unique_id = coordinator.location_key self._attr_attribution = ATTRIBUTION self._attr_device_info = coordinator.device_info diff --git a/homeassistant/components/aemet/weather.py b/homeassistant/components/aemet/weather.py index 695ae283a47..3753d8e33ff 100644 --- a/homeassistant/components/aemet/weather.py +++ b/homeassistant/components/aemet/weather.py @@ -12,10 +12,10 @@ from homeassistant.components.weather import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - LENGTH_MILLIMETERS, - PRESSURE_HPA, - SPEED_KILOMETERS_PER_HOUR, - TEMP_CELSIUS, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -91,10 +91,10 @@ class AemetWeather(CoordinatorEntity[WeatherUpdateCoordinator], WeatherEntity): """Implementation of an AEMET OpenData sensor.""" _attr_attribution = ATTRIBUTION - _attr_native_precipitation_unit = LENGTH_MILLIMETERS - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR def __init__( self, diff --git a/homeassistant/components/buienradar/weather.py b/homeassistant/components/buienradar/weather.py index 6fdf5c166ee..4cee98c07b7 100644 --- a/homeassistant/components/buienradar/weather.py +++ b/homeassistant/components/buienradar/weather.py @@ -41,11 +41,11 @@ from homeassistant.const import ( CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, - LENGTH_METERS, - LENGTH_MILLIMETERS, - PRESSURE_HPA, - SPEED_METERS_PER_SECOND, - TEMP_CELSIUS, + UnitOfLength, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -120,11 +120,11 @@ async def async_setup_entry( class BrWeather(WeatherEntity): """Representation of a weather condition.""" - _attr_native_precipitation_unit = LENGTH_MILLIMETERS - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_visibility_unit = LENGTH_METERS - _attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_visibility_unit = UnitOfLength.METERS + _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND def __init__(self, data, config, coordinates): """Initialize the platform with a data instance and station name.""" diff --git a/homeassistant/components/darksky/weather.py b/homeassistant/components/darksky/weather.py index 88f3b6b2bc9..530f1788dd8 100644 --- a/homeassistant/components/darksky/weather.py +++ b/homeassistant/components/darksky/weather.py @@ -36,11 +36,11 @@ from homeassistant.const import ( CONF_LONGITUDE, CONF_MODE, CONF_NAME, - LENGTH_KILOMETERS, - LENGTH_MILLIMETERS, - PRESSURE_MBAR, - SPEED_METERS_PER_SECOND, - TEMP_CELSIUS, + UnitOfLength, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -113,11 +113,11 @@ def setup_platform( class DarkSkyWeather(WeatherEntity): """Representation of a weather condition.""" - _attr_native_precipitation_unit = LENGTH_MILLIMETERS - _attr_native_pressure_unit = PRESSURE_MBAR - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_visibility_unit = LENGTH_KILOMETERS - _attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS + _attr_native_pressure_unit = UnitOfPressure.MBAR + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_visibility_unit = UnitOfLength.KILOMETERS + _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND def __init__(self, name, dark_sky, mode): """Initialize Dark Sky weather.""" diff --git a/homeassistant/components/ecobee/weather.py b/homeassistant/components/ecobee/weather.py index 69f02d26294..5610cdb2a9c 100644 --- a/homeassistant/components/ecobee/weather.py +++ b/homeassistant/components/ecobee/weather.py @@ -16,10 +16,10 @@ from homeassistant.components.weather import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - LENGTH_METERS, - PRESSURE_HPA, - SPEED_METERS_PER_SECOND, - TEMP_FAHRENHEIT, + UnitOfLength, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo @@ -53,10 +53,10 @@ async def async_setup_entry( class EcobeeWeather(WeatherEntity): """Representation of Ecobee weather data.""" - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_temperature_unit = TEMP_FAHRENHEIT - _attr_native_visibility_unit = LENGTH_METERS - _attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_temperature_unit = UnitOfTemperature.FAHRENHEIT + _attr_native_visibility_unit = UnitOfLength.METERS + _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND def __init__(self, data, name, index): """Initialize the Ecobee weather platform.""" diff --git a/homeassistant/components/environment_canada/weather.py b/homeassistant/components/environment_canada/weather.py index 8dbf8c15731..74bf9c8ca54 100644 --- a/homeassistant/components/environment_canada/weather.py +++ b/homeassistant/components/environment_canada/weather.py @@ -25,10 +25,10 @@ from homeassistant.components.weather import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - LENGTH_KILOMETERS, - PRESSURE_KPA, - SPEED_KILOMETERS_PER_HOUR, - TEMP_CELSIUS, + UnitOfLength, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -70,10 +70,10 @@ class ECWeather(CoordinatorEntity, WeatherEntity): """Representation of a weather condition.""" _attr_has_entity_name = True - _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 + _attr_native_pressure_unit = UnitOfPressure.KPA + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_visibility_unit = UnitOfLength.KILOMETERS + _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR def __init__(self, coordinator, hourly): """Initialize Environment Canada weather.""" diff --git a/homeassistant/components/homematicip_cloud/weather.py b/homeassistant/components/homematicip_cloud/weather.py index a52e99bfa4e..e913e1125f1 100644 --- a/homeassistant/components/homematicip_cloud/weather.py +++ b/homeassistant/components/homematicip_cloud/weather.py @@ -22,7 +22,7 @@ from homeassistant.components.weather import ( WeatherEntity, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import SPEED_KILOMETERS_PER_HOUR, TEMP_CELSIUS +from homeassistant.const import UnitOfSpeed, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -70,8 +70,8 @@ async def async_setup_entry( class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity): """Representation of the HomematicIP weather sensor plus & basic.""" - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the weather sensor.""" @@ -126,8 +126,8 @@ class HomematicipWeatherSensorPro(HomematicipWeatherSensor): class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity): """Representation of the HomematicIP home weather.""" - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR def __init__(self, hap: HomematicipHAP) -> None: """Initialize the home weather.""" diff --git a/homeassistant/components/ipma/weather.py b/homeassistant/components/ipma/weather.py index c448fad592d..467523c5830 100644 --- a/homeassistant/components/ipma/weather.py +++ b/homeassistant/components/ipma/weather.py @@ -38,9 +38,9 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_MODE, CONF_NAME, - PRESSURE_HPA, - SPEED_KILOMETERS_PER_HOUR, - TEMP_CELSIUS, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import entity_registry @@ -115,9 +115,9 @@ async def async_setup_entry( class IPMAWeather(WeatherEntity): """Representation of a weather condition.""" - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR _attr_attribution = ATTRIBUTION diff --git a/homeassistant/components/knx/weather.py b/homeassistant/components/knx/weather.py index 32f37ad2ac2..92034be95ff 100644 --- a/homeassistant/components/knx/weather.py +++ b/homeassistant/components/knx/weather.py @@ -9,10 +9,10 @@ from homeassistant.components.weather import WeatherEntity from homeassistant.const import ( CONF_ENTITY_CATEGORY, CONF_NAME, - PRESSURE_PA, - SPEED_METERS_PER_SECOND, - TEMP_CELSIUS, Platform, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -75,9 +75,9 @@ class KNXWeather(KnxEntity, WeatherEntity): """Representation of a KNX weather device.""" _device: XknxWeather - _attr_native_pressure_unit = PRESSURE_PA - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND + _attr_native_pressure_unit = UnitOfPressure.PA + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND def __init__(self, xknx: XKNX, config: ConfigType) -> None: """Initialize of a KNX sensor.""" diff --git a/homeassistant/components/met/weather.py b/homeassistant/components/met/weather.py index 2aa70929795..222d4a040e3 100644 --- a/homeassistant/components/met/weather.py +++ b/homeassistant/components/met/weather.py @@ -20,10 +20,10 @@ from homeassistant.const import ( CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, - LENGTH_MILLIMETERS, - PRESSURE_HPA, - SPEED_KILOMETERS_PER_HOUR, - TEMP_CELSIUS, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceEntryType @@ -76,10 +76,10 @@ class MetWeather(CoordinatorEntity[MetDataUpdateCoordinator], WeatherEntity): """Implementation of a Met.no weather condition.""" _attr_has_entity_name = True - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_precipitation_unit = LENGTH_MILLIMETERS - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR def __init__( self, diff --git a/homeassistant/components/met_eireann/weather.py b/homeassistant/components/met_eireann/weather.py index b872e9a8df6..c4d8763efa7 100644 --- a/homeassistant/components/met_eireann/weather.py +++ b/homeassistant/components/met_eireann/weather.py @@ -11,10 +11,10 @@ from homeassistant.const import ( CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, - LENGTH_MILLIMETERS, - PRESSURE_HPA, - SPEED_KILOMETERS_PER_HOUR, - TEMP_CELSIUS, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceEntryType @@ -55,10 +55,10 @@ async def async_setup_entry( class MetEireannWeather(CoordinatorEntity, WeatherEntity): """Implementation of a Met Éireann weather condition.""" - _attr_native_precipitation_unit = LENGTH_MILLIMETERS - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR def __init__(self, coordinator, config, hourly): """Initialise the platform with a data instance and site.""" diff --git a/homeassistant/components/meteo_france/weather.py b/homeassistant/components/meteo_france/weather.py index 787b82854af..bf0ff8c469e 100644 --- a/homeassistant/components/meteo_france/weather.py +++ b/homeassistant/components/meteo_france/weather.py @@ -15,10 +15,10 @@ from homeassistant.components.weather import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_MODE, - LENGTH_MILLIMETERS, - PRESSURE_HPA, - SPEED_METERS_PER_SECOND, - TEMP_CELSIUS, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceEntryType @@ -77,10 +77,10 @@ async def async_setup_entry( class MeteoFranceWeather(CoordinatorEntity, WeatherEntity): """Representation of a weather condition.""" - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_precipitation_unit = LENGTH_MILLIMETERS - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND def __init__(self, coordinator: DataUpdateCoordinator, mode: str) -> None: """Initialise the platform with a data instance and station name.""" diff --git a/homeassistant/components/meteoclimatic/weather.py b/homeassistant/components/meteoclimatic/weather.py index 8044dd04aa8..14b953663d0 100644 --- a/homeassistant/components/meteoclimatic/weather.py +++ b/homeassistant/components/meteoclimatic/weather.py @@ -3,7 +3,7 @@ from meteoclimatic import Condition from homeassistant.components.weather import WeatherEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import PRESSURE_HPA, SPEED_KILOMETERS_PER_HOUR, TEMP_CELSIUS +from homeassistant.const import UnitOfPressure, UnitOfSpeed, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.entity import DeviceInfo @@ -38,9 +38,9 @@ async def async_setup_entry( class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity): """Representation of a weather condition.""" - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR def __init__(self, coordinator: DataUpdateCoordinator) -> None: """Initialise the weather platform.""" diff --git a/homeassistant/components/metoffice/weather.py b/homeassistant/components/metoffice/weather.py index 4733ca6ea73..8257c8a3c35 100644 --- a/homeassistant/components/metoffice/weather.py +++ b/homeassistant/components/metoffice/weather.py @@ -15,7 +15,7 @@ from homeassistant.components.weather import ( WeatherEntity, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import PRESSURE_HPA, SPEED_MILES_PER_HOUR, TEMP_CELSIUS +from homeassistant.const import UnitOfPressure, UnitOfSpeed, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import ( @@ -82,9 +82,9 @@ class MetOfficeWeather( _attr_attribution = ATTRIBUTION _attr_has_entity_name = True - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_wind_speed_unit = SPEED_MILES_PER_HOUR + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_wind_speed_unit = UnitOfSpeed.MILES_PER_HOUR def __init__( self, diff --git a/homeassistant/components/nws/weather.py b/homeassistant/components/nws/weather.py index 7963c1161a9..341f35353ef 100644 --- a/homeassistant/components/nws/weather.py +++ b/homeassistant/components/nws/weather.py @@ -14,12 +14,10 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_LATITUDE, CONF_LONGITUDE, - LENGTH_METERS, - PRESSURE_PA, - SPEED_KILOMETERS_PER_HOUR, - SPEED_MILES_PER_HOUR, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfLength, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import DeviceInfo @@ -153,7 +151,7 @@ class NWSWeather(WeatherEntity): @property def native_temperature_unit(self): """Return the current temperature unit.""" - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS @property def native_pressure(self): @@ -165,7 +163,7 @@ class NWSWeather(WeatherEntity): @property def native_pressure_unit(self): """Return the current pressure unit.""" - return PRESSURE_PA + return UnitOfPressure.PA @property def humidity(self): @@ -184,7 +182,7 @@ class NWSWeather(WeatherEntity): @property def native_wind_speed_unit(self): """Return the current windspeed.""" - return SPEED_KILOMETERS_PER_HOUR + return UnitOfSpeed.KILOMETERS_PER_HOUR @property def wind_bearing(self): @@ -216,7 +214,7 @@ class NWSWeather(WeatherEntity): @property def native_visibility_unit(self): """Return visibility unit.""" - return LENGTH_METERS + return UnitOfLength.METERS @property def forecast(self): @@ -234,7 +232,7 @@ class NWSWeather(WeatherEntity): if (temp := forecast_entry.get("temperature")) is not None: data[ATTR_FORECAST_NATIVE_TEMP] = TemperatureConverter.convert( - temp, TEMP_FAHRENHEIT, TEMP_CELSIUS + temp, UnitOfTemperature.FAHRENHEIT, UnitOfTemperature.CELSIUS ) else: data[ATTR_FORECAST_NATIVE_TEMP] = None @@ -254,7 +252,9 @@ class NWSWeather(WeatherEntity): wind_speed = forecast_entry.get("windSpeedAvg") if wind_speed is not None: data[ATTR_FORECAST_NATIVE_WIND_SPEED] = SpeedConverter.convert( - wind_speed, SPEED_MILES_PER_HOUR, SPEED_KILOMETERS_PER_HOUR + wind_speed, + UnitOfSpeed.MILES_PER_HOUR, + UnitOfSpeed.KILOMETERS_PER_HOUR, ) else: data[ATTR_FORECAST_NATIVE_WIND_SPEED] = None diff --git a/homeassistant/components/open_meteo/weather.py b/homeassistant/components/open_meteo/weather.py index 6af9900ec15..614aed6eefb 100644 --- a/homeassistant/components/open_meteo/weather.py +++ b/homeassistant/components/open_meteo/weather.py @@ -5,11 +5,7 @@ from open_meteo import Forecast as OpenMeteoForecast from homeassistant.components.weather import Forecast, WeatherEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - LENGTH_MILLIMETERS, - SPEED_KILOMETERS_PER_HOUR, - TEMP_CELSIUS, -) +from homeassistant.const import UnitOfPrecipitationDepth, UnitOfSpeed, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.entity import DeviceInfo @@ -38,9 +34,9 @@ class OpenMeteoWeatherEntity( """Defines an Open-Meteo weather entity.""" _attr_has_entity_name = True - _attr_native_precipitation_unit = LENGTH_MILLIMETERS - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR def __init__( self, diff --git a/homeassistant/components/openweathermap/weather.py b/homeassistant/components/openweathermap/weather.py index 814dc7dfd02..da29031d513 100644 --- a/homeassistant/components/openweathermap/weather.py +++ b/homeassistant/components/openweathermap/weather.py @@ -18,10 +18,10 @@ from homeassistant.components.weather import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - LENGTH_MILLIMETERS, - PRESSURE_HPA, - SPEED_METERS_PER_SECOND, - TEMP_CELSIUS, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceEntryType @@ -89,10 +89,10 @@ class OpenWeatherMapWeather(WeatherEntity): _attr_attribution = ATTRIBUTION _attr_should_poll = False - _attr_native_precipitation_unit = LENGTH_MILLIMETERS - _attr_native_pressure_unit = PRESSURE_HPA - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS + _attr_native_pressure_unit = UnitOfPressure.HPA + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND def __init__( self, diff --git a/homeassistant/components/smhi/weather.py b/homeassistant/components/smhi/weather.py index a02a627b7f2..12781df6891 100644 --- a/homeassistant/components/smhi/weather.py +++ b/homeassistant/components/smhi/weather.py @@ -45,11 +45,11 @@ from homeassistant.const import ( CONF_LOCATION, CONF_LONGITUDE, CONF_NAME, - LENGTH_KILOMETERS, - LENGTH_MILLIMETERS, - PRESSURE_HPA, - SPEED_METERS_PER_SECOND, - TEMP_CELSIUS, + UnitOfLength, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers import aiohttp_client @@ -121,11 +121,11 @@ class SmhiWeather(WeatherEntity): """Representation of a weather entity.""" _attr_attribution = "Swedish weather institute (SMHI)" - _attr_native_temperature_unit = TEMP_CELSIUS - _attr_native_visibility_unit = LENGTH_KILOMETERS - _attr_native_precipitation_unit = LENGTH_MILLIMETERS - _attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND - _attr_native_pressure_unit = PRESSURE_HPA + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_visibility_unit = UnitOfLength.KILOMETERS + _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS + _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND + _attr_native_pressure_unit = UnitOfPressure.HPA _attr_has_entity_name = True @@ -158,7 +158,7 @@ class SmhiWeather(WeatherEntity): if self._forecasts: wind_gust = SpeedConverter.convert( self._forecasts[0].wind_gust, - SPEED_METERS_PER_SECOND, + UnitOfSpeed.METERS_PER_SECOND, self._wind_speed_unit, ) return { diff --git a/homeassistant/components/zamg/weather.py b/homeassistant/components/zamg/weather.py index b9d8ba67bbf..39c9d77f071 100644 --- a/homeassistant/components/zamg/weather.py +++ b/homeassistant/components/zamg/weather.py @@ -9,10 +9,10 @@ from homeassistant.const import ( CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, - LENGTH_MILLIMETERS, - PRESSURE_HPA, - SPEED_METERS_PER_SECOND, - TEMP_CELSIUS, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv @@ -83,10 +83,10 @@ class ZamgWeather(CoordinatorEntity, WeatherEntity): name=coordinator.name, ) # set units of ZAMG API - self._attr_native_temperature_unit = TEMP_CELSIUS - self._attr_native_pressure_unit = PRESSURE_HPA - self._attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND - self._attr_native_precipitation_unit = LENGTH_MILLIMETERS + self._attr_native_temperature_unit = UnitOfTemperature.CELSIUS + self._attr_native_pressure_unit = UnitOfPressure.HPA + self._attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND + self._attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS @property def condition(self) -> str | None: