From 42fb838500b568c71616f118958c31fdcad46890 Mon Sep 17 00:00:00 2001 From: kevincar Date: Mon, 17 May 2021 12:09:03 -0400 Subject: [PATCH] BlueZ nee to send data off as a list of ints not a byte array Addresses #41 --- bless/backends/bluezdbus/characteristic.py | 2 +- bless/backends/bluezdbus/server.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bless/backends/bluezdbus/characteristic.py b/bless/backends/bluezdbus/characteristic.py index 3f9cfad..5be5b1b 100644 --- a/bless/backends/bluezdbus/characteristic.py +++ b/bless/backends/bluezdbus/characteristic.py @@ -78,7 +78,7 @@ async def init(self, service: "BlessGATTServiceBlueZDBus"): @property def value(self) -> bytearray: """Get the value of the characteristic""" - return self._value + return bytearray(self._value) @value.setter def value(self, val: bytearray): diff --git a/bless/backends/bluezdbus/server.py b/bless/backends/bluezdbus/server.py index 4dc0cf1..c408687 100644 --- a/bless/backends/bluezdbus/server.py +++ b/bless/backends/bluezdbus/server.py @@ -2,7 +2,7 @@ from uuid import UUID -from typing import Optional, Dict, Any, cast +from typing import Optional, Dict, Any, cast, List from asyncio import AbstractEventLoop from twisted.internet.asyncioreactor import AsyncioSelectorReactor # type: ignore @@ -223,12 +223,14 @@ def update_value(self, service_uuid: str, char_uuid: str) -> bool: characteristic.value = cur_value return True - def read(self, char: BlueZGattCharacteristic) -> bytearray: + def read(self, char: BlueZGattCharacteristic) -> List[int]: """ Read request. This re-routes the the request incomming on the dbus to the server to be re-routed to the user defined handler + Note: the BlueZ App handles the data as a list of ints + Parameters ---------- char : BlueZGattCharacteristic @@ -236,10 +238,10 @@ def read(self, char: BlueZGattCharacteristic) -> bytearray: Returns ------- - bytearray + List[int] The value of the characteristic """ - return self.read_request(char.uuid) + return list(self.read_request(char.uuid)) def write(self, char: BlueZGattCharacteristic, value: bytearray): """