Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Entity classes for the AEMET OpenData integration."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from aemet_opendata.helpers import dict_nested_value
8 
9 from homeassistant.components.weather import Forecast
10 from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
11 from homeassistant.helpers.update_coordinator import CoordinatorEntity
12 
13 from .const import ATTRIBUTION, DOMAIN
14 from .coordinator import WeatherUpdateCoordinator
15 
16 
17 class AemetEntity(CoordinatorEntity[WeatherUpdateCoordinator]):
18  """Define an AEMET entity."""
19 
20  _attr_attribution = ATTRIBUTION
21  _attr_has_entity_name = True
22 
23  def __init__(
24  self,
25  coordinator: WeatherUpdateCoordinator,
26  name: str,
27  unique_id: str,
28  ) -> None:
29  """Initialize the entity."""
30  super().__init__(coordinator)
31  self._attr_device_info_attr_device_info = DeviceInfo(
32  name=name,
33  entry_type=DeviceEntryType.SERVICE,
34  identifiers={(DOMAIN, unique_id)},
35  manufacturer="AEMET",
36  model="Forecast",
37  )
38 
39  def get_aemet_forecast(self, forecast_mode: str) -> list[Forecast]:
40  """Return AEMET entity forecast by mode."""
41  return self.coordinator.data["forecast"][forecast_mode]
42 
43  def get_aemet_value(self, keys: list[str]) -> Any:
44  """Return AEMET entity value by keys."""
45  return dict_nested_value(self.coordinator.data["lib"], keys)
list[Forecast] get_aemet_forecast(self, str forecast_mode)
Definition: entity.py:39
Any get_aemet_value(self, list[str] keys)
Definition: entity.py:43
None __init__(self, WeatherUpdateCoordinator coordinator, str name, str unique_id)
Definition: entity.py:28