def test_read_battery(self): """Test reading the battery level.""" poller = MiTempBtPoller(self.TEST_MAC, MockBackend) backend = self._get_backend(poller) backend.battery_level = 50 self.assertEqual(50, poller.battery_level()) self.assertEqual(50, poller.parameter_value(MI_BATTERY)) self.assertEqual(0, len(backend.written_handles))
def get_battery(mac): poller = MiTempBtPoller(mac, BluepyBackend) for _ in range(100): try: return poller.battery_level() except BluetoothBackendException: continue return 0