mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Clean up AsusWRT (#48012)
This commit is contained in:
parent
9e9ba53f0e
commit
19ab7306ec
@ -56,66 +56,51 @@ class AsusWrtDevice(ScannerEntity):
|
|||||||
def __init__(self, router: AsusWrtRouter, device) -> None:
|
def __init__(self, router: AsusWrtRouter, device) -> None:
|
||||||
"""Initialize a AsusWrt device."""
|
"""Initialize a AsusWrt device."""
|
||||||
self._router = router
|
self._router = router
|
||||||
self._mac = device.mac
|
self._device = device
|
||||||
self._name = device.name or DEFAULT_DEVICE_NAME
|
|
||||||
self._active = False
|
|
||||||
self._icon = None
|
|
||||||
self._attrs = {}
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def async_update_state(self) -> None:
|
|
||||||
"""Update the AsusWrt device."""
|
|
||||||
device = self._router.devices[self._mac]
|
|
||||||
self._active = device.is_connected
|
|
||||||
|
|
||||||
self._attrs = {
|
|
||||||
"mac": device.mac,
|
|
||||||
"ip_address": device.ip_address,
|
|
||||||
}
|
|
||||||
if device.last_activity:
|
|
||||||
self._attrs["last_time_reachable"] = device.last_activity.isoformat(
|
|
||||||
timespec="seconds"
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
"""Return a unique ID."""
|
"""Return a unique ID."""
|
||||||
return self._mac
|
return self._device.mac
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name."""
|
"""Return the name."""
|
||||||
return self._name
|
return self._device.name or DEFAULT_DEVICE_NAME
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self):
|
def is_connected(self):
|
||||||
"""Return true if the device is connected to the network."""
|
"""Return true if the device is connected to the network."""
|
||||||
return self._active
|
return self._device.is_connected
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_type(self) -> str:
|
def source_type(self) -> str:
|
||||||
"""Return the source type."""
|
"""Return the source type."""
|
||||||
return SOURCE_TYPE_ROUTER
|
return SOURCE_TYPE_ROUTER
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str:
|
|
||||||
"""Return the icon."""
|
|
||||||
return self._icon
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, any]:
|
def extra_state_attributes(self) -> dict[str, any]:
|
||||||
"""Return the attributes."""
|
"""Return the attributes."""
|
||||||
return self._attrs
|
attrs = {
|
||||||
|
"mac": self._device.mac,
|
||||||
|
"ip_address": self._device.ip_address,
|
||||||
|
}
|
||||||
|
if self._device.last_activity:
|
||||||
|
attrs["last_time_reachable"] = self._device.last_activity.isoformat(
|
||||||
|
timespec="seconds"
|
||||||
|
)
|
||||||
|
return attrs
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> dict[str, any]:
|
def device_info(self) -> dict[str, any]:
|
||||||
"""Return the device information."""
|
"""Return the device information."""
|
||||||
return {
|
data = {
|
||||||
"connections": {(CONNECTION_NETWORK_MAC, self._mac)},
|
"connections": {(CONNECTION_NETWORK_MAC, self._device.mac)},
|
||||||
"identifiers": {(DOMAIN, self.unique_id)},
|
|
||||||
"name": self.name,
|
|
||||||
"manufacturer": "AsusWRT Tracked device",
|
|
||||||
}
|
}
|
||||||
|
if self._device.name:
|
||||||
|
data["default_name"] = self._device.name
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self) -> bool:
|
def should_poll(self) -> bool:
|
||||||
@ -125,12 +110,11 @@ class AsusWrtDevice(ScannerEntity):
|
|||||||
@callback
|
@callback
|
||||||
def async_on_demand_update(self):
|
def async_on_demand_update(self):
|
||||||
"""Update state."""
|
"""Update state."""
|
||||||
self.async_update_state()
|
self._device = self._router.devices[self._device.mac]
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Register state update callback."""
|
"""Register state update callback."""
|
||||||
self.async_update_state()
|
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
self.hass,
|
self.hass,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user