giving loop to other classes may keep the other loops from crashing/becoming un-useable.
This commit is contained in:
+3
-9
@@ -4,13 +4,14 @@ from wand import Wand
|
||||
class Shop(object):
|
||||
"""A scanner class to connect to wands
|
||||
"""
|
||||
def __init__(self, wand_class=Wand, debug=False):
|
||||
def __init__(self, shop_loop, wand_class=Wand, debug=False):
|
||||
"""Create a new scanner
|
||||
|
||||
Keyword Arguments:
|
||||
wand_class {class} -- Class to use when connecting to wand (default: {Wand})
|
||||
debug {bool} -- Print debug messages (default: {False})
|
||||
"""
|
||||
self.shop_loop = shop_loop
|
||||
self.wand_class = wand_class
|
||||
self.debug = debug
|
||||
self._name = None
|
||||
@@ -39,27 +40,20 @@ class Shop(object):
|
||||
except AssertionError as e:
|
||||
print("Either a name, prefix, or mac address must be provided to find a wand")
|
||||
raise e
|
||||
|
||||
|
||||
if prefix is not None:
|
||||
self._prefix = prefix
|
||||
elif mac is not None:
|
||||
self._mac = mac
|
||||
|
||||
self.wands = []
|
||||
|
||||
devices = await discover(timeout= timeout)
|
||||
|
||||
print(devices)
|
||||
|
||||
if self._prefix:
|
||||
devices = list(filter(lambda x : x.name.startswith(self._prefix), devices))
|
||||
if self._mac:
|
||||
devices = list(filter(lambda x : x.address == self.mac, devices))
|
||||
|
||||
print(devices)
|
||||
|
||||
self.wands = [Wand(d.address, d.name) for d in devices]
|
||||
self.wands = [Wand(d.address, d.name, self.shop_loop) for d in devices]
|
||||
print(self.wands)
|
||||
if connect:
|
||||
for wand in self.wands:
|
||||
|
||||
Reference in New Issue
Block a user