def test_hub_alerts(self): conn = ConnectionMock().connect() hub = Hub(conn) conn.notification_delayed('0600 03 0104ff', 0.1) hub.send(MsgHubAlert(MsgHubAlert.LOW_VOLTAGE, MsgHubAlert.UPD_REQUEST)) conn.notification_delayed('0600 03 030400', 0.1) hub.send(MsgHubAlert(MsgHubAlert.LOW_SIGNAL, MsgHubAlert.UPD_REQUEST)) conn.wait_notifications_handled()
def test_hub_actions(self): conn = ConnectionMock().connect() hub = Hub(conn) conn.notification_delayed('04000230', 0.1) hub.send(MsgHubAction(MsgHubAction.UPSTREAM_SHUTDOWN)) conn.notification_delayed('04000231', 0.1) hub.send(MsgHubAction(MsgHubAction.UPSTREAM_DISCONNECT)) conn.notification_delayed('04000232', 0.1) hub.send(MsgHubAction(MsgHubAction.UPSTREAM_BOOT_MODE)) time.sleep(0.1) conn.wait_notifications_handled()
def test_device_attached(self): conn = ConnectionMock().connect() hub = Hub(conn) # regular startup attaches conn.notifications.append('0f0004010126000000001000000010') conn.notifications.append('0f0004020125000000001000000010') # detach and reattach conn.notifications.append('0500040100') conn.notifications.append('0500040200') conn.notifications.append('0f0004010126000000001000000010') conn.notifications.append('0f0004020125000000001000000010') del hub conn.wait_notifications_handled()
def test_hub_properties(self): conn = ConnectionMock().connect() hub = Hub(conn) conn.notification_delayed('060001060600', 0.1) msg = MsgHubProperties(MsgHubProperties.VOLTAGE_PERC, MsgHubProperties.UPD_REQUEST) resp = hub.send(msg) assert isinstance(resp, MsgHubProperties) self.assertEqual(1, len(resp.parameters)) self.assertEqual(0, usbyte(resp.parameters, 0)) conn.notification_delayed('12000101064c45474f204d6f766520487562', 0.1) msg = MsgHubProperties(MsgHubProperties.ADVERTISE_NAME, MsgHubProperties.UPD_REQUEST) resp = hub.send(msg) assert isinstance(resp, MsgHubProperties) self.assertEqual(b"LEGO Move Hub", resp.parameters) conn.wait_notifications_handled()
def test_capabilities(self): conn = ConnectionMock() conn.notifications.append('0f00 04 01 0125000000001000000010') conn.notifications.append('0f00 04 02 0126000000001000000010') conn.notifications.append('0f00 04 37 0127000100000001000000') conn.notifications.append('0f00 04 38 0127000100000001000000') conn.notifications.append('0900 04 39 0227003738') conn.notifications.append('0f00 04 32 0117000100000001000000') conn.notifications.append('0f00 04 3a 0128000000000100000001') conn.notifications.append('0f00 04 3b 0115000200000002000000') conn.notifications.append('0f00 04 3c 0114000200000002000000') conn.notification_delayed('12000101064c45474f204d6f766520487562', 0.1) conn.notification_delayed('0b00010d06001653a0d1d4', 0.3) conn.notification_delayed('060001060600', 0.5) conn.notification_delayed('0600030104ff', 0.7) MoveHub(conn.connect()) time.sleep(1) conn.wait_notifications_handled() self.assertEqual(b"0500010105", conn.writes[1][1]) self.assertEqual(b"0500010d05", conn.writes[2][1]) self.assertEqual(b"0500010605", conn.writes[3][1]) self.assertEqual(b"0500030103", conn.writes[4][1])
def test_error(self): conn = ConnectionMock().connect() hub = Hub(conn) conn.notification_delayed("0500056105", 0.1) time.sleep(0.2) conn.wait_notifications_handled()