From 0d7711f7875986d1234e0476f43f25736b1c19a5 Mon Sep 17 00:00:00 2001
From: Robert Svensson <Kane610@users.noreply.github.com>
Date: Tue, 11 Apr 2023 11:56:55 +0200
Subject: [PATCH] Fix UniFi client tracker host_name missing (#91188)

---
 homeassistant/components/unifi/device_tracker.py | 3 +--
 tests/components/unifi/test_device_tracker.py    | 3 +++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/homeassistant/components/unifi/device_tracker.py b/homeassistant/components/unifi/device_tracker.py
index 149f865e776..296857e1cfa 100644
--- a/homeassistant/components/unifi/device_tracker.py
+++ b/homeassistant/components/unifi/device_tracker.py
@@ -54,7 +54,6 @@ CLIENT_CONNECTED_ATTRIBUTES = [
 ]
 
 CLIENT_STATIC_ATTRIBUTES = [
-    "hostname",
     "mac",
     "name",
     "oui",
@@ -175,7 +174,7 @@ ENTITY_DESCRIPTIONS: tuple[UnifiTrackerEntityDescription, ...] = (
         supported_fn=lambda controller, obj_id: True,
         unique_id_fn=lambda controller, obj_id: f"{obj_id}-{controller.site}",
         ip_address_fn=lambda api, obj_id: api.clients[obj_id].ip,
-        hostname_fn=lambda api, obj_id: None,
+        hostname_fn=lambda api, obj_id: api.clients[obj_id].hostname,
     ),
     UnifiTrackerEntityDescription[Devices, Device](
         key="Device scanner",
diff --git a/tests/components/unifi/test_device_tracker.py b/tests/components/unifi/test_device_tracker.py
index 1e68b497111..16432ff514e 100644
--- a/tests/components/unifi/test_device_tracker.py
+++ b/tests/components/unifi/test_device_tracker.py
@@ -144,6 +144,9 @@ async def test_tracked_clients(
     assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 4
     assert hass.states.get("device_tracker.client_1").state == STATE_NOT_HOME
     assert hass.states.get("device_tracker.client_2").state == STATE_NOT_HOME
+    assert (
+        hass.states.get("device_tracker.client_5").attributes["host_name"] == "client_5"
+    )
 
     # Client on SSID not in SSID filter
     assert not hass.states.get("device_tracker.client_3")
-- 
GitLab