Repository: esphome/aioesphomeapi (language: python)

Issue:
addresses_by_version is not recommended and has been superseded by ip_addresses_by_version in zeroconf 0.53+
https://github.com/esphome/aioesphomeapi/blob/193ad298e0812f07cd54d9e2e4ed9edd6f0b2efd/aioesphomeapi/host_resolver.py#L104C13-L104C13

see home-assistant/core#101039


Discussion / hints:

Fix patch:
diff --git a/aioesphomeapi/host_resolver.py b/aioesphomeapi/host_resolver.py
index 80606f7f..5e510d7a 100644
--- a/aioesphomeapi/host_resolver.py
+++ b/aioesphomeapi/host_resolver.py
@@ -47,7 +47,7 @@ async def _async_zeroconf_get_service_info(
     service_type: str,
     service_name: str,
     timeout: float,
-) -> "zeroconf.ServiceInfo" | None:
+) -> "zeroconf.asyncio.AsyncServiceInfo" | None:
     # Use or create zeroconf instance, ensure it's an AsyncZeroconf
     if zeroconf_instance is None:
         try:
@@ -101,19 +101,19 @@ async def _async_resolve_host_zeroconf(
         return []
 
     addrs: list[AddrInfo] = []
-    for raw in info.addresses_by_version(zeroconf.IPVersion.All):
-        is_ipv6 = len(raw) == 16
+    for ip_address in info.ip_addresses_by_version(zeroconf.IPVersion.All):
+        is_ipv6 = ip_address.version == 6
         sockaddr: Sockaddr
         if is_ipv6:
             sockaddr = IPv6Sockaddr(
-                address=socket.inet_ntop(socket.AF_INET6, raw),
+                address=str(ip_address),
                 port=port,
                 flowinfo=0,
                 scope_id=0,
             )
         else:
             sockaddr = IPv4Sockaddr(
-                address=socket.inet_ntop(socket.AF_INET, raw),
+                address=str(ip_address),
                 port=port,
             )
 


Test patch:
diff --git a/tests/test_host_resolver.py b/tests/test_host_resolver.py
index 541461e3..03894f47 100644
--- a/tests/test_host_resolver.py
+++ b/tests/test_host_resolver.py
@@ -1,5 +1,5 @@
-import asyncio
 import socket
+from ipaddress import ip_address
 
 import pytest
 from mock import AsyncMock, MagicMock, patch
@@ -40,9 +40,9 @@ def addr_infos():
 @pytest.mark.asyncio
 async def test_resolve_host_zeroconf(async_zeroconf, addr_infos):
     info = MagicMock()
-    info.addresses_by_version.return_value = [
-        b"\n\x00\x00*",
-        b" \x01\r\xb8\x85\xa3\x00\x00\x00\x00\x8a.\x03ps4",
+    info.ip_addresses_by_version.return_value = [
+        ip_address(b"\n\x00\x00*"),
+        ip_address(b" \x01\r\xb8\x85\xa3\x00\x00\x00\x00\x8a.\x03ps4"),
     ]
     async_zeroconf.async_get_service_info = AsyncMock(return_value=info)
     async_zeroconf.async_close = AsyncMock()