1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-17 10:42:21 +01:00
This commit is contained in:
J. Nick Koston
2025-09-11 18:47:09 -05:00
parent 80240437c5
commit 7fb8c84d6a
2 changed files with 64 additions and 27 deletions

View File

@@ -136,6 +136,13 @@ def choose_upload_log_host(
(show_ota and "ota" in CORE.config) (show_ota and "ota" in CORE.config)
or (show_api and "api" in CORE.config) or (show_api and "api" in CORE.config)
): ):
# Check if we have cached addresses for CORE.address
if CORE.address_cache and (
cached := CORE.address_cache.get_addresses(CORE.address)
):
_LOGGER.debug("Using cached addresses for OTA: %s", cached)
resolved.extend(cached)
else:
resolved.append(CORE.address) resolved.append(CORE.address)
elif show_mqtt and has_mqtt_logging(): elif show_mqtt and has_mqtt_logging():
resolved.append("MQTT") resolved.append("MQTT")

View File

@@ -337,12 +337,38 @@ class EsphomePortCommandWebSocket(EsphomeCommandWebSocket):
and "api" in entry.loaded_integrations and "api" in entry.loaded_integrations
): ):
now = time.monotonic() now = time.monotonic()
_LOGGER.debug(
"Building cache for %s (address=%s, name=%s)",
configuration,
entry.address,
entry.name,
)
# Build cache entries for any cached addresses we have # Build cache entries for any cached addresses we have
# First check entry.address (use_address) # First check entry.address (use_address)
if (use_address := entry.address) and ( if use_address := entry.address:
cached := dashboard.dns_cache.get_cached(use_address, now) if use_address.endswith(".local"):
): # Check mDNS cache for .local addresses
if mdns := dashboard.mdns_status:
cached = mdns.get_cached_addresses(use_address)
_LOGGER.debug(
"mDNS cache lookup for address %s: %s", use_address, cached
)
if cached:
normalized = use_address.rstrip(".").lower()
cache_args.extend(
[
"--mdns-lookup-cache",
f"{normalized}={','.join(sort_ip_addresses(cached))}",
]
)
else:
# Check DNS cache for non-.local addresses
cached = dashboard.dns_cache.get_cached(use_address, now)
_LOGGER.debug(
"DNS cache lookup for address %s: %s", use_address, cached
)
if cached:
normalized = use_address.rstrip(".").lower() normalized = use_address.rstrip(".").lower()
cache_args.extend( cache_args.extend(
[ [
@@ -352,29 +378,33 @@ class EsphomePortCommandWebSocket(EsphomeCommandWebSocket):
) )
# Also check entry.name for cache entries # Also check entry.name for cache entries
if entry.name: # For mDNS devices, entry.name typically doesn't have .local suffix
if entry.name.endswith(".local"): # but we should check both with and without .local
# Check mDNS cache (zeroconf) if (
if (mdns := dashboard.mdns_status) and ( entry.name and not use_address
cached := mdns.get_cached_addresses(entry.name) ): # Only if we didn't already check address
): # Try mDNS cache with .local suffix
normalized = entry.name.rstrip(".").lower() mdns_name = (
f"{entry.name}.local"
if not entry.name.endswith(".local")
else entry.name
)
if mdns := dashboard.mdns_status:
cached = mdns.get_cached_addresses(mdns_name)
_LOGGER.debug("mDNS cache lookup for %s: %s", mdns_name, cached)
if cached:
normalized = mdns_name.rstrip(".").lower()
cache_args.extend( cache_args.extend(
[ [
"--mdns-lookup-cache", "--mdns-lookup-cache",
f"{normalized}={','.join(sort_ip_addresses(cached))}", f"{normalized}={','.join(sort_ip_addresses(cached))}",
] ]
) )
elif cached := dashboard.dns_cache.get_cached(entry.name, now):
normalized = entry.name.rstrip(".").lower()
cache_args.extend(
[
"--dns-lookup-cache",
f"{normalized}={','.join(sort_ip_addresses(cached))}",
]
)
return [*DASHBOARD_COMMAND, *args, config_file, "--device", port, *cache_args] # Cache arguments must come before the subcommand
cmd = [*DASHBOARD_COMMAND, *cache_args, *args, config_file, "--device", port]
_LOGGER.debug("Built command: %s", cmd)
return cmd
class EsphomeLogsHandler(EsphomePortCommandWebSocket): class EsphomeLogsHandler(EsphomePortCommandWebSocket):