Skip to content

Commit

Permalink
Final modifications for #3 before 0.5.0 release.
Browse files Browse the repository at this point in the history
Implemented new method stumps (due to abstract methods) from #86 in macOS and Windows backends as well.
Modified example files to show how Core Bluetooth backend handles addresses.
Removed corebleak.py, since I do not think it is needed any more either.
  • Loading branch information
hbldh committed Aug 2, 2019
1 parent 5072ab6 commit b16d7c3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 18 deletions.
13 changes: 13 additions & 0 deletions bleak/backends/corebluetooth/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ async def is_connected(self) -> bool:
"""Checks for current active connection"""
return cbapp.central_manager_delegate.isConnected

def set_disconnected_callback(
self, callback: Callable[[BaseBleakClient], None], **kwargs
) -> None:
"""Set the disconnected callback.
N.B. This is not implemented in the Core Bluetooth backend yet.
Args:
callback: callback to be called on disconnection.
"""
raise NotImplementedError("This is not implemented in the Core Bluetooth backend yet")

async def get_services(self) -> BleakGATTServiceCollection:
"""Get all services registered for this GATT server.
Expand Down
14 changes: 0 additions & 14 deletions bleak/backends/corebluetooth/corebleak.py

This file was deleted.

13 changes: 13 additions & 0 deletions bleak/backends/dotnet/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@ async def is_connected(self) -> bool:
else:
return False

def set_disconnected_callback(
self, callback: Callable[[BaseBleakClient], None], **kwargs
) -> None:
"""Set the disconnected callback.
N.B. This is not implemented in the .NET backend yet.
Args:
callback: callback to be called on disconnection.
"""
raise NotImplementedError("This is not implemented in the .NET backend yet")

# GATT services methods

async def get_services(self) -> BleakGATTServiceCollection:
Expand Down
7 changes: 6 additions & 1 deletion examples/enable_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import logging
import asyncio
import platform

from bleak import BleakClient
from bleak import _logger as logger
Expand Down Expand Up @@ -51,6 +52,10 @@ async def run(address, loop, debug=False):
import os

os.environ["PYTHONASYNCIODEBUG"] = str(1)
address = "24:71:89:cc:09:05" # <--- Change to your device's address
address = (
"24:71:89:cc:09:05" # <--- Change to your device's address here if you are using Windows or Linux
if platform.system() != "Darwin"
else "243E23AE-4A99-406C-B317-18F1BD7B4CBE" # <--- Change to your device's address here if you are using macOS
)
loop = asyncio.get_event_loop()
loop.run_until_complete(run(address, loop, True))
7 changes: 6 additions & 1 deletion examples/get_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import asyncio
import platform

from bleak import BleakClient

Expand All @@ -19,6 +20,10 @@ async def print_services(mac_addr: str, loop: asyncio.AbstractEventLoop):
print("Services:", svcs)


mac_addr = "ff:50:35:82:3b:5a"
mac_addr = (
"24:71:89:cc:09:05"
if platform.system() != "Darwin"
else "243E23AE-4A99-406C-B317-18F1BD7B4CBE"
)
loop = asyncio.get_event_loop()
loop.run_until_complete(print_services(mac_addr, loop))
2 changes: 1 addition & 1 deletion examples/sensortag.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def run(address, loop, debug=False):
if debug:
import sys

# loop.set_debug(True)
loop.set_debug(True)
l = logging.getLogger("asyncio")
l.setLevel(logging.DEBUG)
h = logging.StreamHandler(sys.stdout)
Expand Down
2 changes: 1 addition & 1 deletion examples/service_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def run(address, loop, debug=False):
if debug:
import sys

# loop.set_debug(True)
loop.set_debug(True)
log.setLevel(logging.DEBUG)
h = logging.StreamHandler(sys.stdout)
h.setLevel(logging.DEBUG)
Expand Down

0 comments on commit b16d7c3

Please sign in to comment.