From a65a215fd799cc657eab60e11ad54a3a86c5c2ca Mon Sep 17 00:00:00 2001 From: Josh Wu Date: Sun, 26 Nov 2023 19:26:42 +0800 Subject: [PATCH] Provide IntFlag.name property fallback --- bumble/hci.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/bumble/hci.py b/bumble/hci.py index 7a7132ae..8897624e 100644 --- a/bumble/hci.py +++ b/bumble/hci.py @@ -3829,9 +3829,11 @@ class HCI_LE_Set_Advertising_Set_Random_Address_Command(HCI_Command): 'advertising_event_properties', { 'size': 2, - 'mapper': lambda x: HCI_LE_Set_Extended_Advertising_Parameters_Command.AdvertisingProperties( - x - ).name, + 'mapper': lambda x: str( + HCI_LE_Set_Extended_Advertising_Parameters_Command.AdvertisingProperties( + x + ) + ), }, ), ('primary_advertising_interval_min', 3), @@ -3840,9 +3842,9 @@ class HCI_LE_Set_Advertising_Set_Random_Address_Command(HCI_Command): 'primary_advertising_channel_map', { 'size': 1, - 'mapper': lambda x: HCI_LE_Set_Extended_Advertising_Parameters_Command.ChannelMap( - x - ).name, + 'mapper': lambda x: str( + HCI_LE_Set_Extended_Advertising_Parameters_Command.ChannelMap(x) + ), }, ), ('own_address_type', OwnAddressType.TYPE_SPEC), @@ -3872,11 +3874,25 @@ class AdvertisingProperties(enum.IntFlag): ANONYMOUS_ADVERTISING = 1 << 5 INCLUDE_TX_POWER = 1 << 6 + def __str__(self) -> str: + return '|'.join( + flag.name + for flag in HCI_LE_Set_Extended_Advertising_Parameters_Command.AdvertisingProperties + if self.value & flag.value and flag.name is not None + ) + class ChannelMap(enum.IntFlag): CHANNEL_37 = 1 << 0 CHANNEL_38 = 1 << 1 CHANNEL_39 = 1 << 2 + def __str__(self) -> str: + return '|'.join( + flag.name + for flag in HCI_LE_Set_Extended_Advertising_Parameters_Command.ChannelMap + if self.value & flag.value and flag.name is not None + ) + # ----------------------------------------------------------------------------- @HCI_Command.command(