1 """Support for ASUSWRT routers."""
3 from __future__
import annotations
10 from .
import AsusWrtConfigEntry
11 from .router
import AsusWrtDevInfo, AsusWrtRouter
13 ATTR_LAST_TIME_REACHABLE =
"last_time_reachable"
15 DEFAULT_DEVICE_NAME =
"Unknown device"
20 entry: AsusWrtConfigEntry,
21 async_add_entities: AddEntitiesCallback,
23 """Set up device tracker for AsusWrt component."""
24 router = entry.runtime_data
28 def update_router() -> None:
29 """Update the values of the router."""
32 router.async_on_close(
41 router: AsusWrtRouter, async_add_entities: AddEntitiesCallback, tracked: set[str]
43 """Add new tracker entities from the router."""
46 for mac, device
in router.devices.items():
57 """Representation of a AsusWrt device."""
59 _unrecorded_attributes = frozenset({ATTR_LAST_TIME_REACHABLE})
61 _attr_should_poll =
False
63 def __init__(self, router: AsusWrtRouter, device: AsusWrtDevInfo) ->
None:
64 """Initialize a AsusWrt device."""
67 self.
_attr_name_attr_name = device.name
or DEFAULT_DEVICE_NAME
71 """Return true if the device is connected to the network."""
72 return self.
_device_device.is_connected
76 """Return the hostname of device."""
81 """Return device icon."""
82 return "mdi:lan-connect" if self.
_device_device.is_connected
else "mdi:lan-disconnect"
86 """Return the primary ip address of the device."""
87 return self.
_device_device.ip_address
91 """Return the mac address of the device."""
99 if self.
_device_device.last_activity:
101 self.
_device_device.last_activity.isoformat(timespec=
"seconds")
103 self.async_write_ha_state()
106 """Register state update callback."""
107 self.async_on_remove(
110 self.
_router_router.signal_device_update,
None __init__(self, AsusWrtRouter router, AsusWrtDevInfo device)
None async_on_demand_update(self)
str|None ip_address(self)
_attr_extra_state_attributes
None async_added_to_hass(self)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None async_setup_entry(HomeAssistant hass, AsusWrtConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)