From b375ed07b407a2124ccd69b43f027f32ea1ba8a7 Mon Sep 17 00:00:00 2001 From: Gilles Boccon-Gibod Date: Tue, 7 Jan 2025 14:54:59 -0500 Subject: [PATCH] add test --- bumble/hci.py | 2 +- tests/hci_test.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/bumble/hci.py b/bumble/hci.py index f9b39ae..3d849cc 100644 --- a/bumble/hci.py +++ b/bumble/hci.py @@ -5167,7 +5167,7 @@ class HCI_Event(HCI_Packet): # No factory, or the factory could not create an instance, # return a generic vendor event - return HCI_Event(event_code, parameters) + return HCI_Vendor_Event(data=parameters) else: subclass = HCI_Event.event_classes.get(event_code) if subclass is None: diff --git a/tests/hci_test.py b/tests/hci_test.py index 30ab0d7..ee4ef8a 100644 --- a/tests/hci_test.py +++ b/tests/hci_test.py @@ -15,6 +15,7 @@ # ----------------------------------------------------------------------------- # Imports # ----------------------------------------------------------------------------- +import struct from bumble.hci import ( HCI_DISCONNECT_COMMAND, @@ -22,6 +23,7 @@ from bumble.hci import ( HCI_LE_CODED_PHY_BIT, HCI_LE_READ_BUFFER_SIZE_COMMAND, HCI_RESET_COMMAND, + HCI_VENDOR_EVENT, HCI_SUCCESS, HCI_LE_CONNECTION_COMPLETE_EVENT, HCI_LE_ENHANCED_CONNECTION_COMPLETE_V2_EVENT, @@ -67,6 +69,7 @@ from bumble.hci import ( HCI_Read_Local_Version_Information_Command, HCI_Reset_Command, HCI_Set_Event_Mask_Command, + HCI_Vendor_Event, ) @@ -213,6 +216,41 @@ def test_HCI_Number_Of_Completed_Packets_Event(): basic_check(event) +# ----------------------------------------------------------------------------- +def test_HCI_Vendor_Event(): + data = bytes.fromhex('01020304') + event = HCI_Vendor_Event(data=data) + event_bytes = bytes(event) + parsed = HCI_Packet.from_bytes(event_bytes) + assert isinstance(parsed, HCI_Vendor_Event) + assert parsed.data == data + + class HCI_Custom_Event(HCI_Event): + def __init__(self, blabla): + super().__init__(HCI_VENDOR_EVENT, parameters=struct.pack("