mirror of
https://github.com/esphome/esphome.git
synced 2025-10-08 12:53:45 +01:00
Fix dashboard dns lookup delay
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user