Skip to content

Commit

Permalink
fix service
Browse files Browse the repository at this point in the history
  • Loading branch information
ihidchaos committed Nov 29, 2024
1 parent 1e712f6 commit f28a95d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
28 changes: 14 additions & 14 deletions circuitmatter/utility/mdns/zeroconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ def advertise_service(
subtypes=[],
instance_name="",
):
txt_records = [f"{key}={value}" for key, value in txt_records.items()]
txt_records = {key: value for key, value in txt_records.items()}
main_info = ServiceInfo(
f"{service_type}.{protocol}.local",
instance_name,
f"{service_type}.{protocol}.local.",
f"{service_type}.{protocol}.local.",
addresses=[socket.inet_aton("0.0.0.0")],
port=port,
properties=txt_records,
)

sub_info = ServiceInfo(
subtypes,
instance_name,
addresses=[socket.inet_aton("0.0.0.0")],
port=port,
properties=txt_records,
)

self.zeroconf.register_service(main_info)
self.zeroconf.register_service(sub_info)
self.service_infos[service_type + instance_name] = main_info
self.service_infos[subtypes + instance_name] = sub_info

for subtype in subtypes:
sub_info = ServiceInfo(
f"{subtype}.local.",
f"{subtype}.local.",
addresses=[socket.inet_aton("0.0.0.0")],
port=port,
properties=txt_records,
)
self.service_infos[subtype] = sub_info
self.zeroconf.register_service(sub_info)

def __del__(self):
for service_info in self.service_infos.values():
Expand Down
16 changes: 8 additions & 8 deletions examples/fake_onoff_led.py → fake_onoff_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@


class LED(on_off.OnOffLight):
def __init__(self, name, led):
def __init__(self, name):
super().__init__(name)
self._name = name
self._led = led
self.state = False

def on(self):
self._led.value = True
self.state = True
print("Led %s is On", self._name)

def off(self):
self._led.value = False
self.state = False
print("Led %s is Off", self._name)


matter = cm.CircuitMatter()
led = LED("led1")
matter.add_device(led)
led = LED("led2")
matter.add_device(led)
led1 = LED("led1")
matter.add_device(led1)
led2 = LED("led2")
matter.add_device(led2)
while True:
matter.process_packets()

0 comments on commit f28a95d

Please sign in to comment.