From e004cd029aa4c5dc23f68d82c05e54b94fff3f69 Mon Sep 17 00:00:00 2001
From: Robert Svensson <Kane610@users.noreply.github.com>
Date: Tue, 21 Apr 2020 21:12:44 +0200
Subject: [PATCH] UniFi - Improve handling of client tracker is connected to
 better respect configured delay (#34510)

---
 homeassistant/components/unifi/device_tracker.py | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/homeassistant/components/unifi/device_tracker.py b/homeassistant/components/unifi/device_tracker.py
index df93916e45b..d09259f0299 100644
--- a/homeassistant/components/unifi/device_tracker.py
+++ b/homeassistant/components/unifi/device_tracker.py
@@ -148,13 +148,6 @@ class UniFiClientTracker(UniFiClient, ScannerEntity):
             self.cancel_scheduled_update = None
             self.async_write_ha_state()
 
-        if (
-            not self.is_wired
-            and self.controller.option_ssid_filter
-            and self.client.essid not in self.controller.option_ssid_filter
-        ):
-            return False
-
         if (self.is_wired and self.wired_connection) or (
             not self.is_wired and self.wireless_connection
         ):
@@ -174,6 +167,15 @@ class UniFiClientTracker(UniFiClient, ScannerEntity):
                     dt_util.utcnow() + self.controller.option_detection_time,
                 )
 
+        if (
+            not self.is_wired
+            and self.client.essid
+            and self.controller.option_ssid_filter
+            and self.client.essid not in self.controller.option_ssid_filter
+            and not self.cancel_scheduled_update
+        ):
+            return False
+
         if self.is_disconnected is not None:
             return not self.is_disconnected
 
-- 
GitLab