diff --git a/.gitignore b/.gitignore index 862d4b5..c842a47 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,5 @@ docs/_build/ # PyBuilder target/ +.mypy_cache/ +.ropeproject/ diff --git a/Adafruit_BluefruitLE/corebluetooth/objc_helpers.py b/Adafruit_BluefruitLE/corebluetooth/objc_helpers.py index 58da582..a84d20a 100644 --- a/Adafruit_BluefruitLE/corebluetooth/objc_helpers.py +++ b/Adafruit_BluefruitLE/corebluetooth/objc_helpers.py @@ -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): diff --git a/setup.py b/setup.py index be3f499..99cd118 100644 --- a/setup.py +++ b/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())