Added now and unknown states to last seen tracker attribute #203

This commit is contained in:
Tomaae 2022-05-26 10:06:06 +02:00
parent 263b38b301
commit ccb1b1fae7
No known key found for this signature in database
GPG key ID: 8360BBD8A381D1C0

View file

@ -145,3 +145,15 @@ class MikrotikHostDeviceTracker(MikrotikDeviceTracker):
def state(self) -> str: def state(self) -> str:
"""Return the state of the device.""" """Return the state of the device."""
return self._ctrl.option_zone if self.is_connected else STATE_NOT_HOME 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