Skip to content

Commit

Permalink
aics: make it a secondary service (#555)
Browse files Browse the repository at this point in the history
* aics: make it a secondary service
---------

Co-authored-by: zxzxwu <[email protected]>
  • Loading branch information
SilverBzH and zxzxwu authored Sep 17, 2024
1 parent 02eb4d2 commit 737abdc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
5 changes: 3 additions & 2 deletions bumble/profiles/aics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
8 changes: 5 additions & 3 deletions bumble/profiles/vcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from bumble import gatt
from bumble import gatt_client

from typing import Optional
from typing import Optional, Sequence

# -----------------------------------------------------------------------------
# Constants
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions tests/aics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions tests/vcp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 737abdc

Please sign in to comment.