1 """Platform for device tracker integration."""
3 from __future__
import annotations
5 from devolo_plc_api.device
import Device
6 from devolo_plc_api.device_api
import ConnectedStationInfo
9 DOMAIN
as DEVICE_TRACKER_DOMAIN,
18 from .
import DevoloHomeNetworkConfigEntry
19 from .const
import CONNECTED_WIFI_CLIENTS, DOMAIN, WIFI_APTYPE, WIFI_BANDS
20 from .coordinator
import DevoloDataUpdateCoordinator
27 entry: DevoloHomeNetworkConfigEntry,
28 async_add_entities: AddEntitiesCallback,
30 """Get all devices and sensors and setup them via config entry."""
31 device = entry.runtime_data.device
32 coordinators: dict[str, DevoloDataUpdateCoordinator[list[ConnectedStationInfo]]] = (
33 entry.runtime_data.coordinators
35 registry = er.async_get(hass)
39 def new_device_callback() -> None:
40 """Add new devices if needed."""
42 for station
in coordinators[CONNECTED_WIFI_CLIENTS].data:
43 if station.mac_address
in tracked:
48 coordinators[CONNECTED_WIFI_CLIENTS], device, station.mac_address
51 tracked.add(station.mac_address)
56 """Restore clients that are not a part of active clients list."""
58 for entity
in er.async_entries_for_config_entry(registry, entry.entry_id):
60 entity.platform == DOMAIN
61 and entity.domain == DEVICE_TRACKER_DOMAIN
63 mac_address := entity.unique_id.replace(
64 f
"{device.serial_number}_",
""
71 coordinators[CONNECTED_WIFI_CLIENTS], device, mac_address
74 tracked.add(mac_address)
79 entry.async_on_unload(
86 CoordinatorEntity[DevoloDataUpdateCoordinator[list[ConnectedStationInfo]]],
89 """Representation of a devolo device tracker."""
93 coordinator: DevoloDataUpdateCoordinator[list[ConnectedStationInfo]],
97 """Initialize entity."""
100 self._attr_mac_address = mac
104 """Return the attributes."""
105 attrs: dict[str, str] = {}
106 if not self.coordinator.data:
112 for station
in self.coordinator.data
113 if station.mac_address == self.mac_address
118 attrs[
"wifi"] = WIFI_APTYPE.get(station.vap_type, STATE_UNKNOWN)
120 f
"{WIFI_BANDS.get(station.band)} {UnitOfFrequency.GIGAHERTZ}"
121 if WIFI_BANDS.get(station.band)
128 """Return device icon."""
129 if self.is_connected:
130 return "mdi:lan-connect"
131 return "mdi:lan-disconnect"
135 """Return true if the device is connected to the network."""
138 for station
in self.coordinator.data
139 if station.mac_address == self.mac_address
144 """Return unique ID of the entity."""
145 return f
"{self._device.serial_number}_{self.mac_address}"
dict[str, str] extra_state_attributes(self)
None __init__(self, DevoloDataUpdateCoordinator[list[ConnectedStationInfo]] coordinator, Device device, str mac)
None async_setup_entry(HomeAssistant hass, DevoloHomeNetworkConfigEntry entry, AddEntitiesCallback async_add_entities)
None async_add_listener(HomeAssistant hass, Callable[[], None] listener)
None restore_entities(er.EntityRegistry registry, RuckusDataUpdateCoordinator coordinator, ConfigEntry entry, AddEntitiesCallback async_add_entities, set[str] tracked)