From afd84dbfc8082e0018fc6737af1c140c4fb25d3d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 24 Jul 2022 18:01:37 -0500 Subject: [PATCH] fix: adapters now returns a list instead of a set since order matters --- src/bluetooth_adapters/__init__.py | 8 +++++--- tests/test_init.py | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/bluetooth_adapters/__init__.py b/src/bluetooth_adapters/__init__.py index 6d56ea0..0b924da 100644 --- a/src/bluetooth_adapters/__init__.py +++ b/src/bluetooth_adapters/__init__.py @@ -10,9 +10,9 @@ _LOGGER = logging.getLogger(__name__) -async def get_bluetooth_adapters() -> set[str]: +async def get_bluetooth_adapters() -> list[str]: """Return a list of bluetooth adapters.""" - adapters: set[str] = set() + adapters: list[str] = [] try: bus = await MessageBus( bus_type=BusType.SYSTEM, negotiate_unix_fd=True @@ -35,5 +35,7 @@ async def get_bluetooth_adapters() -> set[str]: path_str = str(path) if path_str.startswith("/org/bluez/hci"): split_path = path_str.split("/") - adapters.add(split_path[3]) + adapter = split_path[3] + if adapter not in adapters: + adapters.append(adapter) return adapters diff --git a/tests/test_init.py b/tests/test_init.py index b0a2be5..a138671 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -15,7 +15,7 @@ def __init__(self, *args, **kwargs): raise FileNotFoundError with patch("bluetooth_adapters.MessageBus", MockMessageBus): - assert await get_bluetooth_adapters() == set() + assert await get_bluetooth_adapters() == [] @pytest.mark.asyncio @@ -31,7 +31,7 @@ async def call(self): return None with patch("bluetooth_adapters.MessageBus", MockMessageBus): - assert await get_bluetooth_adapters() == set() + assert await get_bluetooth_adapters() == [] @pytest.mark.asyncio @@ -47,7 +47,7 @@ async def call(self): return None with patch("bluetooth_adapters.MessageBus", MockMessageBus): - assert await get_bluetooth_adapters() == set() + assert await get_bluetooth_adapters() == [] @pytest.mark.asyncio @@ -74,7 +74,7 @@ async def connect(self): ) with patch("bluetooth_adapters.MessageBus", MockMessageBus): - assert await get_bluetooth_adapters() == set() + assert await get_bluetooth_adapters() == [] @pytest.mark.asyncio @@ -102,4 +102,4 @@ async def connect(self): ) with patch("bluetooth_adapters.MessageBus", MockMessageBus): - assert await get_bluetooth_adapters() == {"hci0", "hci1"} + assert await get_bluetooth_adapters() == ["hci0", "hci1"]