Skip to content

Commit

Permalink
Merge pull request #82 from kevincar/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
kevincar authored Jun 6, 2022
2 parents 81044dd + c886b0f commit 7611b56
Show file tree
Hide file tree
Showing 23 changed files with 567 additions and 532 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- ubuntu-latest
- windows-latest
- macos-latest
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -48,6 +48,8 @@ jobs:
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --statistic --max-line-length 88
- name: Check mypy
# Hold off on windows. Mypy is not being consistant there
if: runner.os != 'Windows'
run: |
mypy bless
- name: Test with pytest
Expand Down
16 changes: 16 additions & 0 deletions bless/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,28 @@
BlessServerCoreBluetooth as BlessServer,
)

# Service
from bless.backends.corebluetooth.service import ( # noqa: F401
BlessGATTServiceCoreBluetooth as BlessGATTService
)

# Characteristic Classes
from bless.backends.corebluetooth.characteristic import ( # noqa: F401
BlessGATTCharacteristicCoreBluetooth as BlessGATTCharacteristic,
)

elif sys.platform == "linux":

# Server
from bless.backends.bluezdbus.server import ( # noqa: F401
BlessServerBlueZDBus as BlessServer,
)

# Service
from bless.backends.bluezdbus.service import ( # noqa: F401
BlessGATTServiceBlueZDBus as BlessGATTService
)

# Characteristic Classes
from bless.backends.bluezdbus.characteristic import ( # noqa: F401
BlessGATTCharacteristicBlueZDBus as BlessGATTCharacteristic,
Expand All @@ -31,6 +42,11 @@
BlessServerWinRT as BlessServer,
)

# Service
from bless.backends.winrt.service import ( # noqa: F401
BlessGATTServiceWinRT as BlessGATTService
)

# Characteristic Classes
from bless.backends.winrt.characteristic import ( # noqa: F401
BlessGATTCharacteristicWinRT as BlessGATTCharacteristic,
Expand Down
7 changes: 6 additions & 1 deletion bless/backends/bluezdbus/characteristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def init(self, service: "BlessGATTServiceBlueZDBus"):

# Add to our BlueZDBus app
gatt_char: BlueZGattCharacteristic = await service.gatt.add_characteristic(
self._uuid, flags, self.value
self._uuid, flags, bytes(self.value)
)
dict_obj: Dict = await gatt_char.get_obj()

Expand All @@ -85,6 +85,11 @@ def value(self, val: bytearray):
"""Set the value of the characteristic"""
self._value = val

@property
def uuid(self) -> str:
"""The uuid of this characteristic"""
return self.obj.get("UUID").value


def flags_to_dbus(flags: GATTCharacteristicProperties) -> List[Flags]:
"""
Expand Down
89 changes: 58 additions & 31 deletions bless/backends/bluezdbus/dbus/advertisement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from typing import List, Dict, TYPE_CHECKING

from txdbus.objects import DBusObject, DBusProperty, dbusMethod # type: ignore
from txdbus.interface import DBusInterface, Method, Property # type: ignore
from dbus_next.service import ServiceInterface, method, dbus_property # type: ignore

if TYPE_CHECKING:
from bless.backends.bluezdbus.dbus.application import ( # type: ignore
Expand All @@ -16,33 +15,13 @@ class Type(Enum):
PERIPHERAL = "peripheral"


class BlueZLEAdvertisement(DBusObject):
class BlueZLEAdvertisement(ServiceInterface):
"""
org.bluez.LEAdvertisement1 interface implementation
"""

interface_name: str = "org.bluez.LEAdvertisement1"

iface: DBusInterface = DBusInterface(
interface_name,
Method("Release"),
Property("Type", "s"),
Property("ServiceUUIDs", "as"),
Property("ManufacturerData", "a{qay}"),
Property("SolicitUUIDs", "as"),
Property("ServiceData", "a{sv}"),
Property("IncludeTxPower", "b"),
)

dbusInterfaces: List[DBusInterface] = [iface]

ad_type: DBusProperty = DBusProperty("Type")
service_uuids: DBusProperty = DBusProperty("ServiceUUIDs")
# manufacturer_data = DBusProperty("ManufacturerData")
# solicit_uuids = DBusProperty("SolicitUUIDs")
# service_data = DBusProperty("ServiceData")
include_tx_power: DBusProperty = DBusProperty("IncludeTxPower")

def __init__(
self,
advertising_type: Type,
Expand All @@ -61,19 +40,67 @@ def __init__(
app : BlueZGattApplication
The Application that is responsible for this advertisement
"""
self.ad_type: str = advertising_type.value
self.path = app.base_path + "/advertisement" + str(index)

self.service_uuids: List[str] = []
self.manufacturer_data: Dict = {}
self.solicit_uuids = [""]
self.service_data = {"": 0}
self._type: str = advertising_type.value
self._service_uuids: List[str] = []
self._manufacturer_data: Dict = {}
self._solicit_uuids: List[str] = [""]
self._service_data: Dict = {}

self.include_tx_power: bool = False
self._include_tx_power: bool = False

self.data = None
super(BlueZLEAdvertisement, self).__init__(self.path)
super(BlueZLEAdvertisement, self).__init__(self.interface_name)

@dbusMethod(interface_name, "Release")
@method()
def Release(self): # noqa: N802
print("%s: Released!" % self.path)

@dbus_property()
def Type(self) -> "s": # type: ignore # noqa: F821
return self._type

@Type.setter # type: ignore
def Type(self, type: "s"): # type: ignore # noqa: F821 F722
self._type = type

@dbus_property() # noqa: F722
def ServiceUUIDs(self) -> "as": # type: ignore # noqa: F821 F722
return self._service_uuids

@ServiceUUIDs.setter # type: ignore # noqa: 722
def ServiceUUIDs(self, service_uuids: "as"): # type: ignore # noqa: F821 F722
self._service_uuids = service_uuids

@dbus_property() # noqa: 722
def ManufacturerData(self) -> "a{qv}": # type: ignore # noqa: F821 F722
return self._manufacturer_data

@ManufacturerData.setter # type: ignore # noqa: F722
def ManufacturerData(self, data: "a{qv}"): # type: ignore # noqa: F821 F722
self._manufacturer_data = data

# @dbus_property()
# def SolicitUUIDs(self) -> "as": # type: ignore # noqa: F821 F722
# return self._solicit_uuids

# @SolicitUUIDs.setter # type: ignore
# def SolicitUUIDs(self, uuids: "as"): # type: ignore # noqa: F821 F722
# self._solicit_uuids = uuids

@dbus_property() # noqa: F722
def ServiceData(self) -> "a{sv}": # type: ignore # noqa: F821 F722
return self._service_data

@ServiceData.setter # type: ignore # noqa: F722
def ServiceData(self, data: "a{sv}"): # type: ignore # noqa: F821 F722
self._service_data = data

@dbus_property()
def IncludeTxPower(self) -> "b": # type: ignore # noqa: F821
return self._include_tx_power

@IncludeTxPower.setter # type: ignore
def IncludeTxPower(self, include: "b"): # type: ignore # noqa: F821
self._include_tx_power = include
Loading

0 comments on commit 7611b56

Please sign in to comment.