Cleanup mikrotik device extra_attributes (#74491)

This commit is contained in:
Rami Mosleh 2022-07-10 00:33:10 +03:00 committed by GitHub
parent e529ef7b0e
commit d33779d3a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 22 deletions

View file

@ -18,10 +18,6 @@ import homeassistant.util.dt as dt_util
from .const import DOMAIN
from .hub import Device, MikrotikDataUpdateCoordinator
# These are normalized to ATTR_IP and ATTR_MAC to conform
# to device_tracker
FILTER_ATTRS = ("ip_address", "mac_address")
async def async_setup_entry(
hass: HomeAssistant,
@ -90,6 +86,8 @@ class MikrotikDataUpdateCoordinatorTracker(
"""Initialize the tracked device."""
super().__init__(coordinator)
self.device = device
self._attr_name = str(device.name)
self._attr_unique_id = device.mac
@property
def is_connected(self) -> bool:
@ -107,12 +105,6 @@ class MikrotikDataUpdateCoordinatorTracker(
"""Return the source type of the client."""
return SOURCE_TYPE_ROUTER
@property
def name(self) -> str:
"""Return the name of the client."""
# Stringify to ensure we return a string
return str(self.device.name)
@property
def hostname(self) -> str:
"""Return the hostname of the client."""
@ -128,14 +120,7 @@ class MikrotikDataUpdateCoordinatorTracker(
"""Return the mac address of the client."""
return self.device.ip_address
@property
def unique_id(self) -> str:
"""Return a unique identifier for this device."""
return self.device.mac
@property
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the device state attributes."""
if self.is_connected:
return {k: v for k, v in self.device.attrs.items() if k not in FILTER_ATTRS}
return None
return self.device.attrs if self.is_connected else None