Skip to content

Commit

Permalink
Fix zeroconf name resolution refactoring error (esphome#5725)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 10, 2023
1 parent 3b891bc commit 3363c8f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions esphome/zeroconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ def update_device_mdns(self, node_name: str, version: str):


class EsphomeZeroconf(Zeroconf):
def resolve_host(self, host: str, timeout=3.0):
def resolve_host(self, host: str, timeout: float = 3.0) -> str | None:
"""Resolve a host name to an IP address."""
name = host.partition(".")[0]
info = HostResolver(f"{name}.{ESPHOME_SERVICE_TYPE}", ESPHOME_SERVICE_TYPE)
if (info.load_from_cache(self) or info.request(self, timeout * 1000)) and (
addresses := info.ip_addresses_by_version(IPVersion.V4Only)
):
info = HostResolver(ESPHOME_SERVICE_TYPE, f"{name}.{ESPHOME_SERVICE_TYPE}")
if (
info.load_from_cache(self)
or (timeout and info.request(self, timeout * 1000))
) and (addresses := info.ip_addresses_by_version(IPVersion.V4Only)):
return str(addresses[0])
return None

0 comments on commit 3363c8f

Please sign in to comment.