Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base entity class for the Ambient Weather Network integration."""
2 
3 from __future__ import annotations
4 
5 from abc import abstractmethod
6 
7 from homeassistant.core import callback
8 from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
9 from homeassistant.helpers.entity import EntityDescription
10 from homeassistant.helpers.update_coordinator import CoordinatorEntity
11 
12 from .const import DOMAIN
13 from .coordinator import AmbientNetworkDataUpdateCoordinator
14 
15 
16 class AmbientNetworkEntity(CoordinatorEntity[AmbientNetworkDataUpdateCoordinator]):
17  """Entity class for Ambient network devices."""
18 
19  _attr_attribution = "Data provided by ambientnetwork.net"
20  _attr_has_entity_name = True
21 
22  def __init__(
23  self,
24  coordinator: AmbientNetworkDataUpdateCoordinator,
25  description: EntityDescription,
26  mac_address: str,
27  ) -> None:
28  """Initialize the Ambient network entity."""
29 
30  super().__init__(coordinator)
31  self.entity_descriptionentity_description = description
32  self._attr_unique_id_attr_unique_id = f"{mac_address}_{description.key}"
33  self._attr_device_info_attr_device_info = DeviceInfo(
34  entry_type=DeviceEntryType.SERVICE,
35  name=coordinator.station_name,
36  identifiers={(DOMAIN, mac_address)},
37  manufacturer="Ambient Weather",
38  )
39  self._update_attrs_update_attrs()
40 
41  @abstractmethod
42  def _update_attrs(self) -> None:
43  """Update state attributes."""
44 
45  @callback
46  def _handle_coordinator_update(self) -> None:
47  """Get the latest data and updates the state."""
48 
49  self._update_attrs_update_attrs()
None __init__(self, AmbientNetworkDataUpdateCoordinator coordinator, EntityDescription description, str mac_address)
Definition: entity.py:27