UniFi - Improve client tracker attributes based on connection (#32817)
* Improve client tracker attributes by setting them to None when client is disconnected * Fix martins commentpull/33726/head
parent
738ef38ddc
commit
529656cf64
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue