mirror of
https://github.com/esphome/esphome.git
synced 2025-10-07 20:33:47 +01:00
cleanup
This commit is contained in:
@@ -327,8 +327,7 @@ class EsphomePortCommandWebSocket(EsphomeCommandWebSocket):
|
|||||||
config_file = settings.rel_path(configuration)
|
config_file = settings.rel_path(configuration)
|
||||||
port = json_message["port"]
|
port = json_message["port"]
|
||||||
|
|
||||||
# Only get cached addresses - no async resolution
|
# Build cache arguments to pass to CLI
|
||||||
addresses: list[str] = []
|
|
||||||
cache_args: list[str] = []
|
cache_args: list[str] = []
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -339,53 +338,43 @@ class EsphomePortCommandWebSocket(EsphomeCommandWebSocket):
|
|||||||
):
|
):
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
|
|
||||||
# Collect all cached addresses for this device
|
# Build cache entries for any cached addresses we have
|
||||||
dns_cache_entries: dict[str, set[str]] = {}
|
# First check entry.address (use_address)
|
||||||
mdns_cache_entries: dict[str, set[str]] = {}
|
|
||||||
|
|
||||||
# First priority: entry.address AKA use_address (from DNS cache only)
|
|
||||||
if (use_address := entry.address) and (
|
if (use_address := entry.address) and (
|
||||||
cached := dashboard.dns_cache.get_cached(use_address, now)
|
cached := dashboard.dns_cache.get_cached(use_address, now)
|
||||||
):
|
):
|
||||||
addresses.extend(sort_ip_addresses(cached))
|
normalized = use_address.rstrip(".").lower()
|
||||||
dns_cache_entries[use_address] = set(cached)
|
cache_args.extend(
|
||||||
|
[
|
||||||
|
"--dns-lookup-cache",
|
||||||
|
f"{normalized}={','.join(sort_ip_addresses(cached))}",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
# Second priority: mDNS cache for device name
|
# Also check entry.name for cache entries
|
||||||
if entry.name and not addresses: # Only if we don't have addresses yet
|
if entry.name:
|
||||||
if entry.name.endswith(".local"):
|
if entry.name.endswith(".local"):
|
||||||
# Check mDNS cache (zeroconf)
|
# Check mDNS cache (zeroconf)
|
||||||
if (mdns := dashboard.mdns_status) and (
|
if (mdns := dashboard.mdns_status) and (
|
||||||
cached := mdns.get_cached_addresses(entry.name)
|
cached := mdns.get_cached_addresses(entry.name)
|
||||||
):
|
):
|
||||||
addresses.extend(sort_ip_addresses(cached))
|
normalized = entry.name.rstrip(".").lower()
|
||||||
mdns_cache_entries[entry.name] = set(cached)
|
|
||||||
# Check DNS cache for non-.local names
|
|
||||||
elif cached := dashboard.dns_cache.get_cached(entry.name, now):
|
|
||||||
addresses.extend(sort_ip_addresses(cached))
|
|
||||||
dns_cache_entries[entry.name] = set(cached)
|
|
||||||
|
|
||||||
# Build cache arguments to pass to CLI (normalize hostnames)
|
|
||||||
for hostname, addrs in dns_cache_entries.items():
|
|
||||||
normalized = hostname.rstrip(".").lower()
|
|
||||||
cache_args.extend(
|
cache_args.extend(
|
||||||
["--dns-lookup-cache", f"{normalized}={','.join(sorted(addrs))}"]
|
[
|
||||||
)
|
"--mdns-lookup-cache",
|
||||||
for hostname, addrs in mdns_cache_entries.items():
|
f"{normalized}={','.join(sort_ip_addresses(cached))}",
|
||||||
normalized = hostname.rstrip(".").lower()
|
|
||||||
cache_args.extend(
|
|
||||||
["--mdns-lookup-cache", f"{normalized}={','.join(sorted(addrs))}"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if not addresses:
|
|
||||||
# If no cached address was found, use the port directly
|
|
||||||
# The CLI will do the resolution with the cache hints we provide
|
|
||||||
addresses = [port]
|
|
||||||
|
|
||||||
device_args: list[str] = [
|
|
||||||
arg for address in addresses for arg in ("--device", address)
|
|
||||||
]
|
]
|
||||||
|
)
|
||||||
|
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_args, *cache_args]
|
return [*DASHBOARD_COMMAND, *args, config_file, "--device", port, *cache_args]
|
||||||
|
|
||||||
|
|
||||||
class EsphomeLogsHandler(EsphomePortCommandWebSocket):
|
class EsphomeLogsHandler(EsphomePortCommandWebSocket):
|
||||||
|
Reference in New Issue
Block a user