diff --git a/aioesphomeapi/util.py b/aioesphomeapi/util.py index cc91a820..02072522 100644 --- a/aioesphomeapi/util.py +++ b/aioesphomeapi/util.py @@ -45,7 +45,7 @@ def host_is_name_part(address: str) -> bool: def address_is_local(address: str) -> bool: """Return True if the address is a local address.""" - return address.removesuffix(".").endswith(".local") + return address.removesuffix(".").lower().endswith(".local") def is_ip_address(address: str | None) -> bool: diff --git a/tests/test_util.py b/tests/test_util.py index d79f032c..8efec248 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -5,7 +5,7 @@ import pytest from aioesphomeapi import util -from aioesphomeapi.util import is_ip_address +from aioesphomeapi.util import address_is_local, is_ip_address @pytest.mark.parametrize( @@ -119,3 +119,22 @@ async def _eager_task(): ) def test_is_ip_address(address: str | None, expected: bool) -> None: assert is_ip_address(address) is expected + + +@pytest.mark.parametrize( + ("address", "expected"), + [ + ("myesp.local", True), + ("myesp.local.", True), + # mDNS / DNS names are case-insensitive (RFC 6762 ยง16, RFC 4343). + ("MyESP.LOCAL", True), + ("myesp.Local", True), + ("MYESP.LOCAL.", True), + ("myesp", False), + ("myesp.localdomain", False), + ("host.example.com", False), + ("", False), + ], +) +def test_address_is_local(address: str, expected: bool) -> None: + assert address_is_local(address) is expected