mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Use new unit enums in weather integrations (#82938)
This commit is contained in:
parent
4ad9633dfb
commit
c092f2be04
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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."""
|
||||
|
@ -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."""
|
||||
|
@ -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."""
|
||||
|
@ -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."""
|
||||
|
@ -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."""
|
||||
|
@ -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
|
||||
|
||||
|
@ -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."""
|
||||
|
@ -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,
|
||||
|
@ -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."""
|
||||
|
@ -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."""
|
||||
|
@ -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."""
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user