Exemplo n.º 1
0
 def test_should_add_connection_handle_on_central_connected(self):
     connect_data = (124, 'A_type', 'address')
     service = BatteryService(self.mockBLE)
     self.assertEqual(service.connected_centrals(), 0)
     # triggering 'private' method !!
     service._irq_handler(_IRQ_CENTRAL_CONNECT, connect_data)
     self.assertEqual(service.connected_centrals(), 1)
Exemplo n.º 2
0
 def test_should_notify_connect_centrals_on_battery_level_change(self):
     self.mockBLE.when('gatts_read', (MOCK_BATTERY_LEVEL_HANDLE, ),
                       return_value=b'\x0A')
     connect_data = (124, 'A_type', 'address')
     service = BatteryService(self.mockBLE)
     service.register_services()
     service.start()
     self.assertFalse(self.mockBLE.has_been_called(method='gatts_notify'))
     # triggering 'private' method !!
     service._irq_handler(_IRQ_CENTRAL_CONNECT, connect_data)
     service.set_battery_level_percentage(23)
     self.assertTrue(
         self.mockBLE.has_been_called(method='gatts_notify', times=1))
Exemplo n.º 3
0
 def test_should_restart_advertising_after_connect(self):
     connect_data = (124, 'A_type', 'address')
     service = BatteryService(self.mockBLE)
     # testing 'private' method !!
     self.assertTrue(self.mockBLE.has_been_called(method='irq', times=1))
     service._irq_handler(_IRQ_CENTRAL_CONNECT, connect_data)
     self.assertTrue(
         self.mockBLE.has_been_called_with(
             'gap_advertise', {
                 'interval_us': 500000,
                 'adv_data': _create_expected_advertising_payload()
             },
             times=1))