kevincar / bless

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

NSConcreteMutableData being sent instead of bytes #71

Closed beachcitiessoftware closed 2 years ago

beachcitiessoftware commented 2 years ago

The problem

I've created a basic GattServer on Mac, and instead of receiving bytes, or bytearray in the write_request_func.

Reproduction

    def _write(self, characteristic: BlessGATTCharacteristic, value: Any, **kwargs):
        characteristic.value = value
        if isinstance(value, bytearray) or isinstance(value, bytes):
            logger.debug(f'Char. {characteristic.uuid}, value set to: {value.hex().upper()}')  #  This never hits

Expected behavior

It would be preferable to receive a device agnostic value, or at least provide a way to get from NSConcreteMutableData to bytes

Desktop (please complete the following information):

beachcitiessoftware commented 2 years ago

n/m value.str() has the desired effect.

kevincar commented 2 years ago

Thanks for this. I think this is helpful to know since it still may be worth while to add some checks to still validate os agnostic values here. Will look into this.