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
pull/33726/head
Robert Svensson 2020-04-06 01:26:11 +02:00 committed by GitHub
parent 738ef38ddc
commit 529656cf64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 10 deletions

View File

@ -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