mirror of
https://github.com/esphome/esphome.git
synced 2025-09-26 23:22:21 +01:00
make entry.address take priority over mdns
This commit is contained in:
@@ -324,15 +324,15 @@ class EsphomePortCommandWebSocket(EsphomeCommandWebSocket):
|
|||||||
configuration = json_message["configuration"]
|
configuration = json_message["configuration"]
|
||||||
config_file = settings.rel_path(configuration)
|
config_file = settings.rel_path(configuration)
|
||||||
port = json_message["port"]
|
port = json_message["port"]
|
||||||
addresses: list[str] = []
|
addresses: list[str] = [port]
|
||||||
|
|
||||||
if (
|
if (
|
||||||
port == "OTA" # pylint: disable=too-many-boolean-expressions
|
port == "OTA" # pylint: disable=too-many-boolean-expressions
|
||||||
and (entry := entries.get(config_file))
|
and (entry := entries.get(config_file))
|
||||||
and entry.loaded_integrations
|
and entry.loaded_integrations
|
||||||
and "api" in entry.loaded_integrations
|
and "api" in entry.loaded_integrations
|
||||||
):
|
):
|
||||||
# First priority: use_address from configuration
|
addresses = []
|
||||||
|
# First priority: entry.address AKA use_address
|
||||||
if (
|
if (
|
||||||
entry.address
|
entry.address
|
||||||
and (
|
and (
|
||||||
@@ -342,32 +342,23 @@ class EsphomePortCommandWebSocket(EsphomeCommandWebSocket):
|
|||||||
)
|
)
|
||||||
and not isinstance(address_list, Exception)
|
and not isinstance(address_list, Exception)
|
||||||
):
|
):
|
||||||
addresses = sort_ip_addresses(address_list)
|
addresses.extend(sort_ip_addresses(address_list))
|
||||||
# Second priority: mDNS resolved addresses
|
|
||||||
elif (mdns := dashboard.mdns_status) and (
|
# Second priority: mDNS
|
||||||
|
if (mdns := dashboard.mdns_status) and (
|
||||||
address_list := await mdns.async_resolve_host(entry.name)
|
address_list := await mdns.async_resolve_host(entry.name)
|
||||||
):
|
):
|
||||||
# Use all IP addresses if available but only
|
# Use the IP address if available but only
|
||||||
# if the API is loaded and the device is online
|
# if the API is loaded and the device is online
|
||||||
# since MQTT logging will not work otherwise
|
# since MQTT logging will not work otherwise
|
||||||
addresses = sort_ip_addresses(address_list)
|
addresses.extend(sort_ip_addresses(address_list))
|
||||||
|
|
||||||
# Build command with multiple --device arguments for each address
|
device_args: list[str] = []
|
||||||
command = [
|
for address in addresses:
|
||||||
*DASHBOARD_COMMAND,
|
device_args.append("--device")
|
||||||
*args,
|
device_args.append(address)
|
||||||
config_file,
|
|
||||||
]
|
|
||||||
|
|
||||||
if addresses:
|
return [*DASHBOARD_COMMAND, *args, config_file, *device_args]
|
||||||
# Add multiple --device arguments for each resolved address
|
|
||||||
for address in addresses:
|
|
||||||
command.extend(["--device", address])
|
|
||||||
else:
|
|
||||||
# Fallback to original port if no addresses were resolved
|
|
||||||
command.extend(["--device", port])
|
|
||||||
|
|
||||||
return command
|
|
||||||
|
|
||||||
|
|
||||||
class EsphomeLogsHandler(EsphomePortCommandWebSocket):
|
class EsphomeLogsHandler(EsphomePortCommandWebSocket):
|
||||||
|
Reference in New Issue
Block a user