Skip to content

Commit 7611b56

Browse files
authored
Merge pull request #82 from kevincar/develop
Develop
2 parents 81044dd + c886b0f commit 7611b56

File tree

23 files changed

+567
-532
lines changed

23 files changed

+567
-532
lines changed

.github/workflows/build-and-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- ubuntu-latest
1919
- windows-latest
2020
- macos-latest
21-
python-version: [3.6, 3.7, 3.8]
21+
python-version: [3.7, 3.8, 3.9]
2222

2323
steps:
2424
- uses: actions/checkout@v2
@@ -48,6 +48,8 @@ jobs:
4848
# exit-zero treats all errors as warnings.
4949
flake8 . --count --exit-zero --statistic --max-line-length 88
5050
- name: Check mypy
51+
# Hold off on windows. Mypy is not being consistant there
52+
if: runner.os != 'Windows'
5153
run: |
5254
mypy bless
5355
- name: Test with pytest

bless/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,28 @@
88
BlessServerCoreBluetooth as BlessServer,
99
)
1010

11+
# Service
12+
from bless.backends.corebluetooth.service import ( # noqa: F401
13+
BlessGATTServiceCoreBluetooth as BlessGATTService
14+
)
15+
1116
# Characteristic Classes
1217
from bless.backends.corebluetooth.characteristic import ( # noqa: F401
1318
BlessGATTCharacteristicCoreBluetooth as BlessGATTCharacteristic,
1419
)
20+
1521
elif sys.platform == "linux":
1622

1723
# Server
1824
from bless.backends.bluezdbus.server import ( # noqa: F401
1925
BlessServerBlueZDBus as BlessServer,
2026
)
2127

28+
# Service
29+
from bless.backends.bluezdbus.service import ( # noqa: F401
30+
BlessGATTServiceBlueZDBus as BlessGATTService
31+
)
32+
2233
# Characteristic Classes
2334
from bless.backends.bluezdbus.characteristic import ( # noqa: F401
2435
BlessGATTCharacteristicBlueZDBus as BlessGATTCharacteristic,
@@ -31,6 +42,11 @@
3142
BlessServerWinRT as BlessServer,
3243
)
3344

45+
# Service
46+
from bless.backends.winrt.service import ( # noqa: F401
47+
BlessGATTServiceWinRT as BlessGATTService
48+
)
49+
3450
# Characteristic Classes
3551
from bless.backends.winrt.characteristic import ( # noqa: F401
3652
BlessGATTCharacteristicWinRT as BlessGATTCharacteristic,

bless/backends/bluezdbus/characteristic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def init(self, service: "BlessGATTServiceBlueZDBus"):
6565

6666
# Add to our BlueZDBus app
6767
gatt_char: BlueZGattCharacteristic = await service.gatt.add_characteristic(
68-
self._uuid, flags, self.value
68+
self._uuid, flags, bytes(self.value)
6969
)
7070
dict_obj: Dict = await gatt_char.get_obj()
7171

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

88+
@property
89+
def uuid(self) -> str:
90+
"""The uuid of this characteristic"""
91+
return self.obj.get("UUID").value
92+
8893

8994
def flags_to_dbus(flags: GATTCharacteristicProperties) -> List[Flags]:
9095
"""

bless/backends/bluezdbus/dbus/advertisement.py

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
from typing import List, Dict, TYPE_CHECKING
44

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

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

1817

19-
class BlueZLEAdvertisement(DBusObject):
18+
class BlueZLEAdvertisement(ServiceInterface):
2019
"""
2120
org.bluez.LEAdvertisement1 interface implementation
2221
"""
2322

2423
interface_name: str = "org.bluez.LEAdvertisement1"
2524

26-
iface: DBusInterface = DBusInterface(
27-
interface_name,
28-
Method("Release"),
29-
Property("Type", "s"),
30-
Property("ServiceUUIDs", "as"),
31-
Property("ManufacturerData", "a{qay}"),
32-
Property("SolicitUUIDs", "as"),
33-
Property("ServiceData", "a{sv}"),
34-
Property("IncludeTxPower", "b"),
35-
)
36-
37-
dbusInterfaces: List[DBusInterface] = [iface]
38-
39-
ad_type: DBusProperty = DBusProperty("Type")
40-
service_uuids: DBusProperty = DBusProperty("ServiceUUIDs")
41-
# manufacturer_data = DBusProperty("ManufacturerData")
42-
# solicit_uuids = DBusProperty("SolicitUUIDs")
43-
# service_data = DBusProperty("ServiceData")
44-
include_tx_power: DBusProperty = DBusProperty("IncludeTxPower")
45-
4625
def __init__(
4726
self,
4827
advertising_type: Type,
@@ -61,19 +40,67 @@ def __init__(
6140
app : BlueZGattApplication
6241
The Application that is responsible for this advertisement
6342
"""
64-
self.ad_type: str = advertising_type.value
6543
self.path = app.base_path + "/advertisement" + str(index)
6644

67-
self.service_uuids: List[str] = []
68-
self.manufacturer_data: Dict = {}
69-
self.solicit_uuids = [""]
70-
self.service_data = {"": 0}
45+
self._type: str = advertising_type.value
46+
self._service_uuids: List[str] = []
47+
self._manufacturer_data: Dict = {}
48+
self._solicit_uuids: List[str] = [""]
49+
self._service_data: Dict = {}
7150

72-
self.include_tx_power: bool = False
51+
self._include_tx_power: bool = False
7352

7453
self.data = None
75-
super(BlueZLEAdvertisement, self).__init__(self.path)
54+
super(BlueZLEAdvertisement, self).__init__(self.interface_name)
7655

77-
@dbusMethod(interface_name, "Release")
56+
@method()
7857
def Release(self): # noqa: N802
7958
print("%s: Released!" % self.path)
59+
60+
@dbus_property()
61+
def Type(self) -> "s": # type: ignore # noqa: F821
62+
return self._type
63+
64+
@Type.setter # type: ignore
65+
def Type(self, type: "s"): # type: ignore # noqa: F821 F722
66+
self._type = type
67+
68+
@dbus_property() # noqa: F722
69+
def ServiceUUIDs(self) -> "as": # type: ignore # noqa: F821 F722
70+
return self._service_uuids
71+
72+
@ServiceUUIDs.setter # type: ignore # noqa: 722
73+
def ServiceUUIDs(self, service_uuids: "as"): # type: ignore # noqa: F821 F722
74+
self._service_uuids = service_uuids
75+
76+
@dbus_property() # noqa: 722
77+
def ManufacturerData(self) -> "a{qv}": # type: ignore # noqa: F821 F722
78+
return self._manufacturer_data
79+
80+
@ManufacturerData.setter # type: ignore # noqa: F722
81+
def ManufacturerData(self, data: "a{qv}"): # type: ignore # noqa: F821 F722
82+
self._manufacturer_data = data
83+
84+
# @dbus_property()
85+
# def SolicitUUIDs(self) -> "as": # type: ignore # noqa: F821 F722
86+
# return self._solicit_uuids
87+
88+
# @SolicitUUIDs.setter # type: ignore
89+
# def SolicitUUIDs(self, uuids: "as"): # type: ignore # noqa: F821 F722
90+
# self._solicit_uuids = uuids
91+
92+
@dbus_property() # noqa: F722
93+
def ServiceData(self) -> "a{sv}": # type: ignore # noqa: F821 F722
94+
return self._service_data
95+
96+
@ServiceData.setter # type: ignore # noqa: F722
97+
def ServiceData(self, data: "a{sv}"): # type: ignore # noqa: F821 F722
98+
self._service_data = data
99+
100+
@dbus_property()
101+
def IncludeTxPower(self) -> "b": # type: ignore # noqa: F821
102+
return self._include_tx_power
103+
104+
@IncludeTxPower.setter # type: ignore
105+
def IncludeTxPower(self, include: "b"): # type: ignore # noqa: F821
106+
self._include_tx_power = include

0 commit comments

Comments
 (0)