mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 06:58:11 +01:00
Fix dashboard ip resolving (#7747)
This commit is contained in:
parent
1829e68730
commit
335faf858b
3 changed files with 9 additions and 8 deletions
|
@ -26,7 +26,7 @@ class MDNSStatus:
|
||||||
self.host_mdns_state: dict[str, bool | None] = {}
|
self.host_mdns_state: dict[str, bool | None] = {}
|
||||||
self._loop = asyncio.get_running_loop()
|
self._loop = asyncio.get_running_loop()
|
||||||
|
|
||||||
async def async_resolve_host(self, host_name: str) -> str | None:
|
async def async_resolve_host(self, host_name: str) -> list[str] | None:
|
||||||
"""Resolve a host name to an address in a thread-safe manner."""
|
"""Resolve a host name to an address in a thread-safe manner."""
|
||||||
if aiozc := self.aiozc:
|
if aiozc := self.aiozc:
|
||||||
return await aiozc.async_resolve_host(host_name)
|
return await aiozc.async_resolve_host(host_name)
|
||||||
|
@ -50,13 +50,12 @@ class MDNSStatus:
|
||||||
poll_names.setdefault(entry.name, set()).add(entry)
|
poll_names.setdefault(entry.name, set()).add(entry)
|
||||||
elif (online := host_mdns_state.get(entry.name, SENTINEL)) != SENTINEL:
|
elif (online := host_mdns_state.get(entry.name, SENTINEL)) != SENTINEL:
|
||||||
entries.async_set_state(entry, bool_to_entry_state(online))
|
entries.async_set_state(entry, bool_to_entry_state(online))
|
||||||
|
|
||||||
if poll_names and self.aiozc:
|
if poll_names and self.aiozc:
|
||||||
results = await asyncio.gather(
|
results = await asyncio.gather(
|
||||||
*(self.aiozc.async_resolve_host(name) for name in poll_names)
|
*(self.aiozc.async_resolve_host(name) for name in poll_names)
|
||||||
)
|
)
|
||||||
for name, address in zip(poll_names, results):
|
for name, address_list in zip(poll_names, results):
|
||||||
result = bool(address)
|
result = bool(address_list)
|
||||||
host_mdns_state[name] = result
|
host_mdns_state[name] = result
|
||||||
for entry in poll_names[name]:
|
for entry in poll_names[name]:
|
||||||
entries.async_set_state(entry, bool_to_entry_state(result))
|
entries.async_set_state(entry, bool_to_entry_state(result))
|
||||||
|
|
|
@ -320,12 +320,12 @@ class EsphomePortCommandWebSocket(EsphomeCommandWebSocket):
|
||||||
and "api" in entry.loaded_integrations
|
and "api" in entry.loaded_integrations
|
||||||
):
|
):
|
||||||
if (mdns := dashboard.mdns_status) and (
|
if (mdns := dashboard.mdns_status) and (
|
||||||
address := await mdns.async_resolve_host(entry.name)
|
address_list := await mdns.async_resolve_host(entry.name)
|
||||||
):
|
):
|
||||||
# Use the IP address 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
|
||||||
port = address
|
port = address_list[0]
|
||||||
elif (
|
elif (
|
||||||
entry.address
|
entry.address
|
||||||
and (
|
and (
|
||||||
|
|
|
@ -176,7 +176,7 @@ def _make_host_resolver(host: str) -> HostResolver:
|
||||||
|
|
||||||
|
|
||||||
class EsphomeZeroconf(Zeroconf):
|
class EsphomeZeroconf(Zeroconf):
|
||||||
def resolve_host(self, host: str, timeout: float = 3.0) -> str | None:
|
def resolve_host(self, host: str, timeout: float = 3.0) -> list[str] | None:
|
||||||
"""Resolve a host name to an IP address."""
|
"""Resolve a host name to an IP address."""
|
||||||
info = _make_host_resolver(host)
|
info = _make_host_resolver(host)
|
||||||
if (
|
if (
|
||||||
|
@ -188,7 +188,9 @@ class EsphomeZeroconf(Zeroconf):
|
||||||
|
|
||||||
|
|
||||||
class AsyncEsphomeZeroconf(AsyncZeroconf):
|
class AsyncEsphomeZeroconf(AsyncZeroconf):
|
||||||
async def async_resolve_host(self, host: str, timeout: float = 3.0) -> str | None:
|
async def async_resolve_host(
|
||||||
|
self, host: str, timeout: float = 3.0
|
||||||
|
) -> list[str] | None:
|
||||||
"""Resolve a host name to an IP address."""
|
"""Resolve a host name to an IP address."""
|
||||||
info = _make_host_resolver(host)
|
info = _make_host_resolver(host)
|
||||||
if (
|
if (
|
||||||
|
|
Loading…
Reference in a new issue