host device_tracker calculate time since last successful availability check

This commit is contained in:
tomaae 2020-04-08 09:48:16 +02:00
parent e4e128ab4b
commit 65074df370
2 changed files with 12 additions and 1 deletions

View file

@ -11,6 +11,7 @@ from homeassistant.const import (
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.util.dt import get_age
from .const import ( from .const import (
DOMAIN, DOMAIN,
@ -301,6 +302,12 @@ class MikrotikControllerHostDeviceTracker(ScannerEntity):
for variable in DEVICE_ATTRIBUTES_HOST: for variable in DEVICE_ATTRIBUTES_HOST:
if variable in self._data: 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] attributes[format_attribute(variable)] = self._data[variable]
return attributes return attributes

View file

@ -775,3 +775,7 @@ class MikrotikControllerData:
# Update last seen # Update last seen
if self.data["host"][uid]["available"]: if self.data["host"][uid]["available"]:
self.data["host"][uid]["last-seen"] = utcnow() self.data["host"][uid]["last-seen"] = utcnow()
# TEMP DEBUG
for uid, vals in self.data["host"].items():
_LOGGER.warning("HOST %s: %s", uid, vals)