mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use new device class in aemet (#83315)
This commit is contained in:
parent
7b98656bcd
commit
6053b6f94a
@ -1,11 +1,6 @@
|
|||||||
"""Constant values for the AEMET OpenData component."""
|
"""Constant values for the AEMET OpenData component."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
|
||||||
SensorDeviceClass,
|
|
||||||
SensorEntityDescription,
|
|
||||||
SensorStateClass,
|
|
||||||
)
|
|
||||||
from homeassistant.components.weather import (
|
from homeassistant.components.weather import (
|
||||||
ATTR_CONDITION_CLEAR_NIGHT,
|
ATTR_CONDITION_CLEAR_NIGHT,
|
||||||
ATTR_CONDITION_CLOUDY,
|
ATTR_CONDITION_CLOUDY,
|
||||||
@ -18,15 +13,7 @@ from homeassistant.components.weather import (
|
|||||||
ATTR_CONDITION_SNOWY,
|
ATTR_CONDITION_SNOWY,
|
||||||
ATTR_CONDITION_SUNNY,
|
ATTR_CONDITION_SUNNY,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import Platform
|
||||||
DEGREE,
|
|
||||||
PERCENTAGE,
|
|
||||||
PRESSURE_HPA,
|
|
||||||
SPEED_KILOMETERS_PER_HOUR,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
Platform,
|
|
||||||
UnitOfVolumetricFlux,
|
|
||||||
)
|
|
||||||
|
|
||||||
ATTRIBUTION = "Powered by AEMET OpenData"
|
ATTRIBUTION = "Powered by AEMET OpenData"
|
||||||
CONF_STATION_UPDATES = "station_updates"
|
CONF_STATION_UPDATES = "station_updates"
|
||||||
@ -200,157 +187,6 @@ FORECAST_MODE_ATTR_API = {
|
|||||||
FORECAST_MODE_HOURLY: ATTR_API_FORECAST_HOURLY,
|
FORECAST_MODE_HOURLY: ATTR_API_FORECAST_HOURLY,
|
||||||
}
|
}
|
||||||
|
|
||||||
FORECAST_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_FORECAST_CONDITION,
|
|
||||||
name="Condition",
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_FORECAST_PRECIPITATION,
|
|
||||||
name="Precipitation",
|
|
||||||
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
|
||||||
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_FORECAST_PRECIPITATION_PROBABILITY,
|
|
||||||
name="Precipitation probability",
|
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_FORECAST_TEMP,
|
|
||||||
name="Temperature",
|
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_FORECAST_TEMP_LOW,
|
|
||||||
name="Temperature Low",
|
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_FORECAST_TIME,
|
|
||||||
name="Time",
|
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_FORECAST_WIND_BEARING,
|
|
||||||
name="Wind bearing",
|
|
||||||
native_unit_of_measurement=DEGREE,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_FORECAST_WIND_SPEED,
|
|
||||||
name="Wind speed",
|
|
||||||
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
WEATHER_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_CONDITION,
|
|
||||||
name="Condition",
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_HUMIDITY,
|
|
||||||
name="Humidity",
|
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_PRESSURE,
|
|
||||||
name="Pressure",
|
|
||||||
native_unit_of_measurement=PRESSURE_HPA,
|
|
||||||
device_class=SensorDeviceClass.PRESSURE,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_RAIN,
|
|
||||||
name="Rain",
|
|
||||||
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
|
||||||
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_RAIN_PROB,
|
|
||||||
name="Rain probability",
|
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_SNOW,
|
|
||||||
name="Snow",
|
|
||||||
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
|
||||||
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_SNOW_PROB,
|
|
||||||
name="Snow probability",
|
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_STATION_ID,
|
|
||||||
name="Station ID",
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_STATION_NAME,
|
|
||||||
name="Station name",
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_STATION_TIMESTAMP,
|
|
||||||
name="Station timestamp",
|
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_STORM_PROB,
|
|
||||||
name="Storm probability",
|
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_TEMPERATURE,
|
|
||||||
name="Temperature",
|
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_TEMPERATURE_FEELING,
|
|
||||||
name="Temperature feeling",
|
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_TOWN_ID,
|
|
||||||
name="Town ID",
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_TOWN_NAME,
|
|
||||||
name="Town name",
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_TOWN_TIMESTAMP,
|
|
||||||
name="Town timestamp",
|
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_WIND_BEARING,
|
|
||||||
name="Wind bearing",
|
|
||||||
native_unit_of_measurement=DEGREE,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_WIND_MAX_SPEED,
|
|
||||||
name="Wind max speed",
|
|
||||||
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key=ATTR_API_WIND_SPEED,
|
|
||||||
name="Wind speed",
|
|
||||||
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
WIND_BEARING_MAP = {
|
WIND_BEARING_MAP = {
|
||||||
"C": None,
|
"C": None,
|
||||||
|
@ -1,15 +1,54 @@
|
|||||||
"""Support for the AEMET OpenData service."""
|
"""Support for the AEMET OpenData service."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
from homeassistant.components.sensor import (
|
||||||
|
SensorDeviceClass,
|
||||||
|
SensorEntity,
|
||||||
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import (
|
||||||
|
DEGREE,
|
||||||
|
PERCENTAGE,
|
||||||
|
UnitOfPressure,
|
||||||
|
UnitOfSpeed,
|
||||||
|
UnitOfTemperature,
|
||||||
|
UnitOfVolumetricFlux,
|
||||||
|
)
|
||||||
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
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
ATTR_API_CONDITION,
|
||||||
|
ATTR_API_FORECAST_CONDITION,
|
||||||
|
ATTR_API_FORECAST_PRECIPITATION,
|
||||||
|
ATTR_API_FORECAST_PRECIPITATION_PROBABILITY,
|
||||||
|
ATTR_API_FORECAST_TEMP,
|
||||||
|
ATTR_API_FORECAST_TEMP_LOW,
|
||||||
ATTR_API_FORECAST_TIME,
|
ATTR_API_FORECAST_TIME,
|
||||||
|
ATTR_API_FORECAST_WIND_BEARING,
|
||||||
|
ATTR_API_FORECAST_WIND_SPEED,
|
||||||
|
ATTR_API_HUMIDITY,
|
||||||
|
ATTR_API_PRESSURE,
|
||||||
|
ATTR_API_RAIN,
|
||||||
|
ATTR_API_RAIN_PROB,
|
||||||
|
ATTR_API_SNOW,
|
||||||
|
ATTR_API_SNOW_PROB,
|
||||||
|
ATTR_API_STATION_ID,
|
||||||
|
ATTR_API_STATION_NAME,
|
||||||
|
ATTR_API_STATION_TIMESTAMP,
|
||||||
|
ATTR_API_STORM_PROB,
|
||||||
|
ATTR_API_TEMPERATURE,
|
||||||
|
ATTR_API_TEMPERATURE_FEELING,
|
||||||
|
ATTR_API_TOWN_ID,
|
||||||
|
ATTR_API_TOWN_NAME,
|
||||||
|
ATTR_API_TOWN_TIMESTAMP,
|
||||||
|
ATTR_API_WIND_BEARING,
|
||||||
|
ATTR_API_WIND_MAX_SPEED,
|
||||||
|
ATTR_API_WIND_SPEED,
|
||||||
ATTRIBUTION,
|
ATTRIBUTION,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
ENTRY_NAME,
|
ENTRY_NAME,
|
||||||
@ -18,12 +57,165 @@ from .const import (
|
|||||||
FORECAST_MODE_DAILY,
|
FORECAST_MODE_DAILY,
|
||||||
FORECAST_MODES,
|
FORECAST_MODES,
|
||||||
FORECAST_MONITORED_CONDITIONS,
|
FORECAST_MONITORED_CONDITIONS,
|
||||||
FORECAST_SENSOR_TYPES,
|
|
||||||
MONITORED_CONDITIONS,
|
MONITORED_CONDITIONS,
|
||||||
WEATHER_SENSOR_TYPES,
|
|
||||||
)
|
)
|
||||||
from .weather_update_coordinator import WeatherUpdateCoordinator
|
from .weather_update_coordinator import WeatherUpdateCoordinator
|
||||||
|
|
||||||
|
FORECAST_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_FORECAST_CONDITION,
|
||||||
|
name="Condition",
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_FORECAST_PRECIPITATION,
|
||||||
|
name="Precipitation",
|
||||||
|
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||||
|
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_FORECAST_PRECIPITATION_PROBABILITY,
|
||||||
|
name="Precipitation probability",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_FORECAST_TEMP,
|
||||||
|
name="Temperature",
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_FORECAST_TEMP_LOW,
|
||||||
|
name="Temperature Low",
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_FORECAST_TIME,
|
||||||
|
name="Time",
|
||||||
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_FORECAST_WIND_BEARING,
|
||||||
|
name="Wind bearing",
|
||||||
|
native_unit_of_measurement=DEGREE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_FORECAST_WIND_SPEED,
|
||||||
|
name="Wind speed",
|
||||||
|
native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||||
|
device_class=SensorDeviceClass.WIND_SPEED,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
WEATHER_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_CONDITION,
|
||||||
|
name="Condition",
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_HUMIDITY,
|
||||||
|
name="Humidity",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_PRESSURE,
|
||||||
|
name="Pressure",
|
||||||
|
native_unit_of_measurement=UnitOfPressure.HPA,
|
||||||
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_RAIN,
|
||||||
|
name="Rain",
|
||||||
|
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||||
|
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_RAIN_PROB,
|
||||||
|
name="Rain probability",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_SNOW,
|
||||||
|
name="Snow",
|
||||||
|
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||||
|
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_SNOW_PROB,
|
||||||
|
name="Snow probability",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_STATION_ID,
|
||||||
|
name="Station ID",
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_STATION_NAME,
|
||||||
|
name="Station name",
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_STATION_TIMESTAMP,
|
||||||
|
name="Station timestamp",
|
||||||
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_STORM_PROB,
|
||||||
|
name="Storm probability",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_TEMPERATURE,
|
||||||
|
name="Temperature",
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_TEMPERATURE_FEELING,
|
||||||
|
name="Temperature feeling",
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_TOWN_ID,
|
||||||
|
name="Town ID",
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_TOWN_NAME,
|
||||||
|
name="Town name",
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_TOWN_TIMESTAMP,
|
||||||
|
name="Town timestamp",
|
||||||
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_WIND_BEARING,
|
||||||
|
name="Wind bearing",
|
||||||
|
native_unit_of_measurement=DEGREE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_WIND_MAX_SPEED,
|
||||||
|
name="Wind max speed",
|
||||||
|
native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||||
|
device_class=SensorDeviceClass.WIND_SPEED,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key=ATTR_API_WIND_SPEED,
|
||||||
|
name="Wind speed",
|
||||||
|
native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
device_class=SensorDeviceClass.WIND_SPEED,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user