mirror of
https://github.com/esphome/esphome.git
synced 2025-10-14 07:43:48 +01:00
preen
This commit is contained in:
@@ -28,8 +28,10 @@ class DNSCache:
|
|||||||
self._cache: dict[str, tuple[float, list[str] | Exception]] = {}
|
self._cache: dict[str, tuple[float, list[str] | Exception]] = {}
|
||||||
self._ttl = ttl
|
self._ttl = ttl
|
||||||
|
|
||||||
def get_cached(self, hostname: str, now_monotonic: float) -> list[str] | None:
|
def get_cached_addresses(
|
||||||
"""Get cached address without triggering resolution.
|
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.
|
Returns None if not in cache, list of addresses if found.
|
||||||
"""
|
"""
|
||||||
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from zeroconf import AddressResolver, IPVersion
|
from zeroconf import AddressResolver, IPVersion
|
||||||
@@ -67,7 +68,9 @@ class MDNSStatus:
|
|||||||
|
|
||||||
# Try to load from zeroconf cache without triggering resolution
|
# Try to load from zeroconf cache without triggering resolution
|
||||||
info = AddressResolver(f"{base_name}.local.")
|
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 info.parsed_scoped_addresses(IPVersion.All)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@@ -364,7 +364,7 @@ class EsphomePortCommandWebSocket(EsphomeCommandWebSocket):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Check DNS cache for non-.local addresses
|
# 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(
|
_LOGGER.debug(
|
||||||
"DNS cache lookup for address %s: %s", use_address, cached
|
"DNS cache lookup for address %s: %s", use_address, cached
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user