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
19 changes: 19 additions & 0 deletions tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,3 +1239,22 @@ def mock_incoming_msg(records) -> r.DNSIncoming:
browser.cancel()

zc.close()


def test_changing_name_updates_serviceinfo_key():
"""Verify a name change will adjust the underlying key value."""
type_ = "_homeassistant._tcp.local."
name = "MyTestHome"
info_service = ServiceInfo(
type_,
'%s.%s' % (name, type_),
80,
0,
0,
{'path': '/~paulsm/'},
"ash-2.local.",
addresses=[socket.inet_aton("10.0.1.2")],
)
assert info_service.key == "mytesthome._homeassistant._tcp.local."
info_service.name = "YourTestHome._homeassistant._tcp.local."
assert info_service.key == "yourtesthome._homeassistant._tcp.local."
13 changes: 12 additions & 1 deletion zeroconf/_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def __init__(
if not type_.endswith(service_type_name(name, strict=False)):
raise BadTypeInNameException
self.type = type_
self.name = name
self._name = name
self.key = name.lower()
if addresses is not None:
self._addresses = addresses
Expand Down Expand Up @@ -494,6 +494,17 @@ def __init__(
self.host_ttl = host_ttl
self.other_ttl = other_ttl

@property
def name(self) -> str:
"""The name of the service."""
return self._name

@name.setter
def name(self, name: str) -> None:
"""Replace the the name and reset the key."""
self._name = name
self.key = name.lower()

@property
def addresses(self) -> List[bytes]:
"""IPv4 addresses of this service.
Expand Down