Skip to content

Commit

Permalink
Handle device name char separately.
Browse files Browse the repository at this point in the history
Fixes part of hbldh#104.
  • Loading branch information
hbldh committed Sep 7, 2019
1 parent 749f27c commit 4b9b93c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* bleak version:
* Python version:
* Operating System:
* BlueZ version (`bluetoothctl -v`) in case of Linux:

### Description

Expand Down
15 changes: 15 additions & 0 deletions bleak/backends/bluezdbus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ async def read_gatt_char(self, _uuid: str, **kwargs) -> bytearray:
)
)
return value
if _uuid == '00002a00-0000-1000-8000-00805f9b34fb' and (
self._bluez_version[0] == 5 and self._bluez_version[1] >= 48
):
props = await self._get_device_properties(
interface=defs.DEVICE_INTERFACE
)
# Simulate regular characteristics read to be consistent over all platforms.
value = bytearray(props.get("Name", "").encode('ascii'))
logger.debug(
"Read Device Name {0} | {1}: {2}".format(
_uuid, self._device_path, value
)
)
return value

raise BleakError(
"Characteristic with UUID {0} could not be found!".format(_uuid)
)
Expand Down
18 changes: 12 additions & 6 deletions examples/sensortag.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
MODEL_NBR_UUID = "0000{0:x}-0000-1000-8000-00805f9b34fb".format(
uuid16_dict.get("Model Number String")
)
DEVICE_NAME_UUID = "0000{0:x}-0000-1000-8000-00805f9b34fb".format(
uuid16_dict.get("Device Name")
)
FIRMWARE_REV_UUID = "0000{0:x}-0000-1000-8000-00805f9b34fb".format(
uuid16_dict.get("Firmware Revision String")
)
Expand All @@ -94,12 +97,12 @@ async def run(address, loop, debug=False):
if debug:
import sys

loop.set_debug(True)
l = logging.getLogger("asyncio")
l.setLevel(logging.DEBUG)
h = logging.StreamHandler(sys.stdout)
h.setLevel(logging.DEBUG)
l.addHandler(h)
# loop.set_debug(True)
# l = logging.getLogger("asyncio")
# l.setLevel(logging.DEBUG)
# h = logging.StreamHandler(sys.stdout)
# h.setLevel(logging.DEBUG)
# l.addHandler(h)

async with BleakClient(address, loop=loop) as client:
x = await client.is_connected()
Expand All @@ -115,6 +118,9 @@ async def run(address, loop, debug=False):
model_number = await client.read_gatt_char(MODEL_NBR_UUID)
print("Model Number: {0}".format("".join(map(chr, model_number))))

device_name = await client.read_gatt_char(DEVICE_NAME_UUID)
print("Device Name: {0}".format("".join(map(chr, device_name))))

manufacturer_name = await client.read_gatt_char(MANUFACTURER_NAME_UUID)
print("Manufacturer Name: {0}".format("".join(map(chr, manufacturer_name))))

Expand Down

0 comments on commit 4b9b93c

Please sign in to comment.