Skip to content

Commit

Permalink
feat: expose load_history_from_managed_objects (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Dec 5, 2022
1 parent bcadadd commit 823daa8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/bluetooth_adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
get_bluetooth_adapters,
get_dbus_managed_objects,
)
from .history import AdvertisementHistory
from .history import AdvertisementHistory, load_history_from_managed_objects
from .models import (
ADAPTER_ADDRESS,
ADAPTER_HW_VERSION,
Expand All @@ -40,6 +40,7 @@
"get_bluetooth_adapter_details",
"get_dbus_managed_objects",
"get_adapters",
"load_history_from_managed_objects",
"AdapterDetails",
"ADAPTER_ADDRESS",
"ADAPTER_SW_VERSION",
Expand Down
6 changes: 5 additions & 1 deletion src/bluetooth_adapters/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AdvertisementHistory:


def load_history_from_managed_objects(
managed_objects: dict[str, Any]
managed_objects: dict[str, Any], source_adapter: str | None = None
) -> dict[str, AdvertisementHistory]:
"""Load the history from the bus."""
history: dict[str, AdvertisementHistory] = {}
Expand All @@ -38,6 +38,10 @@ def load_history_from_managed_objects(

split_path = path_str.split("/")
adapter = split_path[3]

if source_adapter and adapter != source_adapter:
continue

uuids = props.get("UUIDs", [])
manufacturer_data = {
k: bytes(v) for k, v in props.get("ManufacturerData", {}).items()
Expand Down
9 changes: 9 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
get_adapters,
get_bluetooth_adapters,
get_dbus_managed_objects,
load_history_from_managed_objects,
)


Expand Down Expand Up @@ -359,6 +360,14 @@ async def connect(self):
"54:D2:72:AB:35:95": AdvertisementHistory(ANY, ANY, "hci0")
}
assert bluez.history["54:D2:72:AB:35:95"].device.rssi == -78
assert (
len(
load_history_from_managed_objects(
bluez.unpacked_managed_objects, "hci1"
)
)
== 1
)


@pytest.mark.asyncio
Expand Down

0 comments on commit 823daa8

Please sign in to comment.