-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replase Avahi with ZeroConf for cross platform;add fake LED for testing
- Loading branch information
Showing
7 changed files
with
88 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 Scott Shawcroft for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import socket | ||
from zeroconf import IPVersion, ServiceInfo, Zeroconf | ||
|
||
class ZeroConf: | ||
def __init__(self): | ||
self.zeroconf = Zeroconf(ip_version=IPVersion.All) | ||
self.service_infos = {} | ||
|
||
def advertise_service( | ||
self, | ||
service_type, | ||
protocol, | ||
port, | ||
txt_records={}, | ||
subtypes=[], | ||
instance_name="", | ||
): | ||
txt_records = [f"{key}={value}" for key, value in txt_records.items()] | ||
main_info = ServiceInfo( | ||
f"{service_type}.{protocol}.local", | ||
instance_name, | ||
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 | ||
|
||
def __del__(self): | ||
for service_info in self.service_infos.values(): | ||
self.zeroconf.unregister_service(service_info) | ||
self.zeroconf.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 Scott Shawcroft for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
"""Simple fake LED on and off as a light.""" | ||
|
||
import circuitmatter as cm | ||
from circuitmatter.device_types.lighting import on_off | ||
|
||
|
||
class LED(on_off.OnOffLight): | ||
def __init__(self, name, led): | ||
super().__init__(name) | ||
self._name = name | ||
self._led = led | ||
|
||
def on(self): | ||
self._led.value = True | ||
print("Led %s is On", self._name) | ||
|
||
def off(self): | ||
self._led.value = 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) | ||
while True: | ||
matter.process_packets() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ requires = [ | |
"setuptools", | ||
"wheel", | ||
"setuptools-scm", | ||
"zeroconf", | ||
] | ||
|
||
[project] | ||
|