-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update oralb to show battery percentage (#85800)
Co-authored-by: J. Nick Koston <nick@koston.org> fixes undefined
- Loading branch information
Showing
9 changed files
with
162 additions
and
16 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,53 @@ | ||
"""OralB session fixtures.""" | ||
|
||
from unittest import mock | ||
|
||
import pytest | ||
|
||
|
||
class MockServices: | ||
"""Mock GATTServicesCollection.""" | ||
|
||
def get_characteristic(self, key: str) -> str: | ||
"""Mock GATTServicesCollection.get_characteristic.""" | ||
return key | ||
|
||
|
||
class MockBleakClient: | ||
"""Mock BleakClient.""" | ||
|
||
services = MockServices() | ||
|
||
def __init__(self, *args, **kwargs): | ||
"""Mock BleakClient.""" | ||
|
||
async def __aenter__(self, *args, **kwargs): | ||
"""Mock BleakClient.__aenter__.""" | ||
return self | ||
|
||
async def __aexit__(self, *args, **kwargs): | ||
"""Mock BleakClient.__aexit__.""" | ||
|
||
async def connect(self, *args, **kwargs): | ||
"""Mock BleakClient.connect.""" | ||
|
||
async def disconnect(self, *args, **kwargs): | ||
"""Mock BleakClient.disconnect.""" | ||
|
||
|
||
class MockBleakClientBattery49(MockBleakClient): | ||
"""Mock BleakClient that returns a battery level of 49.""" | ||
|
||
async def read_gatt_char(self, *args, **kwargs) -> bytes: | ||
"""Mock BleakClient.read_gatt_char.""" | ||
return b"\x31\x00" | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_bluetooth(enable_bluetooth): | ||
"""Auto mock bluetooth.""" | ||
|
||
with mock.patch( | ||
"oralb_ble.parser.BleakClientWithServiceCache", MockBleakClientBattery49 | ||
): | ||
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters