diff --git a/pylgbst/__init__.py b/pylgbst/__init__.py index c996337..66b7ddb 100644 --- a/pylgbst/__init__.py +++ b/pylgbst/__init__.py @@ -32,9 +32,9 @@ class MoveHub(object): self.connection.set_notify_handler(self._notify) self.connection.write(ENABLE_NOTIFICATIONS_HANDLE, ENABLE_NOTIFICATIONS_VALUE) - # while not self.notified: - # log.debug("Waiting to be notified") - # time.sleep(1) + while not self.devices: + log.debug("Waiting to be notified about devices...") + time.sleep(0.1) self.port_C = None self.port_D = None diff --git a/test.py b/test.py index d0b5d79..32ee18f 100644 --- a/test.py +++ b/test.py @@ -53,6 +53,7 @@ class ConnectionMock(Connection): class GeneralTest(unittest.TestCase): def test_led(self): conn = ConnectionMock() + conn.notifications.append((14, '1b0e00 0900 04 39 0227003738')) hub = MoveHub(conn) led = LED(hub, PORT_LED) led.set_color(COLOR_RED) @@ -60,6 +61,7 @@ class GeneralTest(unittest.TestCase): def test_motor(self): conn = ConnectionMock() + conn.notifications.append((14, '1b0e00 0900 04 39 0227003738')) hub = MoveHub(conn) motor = EncodedMotor(hub, PORT_AB) motor.timed(1.5) @@ -69,8 +71,6 @@ class GeneralTest(unittest.TestCase): def test_capabilities(self): conn = ConnectionMock() - hub = MoveHub(conn) - time.sleep(1) conn.notifications.append((14, '1b0e00 0f00 04 01 0125000000001000000010')) conn.notifications.append((14, '1b0e00 0f00 04 02 0126000000001000000010')) conn.notifications.append((14, '1b0e00 0f00 04 37 0127000100000001000000')) @@ -82,7 +82,8 @@ class GeneralTest(unittest.TestCase): conn.notifications.append((14, '1b0e00 0f00 04 3c 0114000200000002000000')) conn.notifications.append((14, '1b0e00 0f00 8202 01')) conn.notifications.append((14, '1b0e00 0f00 8202 0a')) - time.sleep(1) + + hub = MoveHub(conn) # demo_all(hub) conn.running = False