From ccb1b1fae73368ab7af5efa3615aafca4cb1537a Mon Sep 17 00:00:00 2001 From: Tomaae <23486452+tomaae@users.noreply.github.com> Date: Thu, 26 May 2022 10:06:06 +0200 Subject: [PATCH] Added now and unknown states to last seen tracker attribute #203 --- custom_components/mikrotik_router/device_tracker.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/custom_components/mikrotik_router/device_tracker.py b/custom_components/mikrotik_router/device_tracker.py index 4e3fe0f..41ea9cf 100644 --- a/custom_components/mikrotik_router/device_tracker.py +++ b/custom_components/mikrotik_router/device_tracker.py @@ -145,3 +145,15 @@ class MikrotikHostDeviceTracker(MikrotikDeviceTracker): def state(self) -> str: """Return the state of the device.""" return self._ctrl.option_zone if self.is_connected else STATE_NOT_HOME + + @property + def extra_state_attributes(self) -> Mapping[str, Any]: + """Return the state attributes.""" + attributes = super().extra_state_attributes + if self.is_connected: + attributes[format_attribute("last-seen")] = "Now" + + if not attributes[format_attribute("last-seen")]: + attributes[format_attribute("last-seen")] = "Unknown" + + return attributes