kevincar / bless

Cross-platform Bluetooth Low Energy Server Python Library
MIT License
86 stars 28 forks source link

Service and Characteristic Handles #29

Closed kevincar closed 3 years ago

kevincar commented 3 years ago

The problem

self = <bleak.backends.corebluetooth.service.BleakGATTServiceCoreBluetooth object at 0x7fade9a57460>
obj = <CBMutableService: 0x7fade91507c0 Primary = YES, UUID = A438A1A6-47C0-4FD1-88BE-4531A1BAB891, Included Services = (null), Characteristics = (null)>

    def __init__(self, obj: CBService):
        super().__init__(obj)
        self.__characteristics = []
        # N.B. the `startHandle` method of the CBService is an undocumented Core Bluetooth feature,
        # which Bleak takes advantage of in order to have a service handle to use.
>       self.__handle = int(self.obj.startHandle())
E       TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

/usr/local/anaconda3/envs/bless_test/lib/python3.8/site-packages/bleak/backends/corebluetooth/service.py:20: TypeError

This behavior is a result of this recent bleak pull request. It seems that when a new CBService is initialized before setting the server in motion that the service does not yet own a handle

Reproduction

TEST_HARDWARE=True python -m pytest -s -k server

Desktop

Proposed Solution

Create a BlessGATTServiceCoreBluetooth rather than bleak. This will allow us to get the service created, and potentially handle "handles" later.

kevincar commented 3 years ago

This is also occurring on Windows

  File "C:\tools\miniconda3\envs\bless\lib\site-packages\bleak\backends\dotnet\characteristic.py", line 70, in handle
    return int(self.obj.AttributeHandle)
AttributeError: 'GattLocalCharacteristic' object has no attribute 'AttributeHandle'
kevincar commented 3 years ago

Closing with #30