1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-22 05:02:23 +01:00
This commit is contained in:
J. Nick Koston
2025-09-11 18:57:35 -05:00
parent 23d82f8368
commit b9bf81fffc
2 changed files with 15 additions and 6 deletions

View File

@@ -1167,6 +1167,12 @@ def run_esphome(argv):
# Store cache in CORE for access throughout the application
CORE.address_cache = address_cache
if address_cache.has_cache():
_LOGGER.debug(
"Address cache initialized with %d mDNS and %d DNS entries",
len(address_cache.mdns_cache),
len(address_cache.dns_cache),
)
# Override log level if verbose is set
if args.verbose:

View File

@@ -2,7 +2,6 @@ from __future__ import annotations
import asyncio
import logging
import time
import typing
from zeroconf import AddressResolver, IPVersion
@@ -60,6 +59,7 @@ class MDNSStatus:
Returns None if not in cache or no zeroconf available.
"""
if not self.aiozc:
_LOGGER.debug("No zeroconf instance available for %s", host_name)
return None
# Normalize hostname and get the base name
@@ -67,11 +67,14 @@ class MDNSStatus:
base_name = normalized.partition(".")[0]
# Try to load from zeroconf cache without triggering resolution
info = AddressResolver(f"{base_name}.local.")
# Pass current time in milliseconds for cache expiry checking
now = time.time() * 1000
if info.load_from_cache(self.aiozc.zeroconf, now):
return info.parsed_scoped_addresses(IPVersion.All)
resolver_name = f"{base_name}.local."
info = AddressResolver(resolver_name)
# Let zeroconf use its own current time for cache checking
if info.load_from_cache(self.aiozc.zeroconf):
addresses = info.parsed_scoped_addresses(IPVersion.All)
_LOGGER.debug("Found %s in zeroconf cache: %s", resolver_name, addresses)
return addresses
_LOGGER.debug("Not found in zeroconf cache: %s", resolver_name)
return None
async def async_refresh_hosts(self) -> None: