Skip to content

Commit 6160237

Browse files
committed
updated example to use async scan
1 parent 72f36b8 commit 6160237

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

examples/scan.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,20 @@
88
import sys
99
import velbus
1010

11+
def new_module(module, channel):
12+
print(module)
13+
print(channel)
1114

12-
def scan_finished():
13-
"""
14-
Callback for finished scan
15-
"""
16-
logging.info(controller.get_modules("switch"))
17-
logging.info(controller.get_modules("binary_sensor"))
18-
19-
20-
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
15+
logging.basicConfig(stream=sys.stdout, level=logging.WARNING)
2116
# pylint: disable-msg=C0103
22-
port = "/dev/ttyACM0"
17+
port = "/dev/velbus"
2318
logging.info("Configuring controller")
2419
controller = velbus.Controller(port)
20+
controller.subscribe_module(new_module, 'switch')
21+
controller.subscribe_module(new_module, 'binary_sensor')
2522
logging.info("Starting scan")
26-
controller.scan(scan_finished)
23+
controller.async_scan()
2724
logging.info("Starting sleep")
28-
time.sleep(30)
25+
time.sleep(60*10)
2926
logging.info("Exiting ...")
3027
controller.stop()

0 commit comments

Comments
 (0)