mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-13 10:54:33 +02:00
host device_tracker calculate time since last successful availability check
This commit is contained in:
parent
e4e128ab4b
commit
65074df370
2 changed files with 12 additions and 1 deletions
|
@ -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:
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue