mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Migrate AEMET to has entity name (#120284)
This commit is contained in:
parent
fa9bced6b0
commit
4785810dc3
@ -10,13 +10,16 @@ from homeassistant.components.weather import Forecast
|
|||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import ATTRIBUTION, DOMAIN
|
||||||
from .coordinator import WeatherUpdateCoordinator
|
from .coordinator import WeatherUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
class AemetEntity(CoordinatorEntity[WeatherUpdateCoordinator]):
|
class AemetEntity(CoordinatorEntity[WeatherUpdateCoordinator]):
|
||||||
"""Define an AEMET entity."""
|
"""Define an AEMET entity."""
|
||||||
|
|
||||||
|
_attr_attribution = ATTRIBUTION
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: WeatherUpdateCoordinator,
|
coordinator: WeatherUpdateCoordinator,
|
||||||
|
@ -43,7 +43,6 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
DEGREE,
|
DEGREE,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
@ -86,7 +85,6 @@ from .const import (
|
|||||||
ATTR_API_WIND_BEARING,
|
ATTR_API_WIND_BEARING,
|
||||||
ATTR_API_WIND_MAX_SPEED,
|
ATTR_API_WIND_MAX_SPEED,
|
||||||
ATTR_API_WIND_SPEED,
|
ATTR_API_WIND_SPEED,
|
||||||
ATTRIBUTION,
|
|
||||||
CONDITIONS_MAP,
|
CONDITIONS_MAP,
|
||||||
)
|
)
|
||||||
from .coordinator import WeatherUpdateCoordinator
|
from .coordinator import WeatherUpdateCoordinator
|
||||||
@ -366,12 +364,15 @@ async def async_setup_entry(
|
|||||||
name = domain_data.name
|
name = domain_data.name
|
||||||
coordinator = domain_data.coordinator
|
coordinator = domain_data.coordinator
|
||||||
|
|
||||||
|
unique_id = config_entry.unique_id
|
||||||
|
assert unique_id is not None
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
AemetSensor(
|
AemetSensor(
|
||||||
name,
|
name,
|
||||||
coordinator,
|
coordinator,
|
||||||
description,
|
description,
|
||||||
config_entry,
|
unique_id,
|
||||||
)
|
)
|
||||||
for description in FORECAST_SENSORS + WEATHER_SENSORS
|
for description in FORECAST_SENSORS + WEATHER_SENSORS
|
||||||
if dict_nested_value(coordinator.data["lib"], description.keys) is not None
|
if dict_nested_value(coordinator.data["lib"], description.keys) is not None
|
||||||
@ -381,7 +382,6 @@ async def async_setup_entry(
|
|||||||
class AemetSensor(AemetEntity, SensorEntity):
|
class AemetSensor(AemetEntity, SensorEntity):
|
||||||
"""Implementation of an AEMET OpenData sensor."""
|
"""Implementation of an AEMET OpenData sensor."""
|
||||||
|
|
||||||
_attr_attribution = ATTRIBUTION
|
|
||||||
entity_description: AemetSensorEntityDescription
|
entity_description: AemetSensorEntityDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -389,14 +389,11 @@ class AemetSensor(AemetEntity, SensorEntity):
|
|||||||
name: str,
|
name: str,
|
||||||
coordinator: WeatherUpdateCoordinator,
|
coordinator: WeatherUpdateCoordinator,
|
||||||
description: AemetSensorEntityDescription,
|
description: AemetSensorEntityDescription,
|
||||||
config_entry: ConfigEntry,
|
unique_id: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
assert config_entry.unique_id is not None
|
|
||||||
unique_id = config_entry.unique_id
|
|
||||||
super().__init__(coordinator, name, unique_id)
|
super().__init__(coordinator, name, unique_id)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_name = f"{name} {description.name}"
|
|
||||||
self._attr_unique_id = f"{unique_id}-{description.key}"
|
self._attr_unique_id = f"{unique_id}-{description.key}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -28,7 +28,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AemetConfigEntry
|
from . import AemetConfigEntry
|
||||||
from .const import ATTRIBUTION, CONDITIONS_MAP
|
from .const import CONDITIONS_MAP
|
||||||
from .coordinator import WeatherUpdateCoordinator
|
from .coordinator import WeatherUpdateCoordinator
|
||||||
from .entity import AemetEntity
|
from .entity import AemetEntity
|
||||||
|
|
||||||
@ -43,10 +43,10 @@ async def async_setup_entry(
|
|||||||
name = domain_data.name
|
name = domain_data.name
|
||||||
weather_coordinator = domain_data.coordinator
|
weather_coordinator = domain_data.coordinator
|
||||||
|
|
||||||
async_add_entities(
|
unique_id = config_entry.unique_id
|
||||||
[AemetWeather(name, config_entry.unique_id, weather_coordinator)],
|
assert unique_id is not None
|
||||||
False,
|
|
||||||
)
|
async_add_entities([AemetWeather(name, unique_id, weather_coordinator)])
|
||||||
|
|
||||||
|
|
||||||
class AemetWeather(
|
class AemetWeather(
|
||||||
@ -55,7 +55,6 @@ class AemetWeather(
|
|||||||
):
|
):
|
||||||
"""Implementation of an AEMET OpenData weather."""
|
"""Implementation of an AEMET OpenData weather."""
|
||||||
|
|
||||||
_attr_attribution = ATTRIBUTION
|
|
||||||
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||||
_attr_native_pressure_unit = UnitOfPressure.HPA
|
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||||
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
@ -63,16 +62,16 @@ class AemetWeather(
|
|||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
WeatherEntityFeature.FORECAST_DAILY | WeatherEntityFeature.FORECAST_HOURLY
|
WeatherEntityFeature.FORECAST_DAILY | WeatherEntityFeature.FORECAST_HOURLY
|
||||||
)
|
)
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name,
|
name: str,
|
||||||
unique_id,
|
unique_id: str,
|
||||||
coordinator: WeatherUpdateCoordinator,
|
coordinator: WeatherUpdateCoordinator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator, name, unique_id)
|
super().__init__(coordinator, name, unique_id)
|
||||||
self._attr_name = name
|
|
||||||
self._attr_unique_id = unique_id
|
self._attr_unique_id = unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user