From 23d82f8368f38999577d7e8bb586a8f6aa0c6f02 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 11 Sep 2025 18:54:06 -0500 Subject: [PATCH] preen --- esphome/dashboard/dns.py | 6 ++++-- esphome/dashboard/status/mdns.py | 5 ++++- esphome/dashboard/web_server.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/esphome/dashboard/dns.py b/esphome/dashboard/dns.py index b94d816c74..58867f7bc1 100644 --- a/esphome/dashboard/dns.py +++ b/esphome/dashboard/dns.py @@ -28,8 +28,10 @@ class DNSCache: self._cache: dict[str, tuple[float, list[str] | Exception]] = {} self._ttl = ttl - def get_cached(self, hostname: str, now_monotonic: float) -> list[str] | None: - """Get cached address without triggering resolution. + def get_cached_addresses( + self, hostname: str, now_monotonic: float + ) -> list[str] | None: + """Get cached addresses without triggering resolution. Returns None if not in cache, list of addresses if found. """ diff --git a/esphome/dashboard/status/mdns.py b/esphome/dashboard/status/mdns.py index 576bade7cd..c1bf1ce21f 100644 --- a/esphome/dashboard/status/mdns.py +++ b/esphome/dashboard/status/mdns.py @@ -2,6 +2,7 @@ from __future__ import annotations import asyncio import logging +import time import typing from zeroconf import AddressResolver, IPVersion @@ -67,7 +68,9 @@ class MDNSStatus: # Try to load from zeroconf cache without triggering resolution info = AddressResolver(f"{base_name}.local.") - if info.load_from_cache(self.aiozc.zeroconf): + # 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) return None diff --git a/esphome/dashboard/web_server.py b/esphome/dashboard/web_server.py index 9637bc6b88..90a7cab3b5 100644 --- a/esphome/dashboard/web_server.py +++ b/esphome/dashboard/web_server.py @@ -364,7 +364,7 @@ class EsphomePortCommandWebSocket(EsphomeCommandWebSocket): ) else: # Check DNS cache for non-.local addresses - cached = dashboard.dns_cache.get_cached(use_address, now) + cached = dashboard.dns_cache.get_cached_addresses(use_address, now) _LOGGER.debug( "DNS cache lookup for address %s: %s", use_address, cached )