Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions bleak/backends/bluezdbus/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async def discover(timeout=5.0, loop=None, **kwargs):
loop = loop if loop else asyncio.get_event_loop()
cached_devices = {}
devices = {}
rules = list()

def parse_msg(message):
if message.member == "InterfacesAdded":
Expand Down Expand Up @@ -124,21 +125,21 @@ def parse_msg(message):
bus = await client.connect(reactor, "system").asFuture(loop)

# Add signal listeners
await bus.addMatch(
rules.append(await bus.addMatch(
parse_msg,
interface="org.freedesktop.DBus.ObjectManager",
member="InterfacesAdded",
).asFuture(loop)
await bus.addMatch(
).asFuture(loop))
rules.append(await bus.addMatch(
parse_msg,
interface="org.freedesktop.DBus.ObjectManager",
member="InterfacesRemoved",
).asFuture(loop)
await bus.addMatch(
).asFuture(loop))
rules.append(await bus.addMatch(
parse_msg,
interface="org.freedesktop.DBus.Properties",
member="PropertiesChanged",
).asFuture(loop)
).asFuture(loop))

# Find the HCI device to use for scanning and get cached device properties
objects = await bus.callRemote(
Expand Down Expand Up @@ -199,4 +200,8 @@ def parse_msg(message):
manufacturer_data = props.get('ManufacturerData', {})
discovered_devices.append(BLEDevice(address, name, {"path": path, "props": props}, uuids=uuids,
manufacturer_data=manufacturer_data))

for rule in rules:
await bus.delMatch(rule).asFuture(loop)

return discovered_devices