giving loop to other classes may keep the other loops from crashing/becoming un-useable.

This commit is contained in:
Lucas Oskorep
2020-03-06 10:32:43 -06:00
parent d58229f0a1
commit f9c9b9fc8c
3 changed files with 25 additions and 26 deletions
+3 -9
View File
@@ -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: