11from uuid import UUID
22from 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 ,
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