diff --git a/custom_components/mikrotik_router/device_tracker.py b/custom_components/mikrotik_router/device_tracker.py index a751b1c..0fc63bb 100644 --- a/custom_components/mikrotik_router/device_tracker.py +++ b/custom_components/mikrotik_router/device_tracker.py @@ -11,6 +11,7 @@ from homeassistant.const import ( from homeassistant.core import callback from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.util.dt import get_age from .const import ( DOMAIN, @@ -301,6 +302,12 @@ class MikrotikControllerHostDeviceTracker(ScannerEntity): for variable in DEVICE_ATTRIBUTES_HOST: if variable in self._data: - attributes[format_attribute(variable)] = self._data[variable] + if variable == "last-seen": + if self._data[variable]: + attributes[format_attribute(variable)] = get_age(self._data[variable]) + else: + attributes[format_attribute(variable)] = "unknown" + else: + attributes[format_attribute(variable)] = self._data[variable] return attributes diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 74bf3e2..c1101f6 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -775,3 +775,7 @@ class MikrotikControllerData: # Update last seen if self.data["host"][uid]["available"]: self.data["host"][uid]["last-seen"] = utcnow() + + # TEMP DEBUG + for uid, vals in self.data["host"].items(): + _LOGGER.warning("HOST %s: %s", uid, vals)