Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aioesphomeapi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 20 additions & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Loading