-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
97 additions
and
33 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from typing import Any | ||
from unittest.mock import ANY | ||
|
||
from bleak.backends.device import BLEDevice | ||
from bleak.backends.scanner import AdvertisementData | ||
|
||
from habluetooth import BaseHaRemoteScanner, BaseHaScanner, HaBluetoothConnector | ||
|
||
|
||
class MockBleakClient: | ||
pass | ||
|
||
|
||
def test_create_scanner(): | ||
connector = HaBluetoothConnector(MockBleakClient, "any", lambda: True) | ||
|
||
class MockScanner(BaseHaScanner): | ||
pass | ||
|
||
def discovered_devices_and_advertisement_data(self): | ||
return [] | ||
|
||
def discovered_devices(self): | ||
return [] | ||
|
||
scanner = MockScanner("any", "any", connector) | ||
assert isinstance(scanner, BaseHaScanner) | ||
|
||
|
||
def test_create_remote_scanner(): | ||
connector = HaBluetoothConnector(MockBleakClient, "any", lambda: True) | ||
|
||
def callback(data: Any) -> None: | ||
pass | ||
|
||
scanner = BaseHaRemoteScanner("any", "any", callback, connector, True) | ||
assert isinstance(scanner, BaseHaRemoteScanner) | ||
|
||
|
||
def test__async_on_advertisement(): | ||
connector = HaBluetoothConnector(MockBleakClient, "any", lambda: True) | ||
|
||
def callback(data: Any) -> None: | ||
pass | ||
|
||
scanner = BaseHaRemoteScanner("any", "any", callback, connector, True) | ||
details = scanner._details | {} | ||
scanner._async_on_advertisement( | ||
"AA:BB:CC:DD:EE:FF", | ||
-88, | ||
"name", | ||
["service_uuid"], | ||
{"service_uuid": b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"}, | ||
{32: b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"}, | ||
-88, | ||
details, | ||
1.0, | ||
) | ||
scanner._async_on_advertisement( | ||
"AA:BB:CC:DD:EE:FF", | ||
-21, | ||
"name", | ||
["service_uuid2"], | ||
{"service_uuid2": b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"}, | ||
{21: b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b"}, | ||
-88, | ||
details, | ||
1.0, | ||
) | ||
ble_device = BLEDevice( | ||
"AA:BB:CC:DD:EE:FF", | ||
"name", | ||
details, | ||
-21, | ||
) | ||
first_device = scanner.discovered_devices[0] | ||
assert first_device.address == ble_device.address | ||
assert first_device.details == ble_device.details | ||
assert first_device.name == ble_device.name | ||
assert first_device.rssi == ble_device.rssi | ||
assert "AA:BB:CC:DD:EE:FF" in scanner.discovered_devices_and_advertisement_data | ||
adv = scanner.discovered_devices_and_advertisement_data["AA:BB:CC:DD:EE:FF"][1] | ||
assert adv == AdvertisementData( | ||
local_name="name", | ||
manufacturer_data={ | ||
32: b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b", | ||
21: b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b", | ||
}, | ||
service_data={ | ||
"service_uuid": b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b", | ||
"service_uuid2": b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b", | ||
}, | ||
service_uuids=ANY, | ||
tx_power=-88, | ||
rssi=-21, | ||
platform_data=(), | ||
) |
This file was deleted.
Oops, something went wrong.