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

bluetooth.py: handle discover_devices returning bytes (instead of str) #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions nxt/backend/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def find(self, host=None, name=None, **kwargs):
else:
devhost, devname = dev, None
if (host is None or devhost == host) and (name is None or devname == name):
if type(devhost) is bytes:
devhost = devhost.decode('utf8')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be done earlier, so that it can be compared with host in the if condition.

sock = BluetoothSock(self._bluetooth, devhost)
try:
brick = sock.connect()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_backend_bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_bluetooth(mbluetooth, mbluetooth_import, msock):
backend = nxt.backend.bluetooth.get_backend()
# Find brick.
mbluetooth.discover_devices.return_value = [
"00:01:02:03:04:05",
b"00:01:02:03:04:05",
]
bricks = list(backend.find(blah="blah"))
assert len(bricks) == 1
Expand Down