File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1239,3 +1239,22 @@ def mock_incoming_msg(records) -> r.DNSIncoming:
12391239 browser .cancel ()
12401240
12411241 zc .close ()
1242+
1243+
1244+ def test_changing_name_updates_serviceinfo_key ():
1245+ """Verify a name change will adjust the underlying key value."""
1246+ type_ = "_homeassistant._tcp.local."
1247+ name = "MyTestHome"
1248+ info_service = ServiceInfo (
1249+ type_ ,
1250+ '%s.%s' % (name , type_ ),
1251+ 80 ,
1252+ 0 ,
1253+ 0 ,
1254+ {'path' : '/~paulsm/' },
1255+ "ash-2.local." ,
1256+ addresses = [socket .inet_aton ("10.0.1.2" )],
1257+ )
1258+ assert info_service .key == "mytesthome._homeassistant._tcp.local."
1259+ info_service .name = "YourTestHome._homeassistant._tcp.local."
1260+ assert info_service .key == "yourtesthome._homeassistant._tcp.local."
Original file line number Diff line number Diff line change @@ -466,7 +466,7 @@ def __init__(
466466 if not type_ .endswith (service_type_name (name , strict = False )):
467467 raise BadTypeInNameException
468468 self .type = type_
469- self .name = name
469+ self ._name = name
470470 self .key = name .lower ()
471471 if addresses is not None :
472472 self ._addresses = addresses
@@ -494,6 +494,17 @@ def __init__(
494494 self .host_ttl = host_ttl
495495 self .other_ttl = other_ttl
496496
497+ @property
498+ def name (self ) -> str :
499+ """The name of the service."""
500+ return self ._name
501+
502+ @name .setter
503+ def name (self , name : str ) -> None :
504+ """Replace the the name and reset the key."""
505+ self ._name = name
506+ self .key = name .lower ()
507+
497508 @property
498509 def addresses (self ) -> List [bytes ]:
499510 """IPv4 addresses of this service.
You can’t perform that action at this time.
0 commit comments