Skip to content

Commit

Permalink
Version 0.2.4
Browse files Browse the repository at this point in the history
Fixes #52 and #51.
  • Loading branch information
hbldh committed Nov 30, 2018
2 parents fd58155 + 2409980 commit ad3b886
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
9 changes: 8 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
History
=======

0.2.4 (2018-11-30)
------------------

* Fix for issue #52: Timing issue getting characteristics
* Additional fix for issue #51.
* Bugfix for string method for BLEDevice.

0.2.3 (2018-11-28)
------------------

* Fix for issue #51: ``dpkg-query not found on all Linux systems```
* Fix for issue #51: ``dpkg-query not found on all Linux systems``

0.2.2 (2018-11-08)
------------------
Expand Down
2 changes: 1 addition & 1 deletion bleak/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# stdout=subprocess.PIPE)
p = subprocess.Popen(["bluetoothctl", "--version"], stdout=subprocess.PIPE)
out, _ = p.communicate()
s = re.search(b"^(\d+).(\d+)", out.strip(b"'"))
s = re.search(b"(\d+).(\d+)", out.strip(b"'"))
if not s:
raise BleakError("Could not determine BlueZ version: {0}".format(out))

Expand Down
2 changes: 1 addition & 1 deletion bleak/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = "0.2.3"
__version__ = "0.2.4"
20 changes: 11 additions & 9 deletions bleak/backends/bluezdbus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def _services_resolved_callback(message):

# Get all services. This means making the actual connection.
await self.get_services()
# Sleep to ensure `_services_resolved` is set.
properties = await self._get_device_properties()
if not properties.get("Connected"):
raise BleakError("Connection failed!")
Expand Down Expand Up @@ -148,6 +147,16 @@ async def get_services(self) -> dict:
service object's properties as values.
"""
if self.services:
return self.services

while True:
properties = await self._get_device_properties()
services_resolved = properties.get("ServicesResolved", False)
if services_resolved:
break
await asyncio.sleep(0.02, loop=self.loop)

logger.debug("Get Services...")
objs = await get_managed_objects(
self._bus, self.loop, self._device_path + "/service"
Expand All @@ -171,14 +180,7 @@ async def get_services(self) -> dict:
self._descriptors[desc.get("UUID")] = desc
self._descriptors[desc.get("UUID")]["Path"] = object_path

await asyncio.sleep(0.01, loop=self.loop)

properties = await self._get_device_properties()
services_resolved = properties.get("ServicesResolved", False)

if self._services_resolved and not services_resolved:
raise BleakError("Services had not been resolved yet!")

self._services_resolved = True
return self.services

# IO methods
Expand Down
2 changes: 1 addition & 1 deletion bleak/backends/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def __init__(self, address, name, details=None):
self.details = details

def __str__(self):
return "{0}: {0}".format(self.address, self.name)
return "{0}: {1}".format(self.address, self.name)
17 changes: 17 additions & 0 deletions examples/get_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import asyncio

from bleak import BleakClient


async def print_services(mac_addr : str, loop : asyncio.AbstractEventLoop):
async with BleakClient(mac_addr, loop=loop) as client:
svcs = await client.get_services()
print("Services:", svcs)


mac_addr = "ff:50:35:82:3b:5a"
loop = asyncio.get_event_loop()
loop.run_until_complete(print_services(mac_addr, loop))



0 comments on commit ad3b886

Please sign in to comment.