From 519bc5ef9e77f608defb8993b1da2543fe6ba234 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 11 Sep 2025 18:22:16 -0500 Subject: [PATCH] Fix dashboard dns lookup delay --- esphome/dashboard/dns.py | 4 +++- esphome/dashboard/status/mdns.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/esphome/dashboard/dns.py b/esphome/dashboard/dns.py index 4f1ef71dd0..b94d816c74 100644 --- a/esphome/dashboard/dns.py +++ b/esphome/dashboard/dns.py @@ -33,7 +33,9 @@ class DNSCache: Returns None if not in cache, list of addresses if found. """ - if expire_time_addresses := self._cache.get(hostname): + # Normalize hostname for consistent lookups + normalized = hostname.rstrip(".").lower() + if expire_time_addresses := self._cache.get(normalized): expire_time, addresses = expire_time_addresses if expire_time > now_monotonic and not isinstance(addresses, Exception): return addresses diff --git a/esphome/dashboard/status/mdns.py b/esphome/dashboard/status/mdns.py index 0977a89c3a..a5ce69f30c 100644 --- a/esphome/dashboard/status/mdns.py +++ b/esphome/dashboard/status/mdns.py @@ -4,6 +4,8 @@ import asyncio import logging import typing +from zeroconf import AddressResolver, IPVersion + from esphome.zeroconf import ( ESPHOME_SERVICE_TYPE, AsyncEsphomeZeroconf, @@ -58,10 +60,12 @@ class MDNSStatus: if not self.aiozc: return None - from zeroconf import AddressResolver, IPVersion + # Normalize hostname: remove trailing dots and get the base name + normalized = host_name.rstrip(".").lower() + base_name = normalized.partition(".")[0] # Try to load from zeroconf cache without triggering resolution - info = AddressResolver(f"{host_name.partition('.')[0]}.local.") + info = AddressResolver(f"{base_name}.local.") if info.load_from_cache(self.aiozc.zeroconf): return info.parsed_scoped_addresses(IPVersion.All) return None