From d33779d3a05acbc97b7d94a347d3323303dbf828 Mon Sep 17 00:00:00 2001 From: Rami Mosleh Date: Sun, 10 Jul 2022 00:33:10 +0300 Subject: [PATCH] Cleanup mikrotik device extra_attributes (#74491) --- homeassistant/components/mikrotik/const.py | 1 - .../components/mikrotik/device_tracker.py | 21 +++---------------- homeassistant/components/mikrotik/hub.py | 5 ++--- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/mikrotik/const.py b/homeassistant/components/mikrotik/const.py index 2942e6981fa..bbe129c4a00 100644 --- a/homeassistant/components/mikrotik/const.py +++ b/homeassistant/components/mikrotik/const.py @@ -44,7 +44,6 @@ PLATFORMS: Final = [Platform.DEVICE_TRACKER] ATTR_DEVICE_TRACKER: Final = [ "comment", - "mac-address", "ssid", "interface", "signal-strength", diff --git a/homeassistant/components/mikrotik/device_tracker.py b/homeassistant/components/mikrotik/device_tracker.py index 4e002cdbcfe..158d95dd683 100644 --- a/homeassistant/components/mikrotik/device_tracker.py +++ b/homeassistant/components/mikrotik/device_tracker.py @@ -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 diff --git a/homeassistant/components/mikrotik/hub.py b/homeassistant/components/mikrotik/hub.py index 9219159ca74..66fe7226d9b 100644 --- a/homeassistant/components/mikrotik/hub.py +++ b/homeassistant/components/mikrotik/hub.py @@ -77,11 +77,10 @@ class Device: @property def attrs(self) -> dict[str, Any]: """Return device attributes.""" - attr_data = self._wireless_params if self._wireless_params else self._params + attr_data = self._wireless_params | self._params for attr in ATTR_DEVICE_TRACKER: if attr in attr_data: self._attrs[slugify(attr)] = attr_data[attr] - self._attrs["ip_address"] = self._params.get("active-address") return self._attrs def update( @@ -250,7 +249,7 @@ class MikrotikData: ) -> list[dict[str, Any]]: """Retrieve data from Mikrotik API.""" try: - _LOGGER.info("Running command %s", cmd) + _LOGGER.debug("Running command %s", cmd) if params: return list(self.api(cmd=cmd, **params)) return list(self.api(cmd=cmd))