forked from auracaster/bumble_mirror
restore python < 11 compat
This commit is contained in:
+11
-2
@@ -326,6 +326,15 @@ class Characteristic(Attribute):
|
||||
f"Characteristic.Properties::from_string() error:\nExpected a string containing any of the keys, separated by , or |: {enum_list_str}\nGot: {properties_str}"
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
# NOTE: we override this method to offer a consistent result between python
|
||||
# versions: the value returned by IntFlag.__str__() changed in version 11.
|
||||
return '|'.join(
|
||||
flag.name
|
||||
for flag in Characteristic.Properties
|
||||
if self.value & flag.value and flag.name is not None
|
||||
)
|
||||
|
||||
# For backwards compatibility these are defined here
|
||||
# For new code, please use Characteristic.Properties.X
|
||||
BROADCAST = Properties.BROADCAST
|
||||
@@ -365,7 +374,7 @@ class Characteristic(Attribute):
|
||||
f'Characteristic(handle=0x{self.handle:04X}, '
|
||||
f'end=0x{self.end_group_handle:04X}, '
|
||||
f'uuid={self.uuid}, '
|
||||
f'{self.properties.name})'
|
||||
f'{self.properties})'
|
||||
)
|
||||
|
||||
|
||||
@@ -393,7 +402,7 @@ class CharacteristicDeclaration(Attribute):
|
||||
f'CharacteristicDeclaration(handle=0x{self.handle:04X}, '
|
||||
f'value_handle=0x{self.value_handle:04X}, '
|
||||
f'uuid={self.characteristic.uuid}, '
|
||||
f'{self.characteristic.properties.name})'
|
||||
f'{self.characteristic.properties})'
|
||||
)
|
||||
|
||||
|
||||
|
||||
+6
-5
@@ -803,14 +803,15 @@ async def test_mtu_exchange():
|
||||
# -----------------------------------------------------------------------------
|
||||
def test_char_property_to_string():
|
||||
# single
|
||||
assert Characteristic.Properties(0x01).name == "BROADCAST"
|
||||
assert Characteristic.Properties.BROADCAST.name == "BROADCAST"
|
||||
assert str(Characteristic.Properties(0x01)) == "BROADCAST"
|
||||
assert str(Characteristic.Properties.BROADCAST) == "BROADCAST"
|
||||
|
||||
# double
|
||||
assert Characteristic.Properties(0x03).name == "BROADCAST|READ"
|
||||
assert str(Characteristic.Properties(0x03)) == "BROADCAST|READ"
|
||||
assert (
|
||||
Characteristic.Properties.BROADCAST | Characteristic.Properties.READ
|
||||
).name == "BROADCAST|READ"
|
||||
str(Characteristic.Properties.BROADCAST | Characteristic.Properties.READ)
|
||||
== "BROADCAST|READ"
|
||||
)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user