Refactor bluetooth message handling to extract on_bluetooth_message

This commit is contained in:
J. Nick Koston 2023-11-28 08:21:29 -06:00
parent baf21ddb50
commit 3aefecbdab
No known key found for this signature in database
1 changed files with 9 additions and 12 deletions

View File

@ -118,19 +118,16 @@ def on_bluetooth_device_connection_response(
connect_future.set_result(None)
def on_bluetooth_message(address: int, handle: int, msg: message.Message) -> bool:
def on_bluetooth_message(
address: int,
handle: int,
msg: BluetoothGATTErrorResponse
| BluetoothGATTNotifyResponse
| BluetoothGATTReadResponse
| BluetoothGATTWriteResponse
| BluetoothDeviceConnectionResponse,
) -> bool:
"""Handle a Bluetooth message."""
if TYPE_CHECKING:
assert isinstance(
msg,
(
BluetoothGATTErrorResponse,
BluetoothGATTNotifyResponse,
BluetoothGATTReadResponse,
BluetoothGATTWriteResponse,
BluetoothDeviceConnectionResponse,
),
)
if type(msg) is BluetoothDeviceConnectionResponse:
return bool(msg.address == address)
return bool(msg.address == address and msg.handle == handle)