From 737abdc481b226b16d85174d9ae0ebd9346b0fb4 Mon Sep 17 00:00:00 2001 From: Slvr <30467496+SilverBzH@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:06:47 -0700 Subject: [PATCH] aics: make it a secondary service (#555) * aics: make it a secondary service --------- Co-authored-by: zxzxwu <92432172+zxzxwu@users.noreply.github.com> --- bumble/profiles/aics.py | 5 +++-- bumble/profiles/vcp.py | 8 +++++--- tests/aics_test.py | 22 ++++++++++++++++------ tests/vcp_test.py | 3 +++ 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/bumble/profiles/aics.py b/bumble/profiles/aics.py index 8b7468fd..3a696272 100644 --- a/bumble/profiles/aics.py +++ b/bumble/profiles/aics.py @@ -442,14 +442,15 @@ def __init__( ) super().__init__( - [ + characteristics=[ self.audio_input_state_characteristic, # type: ignore self.gain_settings_properties_characteristic, # type: ignore self.audio_input_type_characteristic, # type: ignore self.audio_input_status_characteristic, # type: ignore self.audio_input_control_point_characteristic, # type: ignore self.audio_input_description_characteristic, # type: ignore - ] + ], + primary=False, ) diff --git a/bumble/profiles/vcp.py b/bumble/profiles/vcp.py index 07882193..57452d93 100644 --- a/bumble/profiles/vcp.py +++ b/bumble/profiles/vcp.py @@ -24,7 +24,7 @@ from bumble import gatt from bumble import gatt_client -from typing import Optional +from typing import Optional, Sequence # ----------------------------------------------------------------------------- # Constants @@ -88,6 +88,7 @@ def __init__( muted: int = 0, change_counter: int = 0, volume_flags: int = 0, + included_services: Sequence[gatt.Service] = (), ) -> None: self.step_size = step_size self.volume_setting = volume_setting @@ -117,11 +118,12 @@ def __init__( ) super().__init__( - [ + characteristics=[ self.volume_state, self.volume_control_point, self.volume_flags, - ] + ], + included_services=list(included_services), ) @property diff --git a/tests/aics_test.py b/tests/aics_test.py index 8b472982..9526558f 100644 --- a/tests/aics_test.py +++ b/tests/aics_test.py @@ -30,10 +30,9 @@ GainMode, AudioInputStatus, AudioInputControlPointOpCode, - GAIN_SETTINGS_MAX_VALUE, - GAIN_SETTINGS_MIN_VALUE, ErrorCode, ) +from bumble.profiles.vcp import VolumeControlService, VolumeControlServiceProxy from .test_utils import TwoDevices @@ -42,23 +41,34 @@ # Tests # ----------------------------------------------------------------------------- aics_service = AICSService() +vcp_service = VolumeControlService( + volume_setting=32, muted=1, volume_flags=1, included_services=[aics_service] +) @pytest_asyncio.fixture async def aics_client(): devices = TwoDevices() - devices[0].add_service(aics_service) + devices[0].add_service(vcp_service) await devices.setup_connection() - assert devices.connections[0] is not None - assert devices.connections[1] is not None + assert devices.connections[0] + assert devices.connections[1] devices.connections[0].encryption = 1 devices.connections[1].encryption = 1 peer = device.Peer(devices.connections[1]) - aics_client = await peer.discover_service_and_create_proxy(AICSServiceProxy) + + vcp_client = await peer.discover_service_and_create_proxy(VolumeControlServiceProxy) + + assert vcp_client + included_services = await peer.discover_included_services(vcp_client.service_proxy) + assert included_services + aics_service_discovered = included_services[0] + await peer.discover_characteristics(service=aics_service_discovered) + aics_client = AICSServiceProxy(aics_service_discovered) yield aics_client diff --git a/tests/vcp_test.py b/tests/vcp_test.py index d45a5f50..5853ed96 100644 --- a/tests/vcp_test.py +++ b/tests/vcp_test.py @@ -39,6 +39,9 @@ async def vcp_client(): await devices.setup_connection() + assert devices.connections[0] + assert devices.connections[1] + # Mock encryption. devices.connections[0].encryption = 1 devices.connections[1].encryption = 1