mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Add device info for Aemet (#120243)
* Update sensor.py * Update weather.py * Update sensor.py * ruff * add device info to entity * remove info from sensor * remove info from weather * ruff * amend entity * Update sensor.py * Update weather.py * ruff again * add DOMAIN * type unique_id * Update entity.py * Update entity.py * assert * update tests * change snapshot
This commit is contained in:
parent
fe3027f7de
commit
fdade67211
@ -7,14 +7,32 @@ from typing import Any
|
||||
from aemet_opendata.helpers import dict_nested_value
|
||||
|
||||
from homeassistant.components.weather import Forecast
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import WeatherUpdateCoordinator
|
||||
|
||||
|
||||
class AemetEntity(CoordinatorEntity[WeatherUpdateCoordinator]):
|
||||
"""Define an AEMET entity."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: WeatherUpdateCoordinator,
|
||||
name: str,
|
||||
unique_id: str,
|
||||
) -> None:
|
||||
"""Initialize the entity."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_device_info = DeviceInfo(
|
||||
name=name,
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
identifiers={(DOMAIN, unique_id)},
|
||||
manufacturer="AEMET",
|
||||
model="Forecast",
|
||||
)
|
||||
|
||||
def get_aemet_forecast(self, forecast_mode: str) -> list[Forecast]:
|
||||
"""Return AEMET entity forecast by mode."""
|
||||
return self.coordinator.data["forecast"][forecast_mode]
|
||||
|
@ -392,10 +392,12 @@ class AemetSensor(AemetEntity, SensorEntity):
|
||||
config_entry: ConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
assert config_entry.unique_id is not None
|
||||
unique_id = config_entry.unique_id
|
||||
super().__init__(coordinator, name, unique_id)
|
||||
self.entity_description = description
|
||||
self._attr_name = f"{name} {description.name}"
|
||||
self._attr_unique_id = f"{config_entry.unique_id}-{description.key}"
|
||||
self._attr_unique_id = f"{unique_id}-{description.key}"
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
|
@ -71,7 +71,7 @@ class AemetWeather(
|
||||
coordinator: WeatherUpdateCoordinator,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
super().__init__(coordinator, name, unique_id)
|
||||
self._attr_name = name
|
||||
self._attr_unique_id = unique_id
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': 'Mock Title',
|
||||
'unique_id': None,
|
||||
'unique_id': '**REDACTED**',
|
||||
'version': 1,
|
||||
}),
|
||||
'coord_data': dict({
|
||||
|
@ -68,6 +68,7 @@ async def async_init_integration(hass: HomeAssistant):
|
||||
CONF_NAME: "AEMET",
|
||||
},
|
||||
entry_id="7442b231f139e813fc1939281123f220",
|
||||
unique_id="40.30403754--3.72935236",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user