From 529656cf64d0fd946480bf8eac507fbb183aafb2 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Mon, 6 Apr 2020 01:26:11 +0200 Subject: [PATCH] UniFi - Improve client tracker attributes based on connection (#32817) * Improve client tracker attributes by setting them to None when client is disconnected * Fix martins comment --- .../components/unifi/device_tracker.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/unifi/device_tracker.py b/homeassistant/components/unifi/device_tracker.py index 43494ec485f..c5aa74706a1 100644 --- a/homeassistant/components/unifi/device_tracker.py +++ b/homeassistant/components/unifi/device_tracker.py @@ -16,26 +16,28 @@ from .unifi_client import UniFiClient LOGGER = logging.getLogger(__name__) -DEVICE_ATTRIBUTES = [ +CLIENT_CONNECTED_ATTRIBUTES = [ "_is_guest_by_uap", "ap_mac", "authorized", "essid", - "hostname", "ip", "is_11r", "is_guest", - "mac", - "name", "noted", - "oui", "qos_policy_applied", "radio", "radio_proto", - "site_id", "vlan", ] +CLIENT_STATIC_ATTRIBUTES = [ + "hostname", + "mac", + "name", + "oui", +] + async def async_setup_entry(hass, config_entry, async_add_entities): """Set up device tracker for UniFi component.""" @@ -284,12 +286,14 @@ class UniFiClientTracker(UniFiClient, ScannerEntity): """Return the client state attributes.""" attributes = {} - for variable in DEVICE_ATTRIBUTES: - if variable in self.client.raw: - attributes[variable] = self.client.raw[variable] - attributes["is_wired"] = self.is_wired + for variable in CLIENT_STATIC_ATTRIBUTES + CLIENT_CONNECTED_ATTRIBUTES: + if variable in self.client.raw: + if self.is_disconnected and variable in CLIENT_CONNECTED_ATTRIBUTES: + continue + attributes[variable] = self.client.raw[variable] + return attributes