mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +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.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
LENGTH_INCHES,
|
UnitOfLength,
|
||||||
LENGTH_KILOMETERS,
|
UnitOfPrecipitationDepth,
|
||||||
LENGTH_MILES,
|
UnitOfPressure,
|
||||||
LENGTH_MILLIMETERS,
|
UnitOfSpeed,
|
||||||
PRESSURE_HPA,
|
UnitOfTemperature,
|
||||||
PRESSURE_INHG,
|
|
||||||
SPEED_KILOMETERS_PER_HOUR,
|
|
||||||
SPEED_MILES_PER_HOUR,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
TEMP_FAHRENHEIT,
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
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
|
# converted, hence the weather entity's native units follow the configured unit
|
||||||
# system
|
# system
|
||||||
if coordinator.hass.config.units is METRIC_SYSTEM:
|
if coordinator.hass.config.units is METRIC_SYSTEM:
|
||||||
self._attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
self._attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
self._attr_native_pressure_unit = PRESSURE_HPA
|
self._attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
self._attr_native_temperature_unit = TEMP_CELSIUS
|
self._attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
self._attr_native_visibility_unit = LENGTH_KILOMETERS
|
self._attr_native_visibility_unit = UnitOfLength.KILOMETERS
|
||||||
self._attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
|
self._attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
self._unit_system = API_METRIC
|
self._unit_system = API_METRIC
|
||||||
else:
|
else:
|
||||||
self._unit_system = API_IMPERIAL
|
self._unit_system = API_IMPERIAL
|
||||||
self._attr_native_precipitation_unit = LENGTH_INCHES
|
self._attr_native_precipitation_unit = UnitOfPrecipitationDepth.INCHES
|
||||||
self._attr_native_pressure_unit = PRESSURE_INHG
|
self._attr_native_pressure_unit = UnitOfPressure.INHG
|
||||||
self._attr_native_temperature_unit = TEMP_FAHRENHEIT
|
self._attr_native_temperature_unit = UnitOfTemperature.FAHRENHEIT
|
||||||
self._attr_native_visibility_unit = LENGTH_MILES
|
self._attr_native_visibility_unit = UnitOfLength.MILES
|
||||||
self._attr_native_wind_speed_unit = SPEED_MILES_PER_HOUR
|
self._attr_native_wind_speed_unit = UnitOfSpeed.MILES_PER_HOUR
|
||||||
self._attr_unique_id = coordinator.location_key
|
self._attr_unique_id = coordinator.location_key
|
||||||
self._attr_attribution = ATTRIBUTION
|
self._attr_attribution = ATTRIBUTION
|
||||||
self._attr_device_info = coordinator.device_info
|
self._attr_device_info = coordinator.device_info
|
||||||
|
@ -12,10 +12,10 @@ from homeassistant.components.weather import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
LENGTH_MILLIMETERS,
|
UnitOfPrecipitationDepth,
|
||||||
PRESSURE_HPA,
|
UnitOfPressure,
|
||||||
SPEED_KILOMETERS_PER_HOUR,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -91,10 +91,10 @@ class AemetWeather(CoordinatorEntity[WeatherUpdateCoordinator], WeatherEntity):
|
|||||||
"""Implementation of an AEMET OpenData sensor."""
|
"""Implementation of an AEMET OpenData sensor."""
|
||||||
|
|
||||||
_attr_attribution = ATTRIBUTION
|
_attr_attribution = ATTRIBUTION
|
||||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
|
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -41,11 +41,11 @@ from homeassistant.const import (
|
|||||||
CONF_LATITUDE,
|
CONF_LATITUDE,
|
||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
LENGTH_METERS,
|
UnitOfLength,
|
||||||
LENGTH_MILLIMETERS,
|
UnitOfPrecipitationDepth,
|
||||||
PRESSURE_HPA,
|
UnitOfPressure,
|
||||||
SPEED_METERS_PER_SECOND,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -120,11 +120,11 @@ async def async_setup_entry(
|
|||||||
class BrWeather(WeatherEntity):
|
class BrWeather(WeatherEntity):
|
||||||
"""Representation of a weather condition."""
|
"""Representation of a weather condition."""
|
||||||
|
|
||||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_visibility_unit = LENGTH_METERS
|
_attr_native_visibility_unit = UnitOfLength.METERS
|
||||||
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
_attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
||||||
|
|
||||||
def __init__(self, data, config, coordinates):
|
def __init__(self, data, config, coordinates):
|
||||||
"""Initialize the platform with a data instance and station name."""
|
"""Initialize the platform with a data instance and station name."""
|
||||||
|
@ -36,11 +36,11 @@ from homeassistant.const import (
|
|||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
CONF_MODE,
|
CONF_MODE,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
LENGTH_KILOMETERS,
|
UnitOfLength,
|
||||||
LENGTH_MILLIMETERS,
|
UnitOfPrecipitationDepth,
|
||||||
PRESSURE_MBAR,
|
UnitOfPressure,
|
||||||
SPEED_METERS_PER_SECOND,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -113,11 +113,11 @@ def setup_platform(
|
|||||||
class DarkSkyWeather(WeatherEntity):
|
class DarkSkyWeather(WeatherEntity):
|
||||||
"""Representation of a weather condition."""
|
"""Representation of a weather condition."""
|
||||||
|
|
||||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
_attr_native_pressure_unit = PRESSURE_MBAR
|
_attr_native_pressure_unit = UnitOfPressure.MBAR
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_visibility_unit = LENGTH_KILOMETERS
|
_attr_native_visibility_unit = UnitOfLength.KILOMETERS
|
||||||
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
_attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
||||||
|
|
||||||
def __init__(self, name, dark_sky, mode):
|
def __init__(self, name, dark_sky, mode):
|
||||||
"""Initialize Dark Sky weather."""
|
"""Initialize Dark Sky weather."""
|
||||||
|
@ -16,10 +16,10 @@ from homeassistant.components.weather import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
LENGTH_METERS,
|
UnitOfLength,
|
||||||
PRESSURE_HPA,
|
UnitOfPressure,
|
||||||
SPEED_METERS_PER_SECOND,
|
UnitOfSpeed,
|
||||||
TEMP_FAHRENHEIT,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
@ -53,10 +53,10 @@ async def async_setup_entry(
|
|||||||
class EcobeeWeather(WeatherEntity):
|
class EcobeeWeather(WeatherEntity):
|
||||||
"""Representation of Ecobee weather data."""
|
"""Representation of Ecobee weather data."""
|
||||||
|
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_temperature_unit = TEMP_FAHRENHEIT
|
_attr_native_temperature_unit = UnitOfTemperature.FAHRENHEIT
|
||||||
_attr_native_visibility_unit = LENGTH_METERS
|
_attr_native_visibility_unit = UnitOfLength.METERS
|
||||||
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
_attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
||||||
|
|
||||||
def __init__(self, data, name, index):
|
def __init__(self, data, name, index):
|
||||||
"""Initialize the Ecobee weather platform."""
|
"""Initialize the Ecobee weather platform."""
|
||||||
|
@ -25,10 +25,10 @@ from homeassistant.components.weather import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
LENGTH_KILOMETERS,
|
UnitOfLength,
|
||||||
PRESSURE_KPA,
|
UnitOfPressure,
|
||||||
SPEED_KILOMETERS_PER_HOUR,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -70,10 +70,10 @@ class ECWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
"""Representation of a weather condition."""
|
"""Representation of a weather condition."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
_attr_native_pressure_unit = PRESSURE_KPA
|
_attr_native_pressure_unit = UnitOfPressure.KPA
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_visibility_unit = LENGTH_KILOMETERS
|
_attr_native_visibility_unit = UnitOfLength.KILOMETERS
|
||||||
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
|
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
|
|
||||||
def __init__(self, coordinator, hourly):
|
def __init__(self, coordinator, hourly):
|
||||||
"""Initialize Environment Canada weather."""
|
"""Initialize Environment Canada weather."""
|
||||||
|
@ -22,7 +22,7 @@ from homeassistant.components.weather import (
|
|||||||
WeatherEntity,
|
WeatherEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -70,8 +70,8 @@ async def async_setup_entry(
|
|||||||
class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity):
|
class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity):
|
||||||
"""Representation of the HomematicIP weather sensor plus & basic."""
|
"""Representation of the HomematicIP weather sensor plus & basic."""
|
||||||
|
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
|
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize the weather sensor."""
|
"""Initialize the weather sensor."""
|
||||||
@ -126,8 +126,8 @@ class HomematicipWeatherSensorPro(HomematicipWeatherSensor):
|
|||||||
class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity):
|
class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity):
|
||||||
"""Representation of the HomematicIP home weather."""
|
"""Representation of the HomematicIP home weather."""
|
||||||
|
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
|
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP) -> None:
|
def __init__(self, hap: HomematicipHAP) -> None:
|
||||||
"""Initialize the home weather."""
|
"""Initialize the home weather."""
|
||||||
|
@ -38,9 +38,9 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_MODE,
|
CONF_MODE,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
PRESSURE_HPA,
|
UnitOfPressure,
|
||||||
SPEED_KILOMETERS_PER_HOUR,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import entity_registry
|
from homeassistant.helpers import entity_registry
|
||||||
@ -115,9 +115,9 @@ async def async_setup_entry(
|
|||||||
class IPMAWeather(WeatherEntity):
|
class IPMAWeather(WeatherEntity):
|
||||||
"""Representation of a weather condition."""
|
"""Representation of a weather condition."""
|
||||||
|
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
|
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
|
|
||||||
_attr_attribution = ATTRIBUTION
|
_attr_attribution = ATTRIBUTION
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@ from homeassistant.components.weather import WeatherEntity
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_ENTITY_CATEGORY,
|
CONF_ENTITY_CATEGORY,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
PRESSURE_PA,
|
|
||||||
SPEED_METERS_PER_SECOND,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
Platform,
|
Platform,
|
||||||
|
UnitOfPressure,
|
||||||
|
UnitOfSpeed,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -75,9 +75,9 @@ class KNXWeather(KnxEntity, WeatherEntity):
|
|||||||
"""Representation of a KNX weather device."""
|
"""Representation of a KNX weather device."""
|
||||||
|
|
||||||
_device: XknxWeather
|
_device: XknxWeather
|
||||||
_attr_native_pressure_unit = PRESSURE_PA
|
_attr_native_pressure_unit = UnitOfPressure.PA
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
_attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
||||||
|
|
||||||
def __init__(self, xknx: XKNX, config: ConfigType) -> None:
|
def __init__(self, xknx: XKNX, config: ConfigType) -> None:
|
||||||
"""Initialize of a KNX sensor."""
|
"""Initialize of a KNX sensor."""
|
||||||
|
@ -20,10 +20,10 @@ from homeassistant.const import (
|
|||||||
CONF_LATITUDE,
|
CONF_LATITUDE,
|
||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
LENGTH_MILLIMETERS,
|
UnitOfPrecipitationDepth,
|
||||||
PRESSURE_HPA,
|
UnitOfPressure,
|
||||||
SPEED_KILOMETERS_PER_HOUR,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
@ -76,10 +76,10 @@ class MetWeather(CoordinatorEntity[MetDataUpdateCoordinator], WeatherEntity):
|
|||||||
"""Implementation of a Met.no weather condition."""
|
"""Implementation of a Met.no weather condition."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
|
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -11,10 +11,10 @@ from homeassistant.const import (
|
|||||||
CONF_LATITUDE,
|
CONF_LATITUDE,
|
||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
LENGTH_MILLIMETERS,
|
UnitOfPrecipitationDepth,
|
||||||
PRESSURE_HPA,
|
UnitOfPressure,
|
||||||
SPEED_KILOMETERS_PER_HOUR,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
@ -55,10 +55,10 @@ async def async_setup_entry(
|
|||||||
class MetEireannWeather(CoordinatorEntity, WeatherEntity):
|
class MetEireannWeather(CoordinatorEntity, WeatherEntity):
|
||||||
"""Implementation of a Met Éireann weather condition."""
|
"""Implementation of a Met Éireann weather condition."""
|
||||||
|
|
||||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
|
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
|
|
||||||
def __init__(self, coordinator, config, hourly):
|
def __init__(self, coordinator, config, hourly):
|
||||||
"""Initialise the platform with a data instance and site."""
|
"""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.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_MODE,
|
CONF_MODE,
|
||||||
LENGTH_MILLIMETERS,
|
UnitOfPrecipitationDepth,
|
||||||
PRESSURE_HPA,
|
UnitOfPressure,
|
||||||
SPEED_METERS_PER_SECOND,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
@ -77,10 +77,10 @@ async def async_setup_entry(
|
|||||||
class MeteoFranceWeather(CoordinatorEntity, WeatherEntity):
|
class MeteoFranceWeather(CoordinatorEntity, WeatherEntity):
|
||||||
"""Representation of a weather condition."""
|
"""Representation of a weather condition."""
|
||||||
|
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
_attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
||||||
|
|
||||||
def __init__(self, coordinator: DataUpdateCoordinator, mode: str) -> None:
|
def __init__(self, coordinator: DataUpdateCoordinator, mode: str) -> None:
|
||||||
"""Initialise the platform with a data instance and station name."""
|
"""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.components.weather import WeatherEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
@ -38,9 +38,9 @@ async def async_setup_entry(
|
|||||||
class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity):
|
class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity):
|
||||||
"""Representation of a weather condition."""
|
"""Representation of a weather condition."""
|
||||||
|
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
|
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
|
|
||||||
def __init__(self, coordinator: DataUpdateCoordinator) -> None:
|
def __init__(self, coordinator: DataUpdateCoordinator) -> None:
|
||||||
"""Initialise the weather platform."""
|
"""Initialise the weather platform."""
|
||||||
|
@ -15,7 +15,7 @@ from homeassistant.components.weather import (
|
|||||||
WeatherEntity,
|
WeatherEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
@ -82,9 +82,9 @@ class MetOfficeWeather(
|
|||||||
_attr_attribution = ATTRIBUTION
|
_attr_attribution = ATTRIBUTION
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_wind_speed_unit = SPEED_MILES_PER_HOUR
|
_attr_native_wind_speed_unit = UnitOfSpeed.MILES_PER_HOUR
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -14,12 +14,10 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_LATITUDE,
|
CONF_LATITUDE,
|
||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
LENGTH_METERS,
|
UnitOfLength,
|
||||||
PRESSURE_PA,
|
UnitOfPressure,
|
||||||
SPEED_KILOMETERS_PER_HOUR,
|
UnitOfSpeed,
|
||||||
SPEED_MILES_PER_HOUR,
|
UnitOfTemperature,
|
||||||
TEMP_CELSIUS,
|
|
||||||
TEMP_FAHRENHEIT,
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
@ -153,7 +151,7 @@ class NWSWeather(WeatherEntity):
|
|||||||
@property
|
@property
|
||||||
def native_temperature_unit(self):
|
def native_temperature_unit(self):
|
||||||
"""Return the current temperature unit."""
|
"""Return the current temperature unit."""
|
||||||
return TEMP_CELSIUS
|
return UnitOfTemperature.CELSIUS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_pressure(self):
|
def native_pressure(self):
|
||||||
@ -165,7 +163,7 @@ class NWSWeather(WeatherEntity):
|
|||||||
@property
|
@property
|
||||||
def native_pressure_unit(self):
|
def native_pressure_unit(self):
|
||||||
"""Return the current pressure unit."""
|
"""Return the current pressure unit."""
|
||||||
return PRESSURE_PA
|
return UnitOfPressure.PA
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def humidity(self):
|
def humidity(self):
|
||||||
@ -184,7 +182,7 @@ class NWSWeather(WeatherEntity):
|
|||||||
@property
|
@property
|
||||||
def native_wind_speed_unit(self):
|
def native_wind_speed_unit(self):
|
||||||
"""Return the current windspeed."""
|
"""Return the current windspeed."""
|
||||||
return SPEED_KILOMETERS_PER_HOUR
|
return UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wind_bearing(self):
|
def wind_bearing(self):
|
||||||
@ -216,7 +214,7 @@ class NWSWeather(WeatherEntity):
|
|||||||
@property
|
@property
|
||||||
def native_visibility_unit(self):
|
def native_visibility_unit(self):
|
||||||
"""Return visibility unit."""
|
"""Return visibility unit."""
|
||||||
return LENGTH_METERS
|
return UnitOfLength.METERS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def forecast(self):
|
def forecast(self):
|
||||||
@ -234,7 +232,7 @@ class NWSWeather(WeatherEntity):
|
|||||||
|
|
||||||
if (temp := forecast_entry.get("temperature")) is not None:
|
if (temp := forecast_entry.get("temperature")) is not None:
|
||||||
data[ATTR_FORECAST_NATIVE_TEMP] = TemperatureConverter.convert(
|
data[ATTR_FORECAST_NATIVE_TEMP] = TemperatureConverter.convert(
|
||||||
temp, TEMP_FAHRENHEIT, TEMP_CELSIUS
|
temp, UnitOfTemperature.FAHRENHEIT, UnitOfTemperature.CELSIUS
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
data[ATTR_FORECAST_NATIVE_TEMP] = None
|
data[ATTR_FORECAST_NATIVE_TEMP] = None
|
||||||
@ -254,7 +252,9 @@ class NWSWeather(WeatherEntity):
|
|||||||
wind_speed = forecast_entry.get("windSpeedAvg")
|
wind_speed = forecast_entry.get("windSpeedAvg")
|
||||||
if wind_speed is not None:
|
if wind_speed is not None:
|
||||||
data[ATTR_FORECAST_NATIVE_WIND_SPEED] = SpeedConverter.convert(
|
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:
|
else:
|
||||||
data[ATTR_FORECAST_NATIVE_WIND_SPEED] = None
|
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.components.weather import Forecast, WeatherEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import UnitOfPrecipitationDepth, UnitOfSpeed, UnitOfTemperature
|
||||||
LENGTH_MILLIMETERS,
|
|
||||||
SPEED_KILOMETERS_PER_HOUR,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
@ -38,9 +34,9 @@ class OpenMeteoWeatherEntity(
|
|||||||
"""Defines an Open-Meteo weather entity."""
|
"""Defines an Open-Meteo weather entity."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
|
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -18,10 +18,10 @@ from homeassistant.components.weather import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
LENGTH_MILLIMETERS,
|
UnitOfPrecipitationDepth,
|
||||||
PRESSURE_HPA,
|
UnitOfPressure,
|
||||||
SPEED_METERS_PER_SECOND,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
@ -89,10 +89,10 @@ class OpenWeatherMapWeather(WeatherEntity):
|
|||||||
_attr_attribution = ATTRIBUTION
|
_attr_attribution = ATTRIBUTION
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
_attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -45,11 +45,11 @@ from homeassistant.const import (
|
|||||||
CONF_LOCATION,
|
CONF_LOCATION,
|
||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
LENGTH_KILOMETERS,
|
UnitOfLength,
|
||||||
LENGTH_MILLIMETERS,
|
UnitOfPrecipitationDepth,
|
||||||
PRESSURE_HPA,
|
UnitOfPressure,
|
||||||
SPEED_METERS_PER_SECOND,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
@ -121,11 +121,11 @@ class SmhiWeather(WeatherEntity):
|
|||||||
"""Representation of a weather entity."""
|
"""Representation of a weather entity."""
|
||||||
|
|
||||||
_attr_attribution = "Swedish weather institute (SMHI)"
|
_attr_attribution = "Swedish weather institute (SMHI)"
|
||||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_native_visibility_unit = LENGTH_KILOMETERS
|
_attr_native_visibility_unit = UnitOfLength.KILOMETERS
|
||||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
_attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
||||||
_attr_native_pressure_unit = PRESSURE_HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ class SmhiWeather(WeatherEntity):
|
|||||||
if self._forecasts:
|
if self._forecasts:
|
||||||
wind_gust = SpeedConverter.convert(
|
wind_gust = SpeedConverter.convert(
|
||||||
self._forecasts[0].wind_gust,
|
self._forecasts[0].wind_gust,
|
||||||
SPEED_METERS_PER_SECOND,
|
UnitOfSpeed.METERS_PER_SECOND,
|
||||||
self._wind_speed_unit,
|
self._wind_speed_unit,
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
|
@ -9,10 +9,10 @@ from homeassistant.const import (
|
|||||||
CONF_LATITUDE,
|
CONF_LATITUDE,
|
||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
LENGTH_MILLIMETERS,
|
UnitOfPrecipitationDepth,
|
||||||
PRESSURE_HPA,
|
UnitOfPressure,
|
||||||
SPEED_METERS_PER_SECOND,
|
UnitOfSpeed,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
@ -83,10 +83,10 @@ class ZamgWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
name=coordinator.name,
|
name=coordinator.name,
|
||||||
)
|
)
|
||||||
# set units of ZAMG API
|
# set units of ZAMG API
|
||||||
self._attr_native_temperature_unit = TEMP_CELSIUS
|
self._attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
self._attr_native_pressure_unit = PRESSURE_HPA
|
self._attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
self._attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
self._attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
||||||
self._attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
self._attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def condition(self) -> str | None:
|
def condition(self) -> str | None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user