fix UUIDs on python3/macOS and added pyobjc requirements for macOS
This commit is contained in:
parent
15cec50a40
commit
efaa472f4c
3 changed files with 14 additions and 10 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -56,3 +56,5 @@ docs/_build/
|
|||
|
||||
# PyBuilder
|
||||
target/
|
||||
.mypy_cache/
|
||||
.ropeproject/
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
import uuid
|
||||
from binascii import hexlify
|
||||
|
||||
import objc
|
||||
|
||||
|
|
@ -33,15 +34,10 @@ objc.loadBundle("CoreBluetooth", globals(),
|
|||
def cbuuid_to_uuid(cbuuid):
|
||||
"""Convert Objective-C CBUUID type to native Python UUID type."""
|
||||
data = cbuuid.data().bytes()
|
||||
if len(data) == 2:
|
||||
# Short 16-bit UUID
|
||||
return uuid.UUID(bytes='\x00\x00{0}{1}\x00\x00\x10\x00\x80\x00\x00\x80\x5F\x9B\x34\xFB'.format(data[0], data[1]))
|
||||
elif len(data) == 4:
|
||||
# Short 32-bit UUID
|
||||
return uuid.UUID(bytes='{0}{1}{2}{3}\x00\x00\x10\x00\x80\x00\x00\x80\x5F\x9B\x34\xFB'.format(data[0], data[1], data[2], data[3]))
|
||||
else:
|
||||
# Full 128-bit UUID
|
||||
return uuid.UUID(bytes=data)
|
||||
|
||||
template = '{:0>8}-0000-1000-8000-00805f9b34fb' if len(data) <= 4 else '{:0>32}'
|
||||
value = template.format(hexlify(data.tobytes()[:16]).decode('ascii'))
|
||||
return uuid.UUID(hex=value)
|
||||
|
||||
|
||||
def uuid_to_cbuuid(uuid):
|
||||
|
|
|
|||
8
setup.py
8
setup.py
|
|
@ -1,6 +1,12 @@
|
|||
from ez_setup import use_setuptools
|
||||
use_setuptools()
|
||||
from setuptools import setup, find_packages
|
||||
import platform
|
||||
|
||||
platform_install_requires = []
|
||||
|
||||
if platform.system() == 'Darwin':
|
||||
platform_install_requires += ['pyobjc-framework-CoreBluetooth']
|
||||
|
||||
setup(name = 'Adafruit_BluefruitLE',
|
||||
version = '0.9.9',
|
||||
|
|
@ -9,5 +15,5 @@ setup(name = 'Adafruit_BluefruitLE',
|
|||
description = 'Python library for interacting with Bluefruit LE (Bluetooth low energy) devices on Linux or OSX.',
|
||||
license = 'MIT',
|
||||
url = 'https://github.com/adafruit/Adafruit_Python_BluefruitLE/',
|
||||
install_requires = ['future',],
|
||||
install_requires = ['future'] + platform_install_requires,
|
||||
packages = find_packages())
|
||||
|
|
|
|||
Loading…
Reference in a new issue