Adding filtering to the shop.
This commit is contained in:
+12
-42
@@ -17,7 +17,7 @@ class Shop(object):
|
|||||||
self._prefix = None
|
self._prefix = None
|
||||||
self._mac = None
|
self._mac = None
|
||||||
|
|
||||||
async def scan(self, name=None, prefix="Kano-Wand", mac=None, timeout=2.0, connect=False):
|
async def scan(self, prefix="Kano-Wand", mac=None, timeout=2.0, connect=False):
|
||||||
"""Scan for devices
|
"""Scan for devices
|
||||||
|
|
||||||
Keyword Arguments:
|
Keyword Arguments:
|
||||||
@@ -33,17 +33,15 @@ class Shop(object):
|
|||||||
if self.debug:
|
if self.debug:
|
||||||
print("Scanning for {} seconds...".format(timeout))
|
print("Scanning for {} seconds...".format(timeout))
|
||||||
try:
|
try:
|
||||||
name_check = not (name is None)
|
|
||||||
prefix_check = not (prefix is None)
|
prefix_check = not (prefix is None)
|
||||||
mac_check = not (mac is None)
|
mac_check = not (mac is None)
|
||||||
assert name_check or prefix_check or mac_check
|
assert prefix_check or mac_check
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
print("Either a name, prefix, or mac address must be provided to find a wand")
|
print("Either a name, prefix, or mac address must be provided to find a wand")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
if name is not None:
|
|
||||||
self._name = name
|
if prefix is not None:
|
||||||
elif prefix is not None:
|
|
||||||
self._prefix = prefix
|
self._prefix = prefix
|
||||||
elif mac is not None:
|
elif mac is not None:
|
||||||
self._mac = mac
|
self._mac = mac
|
||||||
@@ -52,46 +50,18 @@ class Shop(object):
|
|||||||
|
|
||||||
devices = await discover(timeout= timeout)
|
devices = await discover(timeout= timeout)
|
||||||
|
|
||||||
#TODO: Add in wand filtering.
|
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))
|
||||||
|
|
||||||
# if isNewDev:
|
|
||||||
# # Perform initial detection attempt
|
|
||||||
# mode = 0
|
|
||||||
# found = 0
|
|
||||||
# name = device.getValueText(9)
|
|
||||||
# if self._name is not None:
|
|
||||||
# mode += 1
|
|
||||||
# if name == self._name:
|
|
||||||
# found += 1
|
|
||||||
# if self._prefix is not None:
|
|
||||||
# mode += 1
|
|
||||||
# if name is not None and name.startswith(self._prefix):
|
|
||||||
# found += 1
|
|
||||||
# if self._mac is not None:
|
|
||||||
# mode += 1
|
|
||||||
# if device.addr == self._mac:
|
|
||||||
# found += 1
|
|
||||||
#
|
|
||||||
# if found >= mode:
|
|
||||||
# self.wands.append(self.wand_class(device, debug=self.debug))
|
|
||||||
# elif self.debug:
|
|
||||||
# if name != "None":
|
|
||||||
# print("Mac: {}\tCommon Name: {}".format(device.addr, name))
|
|
||||||
# else:
|
|
||||||
# print("Mac: {}".format(device.addr))
|
|
||||||
print(devices)
|
|
||||||
devices = list(filter(lambda x : x.name.startswith("kano"), devices))
|
|
||||||
print(devices)
|
print(devices)
|
||||||
|
|
||||||
self.wands = [Wand(d.address, d.name) for d in devices]
|
self.wands = [Wand(d.address, d.name) for d in devices]
|
||||||
# for d in devices:
|
|
||||||
# #Convert to device making here.
|
|
||||||
# print(d)
|
|
||||||
# print(d.name, d.address)
|
|
||||||
print(self.wands)
|
print(self.wands)
|
||||||
|
|
||||||
#TODO: Process device list here for the shop - > not all BLE devices are necessary
|
|
||||||
# client = BleakClient(self.wand_address, loop=self.loop)
|
|
||||||
if connect:
|
if connect:
|
||||||
for wand in self.wands:
|
for wand in self.wands:
|
||||||
wand.connect()
|
await wand.connect()
|
||||||
return self.wands
|
return self.wands
|
||||||
|
|||||||
Reference in New Issue
Block a user