Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adapters now returns a list instead of a set since order matters #5

Merged
merged 1 commit into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]