mirror of
https://github.com/esphome/esphome.git
synced 2025-10-08 04:43:46 +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.
|
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
|
expire_time, addresses = expire_time_addresses
|
||||||
if expire_time > now_monotonic and not isinstance(addresses, Exception):
|
if expire_time > now_monotonic and not isinstance(addresses, Exception):
|
||||||
return addresses
|
return addresses
|
||||||
|
@@ -4,6 +4,8 @@ import asyncio
|
|||||||
import logging
|
import logging
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
from zeroconf import AddressResolver, IPVersion
|
||||||
|
|
||||||
from esphome.zeroconf import (
|
from esphome.zeroconf import (
|
||||||
ESPHOME_SERVICE_TYPE,
|
ESPHOME_SERVICE_TYPE,
|
||||||
AsyncEsphomeZeroconf,
|
AsyncEsphomeZeroconf,
|
||||||
@@ -58,10 +60,12 @@ class MDNSStatus:
|
|||||||
if not self.aiozc:
|
if not self.aiozc:
|
||||||
return None
|
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
|
# 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):
|
if info.load_from_cache(self.aiozc.zeroconf):
|
||||||
return info.parsed_scoped_addresses(IPVersion.All)
|
return info.parsed_scoped_addresses(IPVersion.All)
|
||||||
return None
|
return None
|
||||||
|
Reference in New Issue
Block a user