1
0
mirror of https://github.com/undera/pylgbst.git synced 2020-11-18 19:37:26 -08:00

Added test and fix for device matching (#46)

* Added test for device matching

Mocking the scanning and testing the connect() of each backend would be
better, but that requires more refactoring with prior agreement.
Added unittest2 dependency for subTest support, other solutions are
available.

* Fixed matching for Move Hub

If other BLE devices are around, an exception occurs on hub_mac.lower() if
default hub_mac (None) is used.

* fixup! Added test for device matching

Removed unittest2 dependency and features
This commit is contained in:
MDE 2020-01-29 07:33:53 +01:00 committed by GitHub
parent 9e4fab4aae
commit dff312534f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 3 deletions

View File

@ -48,11 +48,18 @@ class Connection(object):
def _is_device_matched(self, address, name, hub_mac):
log.debug("Checking device name: %s, MAC: %s", name, address)
matched = False
if address != "00:00:00:00:00:00":
if (not hub_mac and name == LEGO_MOVE_HUB) or hub_mac.lower() == address.lower():
if hub_mac:
if hub_mac.lower() == address.lower():
matched = True
elif name == LEGO_MOVE_HUB:
matched = True
if matched:
log.info("Found %s at %s", name, address)
return True
return False
return matched
class DebugServer(object):

38
tests/test_comms.py Normal file
View File

@ -0,0 +1,38 @@
import unittest
from pylgbst.comms import *
class ConnectionTestCase(unittest.TestCase):
def test_is_device_matched(self):
conn = Connection()
hub_address = '1a:2A:3A:4A:5A:6A'
other_address = 'A1:a2:a3:a4:a5:a6'
zero_address = '00:00:00:00:00:00'
hub_name = LEGO_MOVE_HUB
other_name = 'HRM'
test_matrix = [
# address, name, hub_mac, expected
(hub_address, hub_name, hub_address, True),
(hub_address, hub_name, None, True),
(hub_address, None, hub_address, True),
(hub_address, None, None, False),
(hub_address, other_name, hub_address, True),
(hub_address, other_name, None, False),
(other_address, hub_name, hub_address, False),
(other_address, hub_name, None, True),
(other_address, None, hub_address, False),
(other_address, None, None, False),
(other_address, other_name, hub_address, False),
(other_address, other_name, None, False),
(zero_address, hub_name, hub_address, False),
(zero_address, hub_name, None, False),
(zero_address, None, hub_address, False),
(zero_address, None, None, False),
(zero_address, other_name, hub_address, False),
(zero_address, other_name, None, False),
]
for address, name, hub_mac, expected in test_matrix:
self.assertEqual(conn._is_device_matched(address=address, name=name, hub_mac=hub_mac), expected)