Skip to content

Commit 81044dd

Browse files
authored
Merge pull request #58 from kevincar/develop
Develop
2 parents 8db03e3 + 788c32a commit 81044dd

File tree

9 files changed

+233
-293
lines changed

9 files changed

+233
-293
lines changed

bless/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
elif sys.platform == "win32":
2828

2929
# Server
30-
from bless.backends.dotnet.server import ( # noqa: F401
31-
BlessServerDotNet as BlessServer,
30+
from bless.backends.winrt.server import ( # noqa: F401
31+
BlessServerWinRT as BlessServer,
3232
)
3333

3434
# Characteristic Classes
35-
from bless.backends.dotnet.characteristic import ( # noqa: F401
36-
BlessGATTCharacteristicDotNet as BlessGATTCharacteristic,
35+
from bless.backends.winrt.characteristic import ( # noqa: F401
36+
BlessGATTCharacteristicWinRT as BlessGATTCharacteristic,
3737
)
3838

3939

bless/backends/dotnet/service.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

bless/backends/dotnet/utils.py

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
from uuid import UUID
22
from typing import Union, Optional
33

4-
from bleak.backends.dotnet.characteristic import ( # type: ignore
5-
BleakGATTCharacteristicDotNet,
6-
)
7-
from bleak.backends.dotnet.utils import ( # type: ignore
8-
wrap_IAsyncOperation,
4+
from bleak.backends.winrt.characteristic import ( # type: ignore
5+
BleakGATTCharacteristicWinRT,
96
)
107

11-
from System import Guid # type: ignore
12-
from Windows.Foundation import IAsyncOperation # type: ignore
13-
from Windows.Devices.Bluetooth.GenericAttributeProfile import ( # type: ignore
8+
from bleak_winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E501
149
GattProtectionLevel,
1510
GattLocalCharacteristicParameters,
1611
GattLocalCharacteristic,
@@ -26,11 +21,11 @@
2621
)
2722

2823

29-
class BlessGATTCharacteristicDotNet(
30-
BlessGATTCharacteristic, BleakGATTCharacteristicDotNet
24+
class BlessGATTCharacteristicWinRT(
25+
BlessGATTCharacteristic, BleakGATTCharacteristicWinRT
3126
):
3227
"""
33-
DotNet implementation of the BlessGATTCharacteristic
28+
WinRT implementation of the BlessGATTCharacteristic
3429
"""
3530

3631
def __init__(
@@ -62,40 +57,35 @@ def __init__(
6257

6358
async def init(self, service: BlessGATTService):
6459
"""
65-
Initialize the DotNet GattLocalCharacteristic object
60+
Initialize the WinRT GattLocalCharacteristic object
6661
6762
Parameters
6863
----------
69-
service : BlessGATTServiceDotNet
64+
service : BlessGATTServiceWinRT
7065
The service to assign the characteristic to
7166
"""
72-
charguid: Guid = Guid.Parse(self._uuid)
73-
7467
char_parameters: GattLocalCharacteristicParameters = (
7568
GattLocalCharacteristicParameters()
7669
)
77-
char_parameters.CharacteristicProperties = self._properties.value
78-
char_parameters.ReadProtectionLevel = (
79-
BlessGATTCharacteristicDotNet.permissions_to_protection_level(
70+
char_parameters.characteristic_properties = self._properties.value
71+
char_parameters.read_protection_level = (
72+
BlessGATTCharacteristicWinRT.permissions_to_protection_level(
8073
self._permissions, True
8174
)
8275
)
83-
char_parameters.WriteProtectionLevel = (
84-
BlessGATTCharacteristicDotNet.permissions_to_protection_level(
76+
char_parameters.write_protection_level = (
77+
BlessGATTCharacteristicWinRT.permissions_to_protection_level(
8578
self._permissions, False
8679
)
8780
)
8881

8982
characteristic_result: GattLocalCharacteristicResult = (
90-
await wrap_IAsyncOperation(
91-
IAsyncOperation[GattLocalCharacteristicResult](
92-
service.obj.CreateCharacteristicAsync(charguid, char_parameters)
93-
),
94-
return_type=GattLocalCharacteristicResult,
83+
await service.obj.create_characteristic_async(
84+
UUID(self._uuid), char_parameters
9585
)
9686
)
9787

98-
gatt_char: GattLocalCharacteristic = characteristic_result.Characteristic
88+
gatt_char: GattLocalCharacteristic = characteristic_result.characteristic
9989
super(BlessGATTCharacteristic, self).__init__(obj=gatt_char)
10090

10191
@staticmethod
@@ -118,11 +108,11 @@ def permissions_to_protection_level(
118108
GattProtectionLevel
119109
The protection level equivalent
120110
"""
121-
result: GattProtectionLevel = GattProtectionLevel.Plain
111+
result: GattProtectionLevel = GattProtectionLevel.PLAIN
122112
shift_value: int = 3 if read else 4
123113
permission_value: int = permissions.value >> shift_value
124114
if permission_value & 1:
125-
result |= GattProtectionLevel.EncryptionRequired
115+
result |= GattProtectionLevel.ENCRYPTION_REQURIED
126116
return result
127117

128118
@property

0 commit comments

Comments
 (0)