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

Add python's native support for bluetooth sockets #53

Conversation

sergioisidoro
Copy link
Contributor

@sergioisidoro sergioisidoro commented Dec 22, 2019

Python 3 has native support for bluetooth sockets, with socket family AF_BLUETOOTH

However, it only has support for it if built with bluetooth.h in the dependencies

Before:

Python 3.7.6 (default, Dec 20 2019, 22:36:14) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from socket import AF_BLUETOOTH"
  File "<stdin>", line 1
    from socket import AF_BLUETOOTH"
                                   ^
SyntaxError: EOL while scanning string literal
>>> from socket import AF_BLUETOOTH
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'AF_BLUETOOTH' from 'socket' (/usr/local/lib/python3.7/socket.py)

Expected after:

Python 3.7.6 (default, Dec 21 2019, 23:33:58) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from socket import AF_BLUETOOTH
>>> AF_BLUETOOTH
<AddressFamily.AF_BLUETOOTH: 31>
>>> 

⚠️ This assumes the python images are only built in an alpine environment

For Ubuntu / Debian environment, the lib to install before building python is libbluetooth-dev

@pvizeli pvizeli merged commit 92e0128 into home-assistant:master Dec 24, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants