Skip to content

Commit

Permalink
fix: adapters now returns a list instead of a set since order matters (
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jul 24, 2022
1 parent d9bc2a3 commit b4f153b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/bluetooth_adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 5 additions & 5 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"]

0 comments on commit b4f153b

Please sign in to comment.