mirror of
https://github.com/google/bumble.git
synced 2026-05-09 04:08:02 +00:00
Implement optional synchronization for has (#704)
HAS can be run in synchronized mode, requiring a server to be able to communicate with another CL. This CL is doing a quick implementation of such functionality for preset selection.
This commit is contained in:
@@ -236,6 +236,8 @@ class HearingAccessService(gatt.TemplateService):
|
|||||||
preset_records: Dict[int, PresetRecord] # key is the preset index
|
preset_records: Dict[int, PresetRecord] # key is the preset index
|
||||||
read_presets_request_in_progress: bool
|
read_presets_request_in_progress: bool
|
||||||
|
|
||||||
|
other_server_in_binaural_set: Optional[HearingAccessService] = None
|
||||||
|
|
||||||
preset_changed_operations_history_per_device: Dict[
|
preset_changed_operations_history_per_device: Dict[
|
||||||
Address, List[PresetChangedOperation]
|
Address, List[PresetChangedOperation]
|
||||||
]
|
]
|
||||||
@@ -513,7 +515,7 @@ class HearingAccessService(gatt.TemplateService):
|
|||||||
for connection in self.currently_connected_clients:
|
for connection in self.currently_connected_clients:
|
||||||
await self.notify_active_preset_for_connection(connection)
|
await self.notify_active_preset_for_connection(connection)
|
||||||
|
|
||||||
async def set_active_preset(self, connection: Connection, value: bytes) -> None:
|
async def set_active_preset(self, value: bytes) -> None:
|
||||||
index = value[1]
|
index = value[1]
|
||||||
preset = self.preset_records.get(index, None)
|
preset = self.preset_records.get(index, None)
|
||||||
if (
|
if (
|
||||||
@@ -530,10 +532,10 @@ class HearingAccessService(gatt.TemplateService):
|
|||||||
self.active_preset_index = index
|
self.active_preset_index = index
|
||||||
await self.notify_active_preset()
|
await self.notify_active_preset()
|
||||||
|
|
||||||
async def _on_set_active_preset(self, connection: Connection, value: bytes):
|
async def _on_set_active_preset(self, _: Connection, value: bytes):
|
||||||
await self.set_active_preset(connection, value)
|
await self.set_active_preset(value)
|
||||||
|
|
||||||
async def set_next_or_previous_preset(self, connection: Connection, is_previous):
|
async def set_next_or_previous_preset(self, is_previous):
|
||||||
'''Set the next or the previous preset as active'''
|
'''Set the next or the previous preset as active'''
|
||||||
|
|
||||||
if self.active_preset_index == 0x00:
|
if self.active_preset_index == 0x00:
|
||||||
@@ -563,48 +565,47 @@ class HearingAccessService(gatt.TemplateService):
|
|||||||
self.active_preset_index = first_preset.index
|
self.active_preset_index = first_preset.index
|
||||||
await self.notify_active_preset()
|
await self.notify_active_preset()
|
||||||
|
|
||||||
async def _on_set_next_preset(
|
async def _on_set_next_preset(self, _: Connection, __value__: bytes) -> None:
|
||||||
self, connection: Connection, __value__: bytes
|
await self.set_next_or_previous_preset(False)
|
||||||
) -> None:
|
|
||||||
await self.set_next_or_previous_preset(connection, False)
|
|
||||||
|
|
||||||
async def _on_set_previous_preset(
|
async def _on_set_previous_preset(self, _: Connection, __value__: bytes) -> None:
|
||||||
self, connection: Connection, __value__: bytes
|
await self.set_next_or_previous_preset(True)
|
||||||
) -> None:
|
|
||||||
await self.set_next_or_previous_preset(connection, True)
|
|
||||||
|
|
||||||
async def _on_set_active_preset_synchronized_locally(
|
async def _on_set_active_preset_synchronized_locally(
|
||||||
self, connection: Connection, value: bytes
|
self, _: Connection, value: bytes
|
||||||
):
|
):
|
||||||
if (
|
if (
|
||||||
self.server_features.preset_synchronization_support
|
self.server_features.preset_synchronization_support
|
||||||
== PresetSynchronizationSupport.PRESET_SYNCHRONIZATION_IS_SUPPORTED
|
== PresetSynchronizationSupport.PRESET_SYNCHRONIZATION_IS_NOT_SUPPORTED
|
||||||
):
|
):
|
||||||
raise att.ATT_Error(ErrorCode.PRESET_SYNCHRONIZATION_NOT_SUPPORTED)
|
raise att.ATT_Error(ErrorCode.PRESET_SYNCHRONIZATION_NOT_SUPPORTED)
|
||||||
await self.set_active_preset(connection, value)
|
await self.set_active_preset(value)
|
||||||
# TODO (low priority) inform other server of the change
|
if self.other_server_in_binaural_set:
|
||||||
|
await self.other_server_in_binaural_set.set_active_preset(value)
|
||||||
|
|
||||||
async def _on_set_next_preset_synchronized_locally(
|
async def _on_set_next_preset_synchronized_locally(
|
||||||
self, connection: Connection, __value__: bytes
|
self, _: Connection, __value__: bytes
|
||||||
):
|
):
|
||||||
if (
|
if (
|
||||||
self.server_features.preset_synchronization_support
|
self.server_features.preset_synchronization_support
|
||||||
== PresetSynchronizationSupport.PRESET_SYNCHRONIZATION_IS_SUPPORTED
|
== PresetSynchronizationSupport.PRESET_SYNCHRONIZATION_IS_NOT_SUPPORTED
|
||||||
):
|
):
|
||||||
raise att.ATT_Error(ErrorCode.PRESET_SYNCHRONIZATION_NOT_SUPPORTED)
|
raise att.ATT_Error(ErrorCode.PRESET_SYNCHRONIZATION_NOT_SUPPORTED)
|
||||||
await self.set_next_or_previous_preset(connection, False)
|
await self.set_next_or_previous_preset(False)
|
||||||
# TODO (low priority) inform other server of the change
|
if self.other_server_in_binaural_set:
|
||||||
|
await self.other_server_in_binaural_set.set_next_or_previous_preset(False)
|
||||||
|
|
||||||
async def _on_set_previous_preset_synchronized_locally(
|
async def _on_set_previous_preset_synchronized_locally(
|
||||||
self, connection: Connection, __value__: bytes
|
self, _: Connection, __value__: bytes
|
||||||
):
|
):
|
||||||
if (
|
if (
|
||||||
self.server_features.preset_synchronization_support
|
self.server_features.preset_synchronization_support
|
||||||
== PresetSynchronizationSupport.PRESET_SYNCHRONIZATION_IS_SUPPORTED
|
== PresetSynchronizationSupport.PRESET_SYNCHRONIZATION_IS_NOT_SUPPORTED
|
||||||
):
|
):
|
||||||
raise att.ATT_Error(ErrorCode.PRESET_SYNCHRONIZATION_NOT_SUPPORTED)
|
raise att.ATT_Error(ErrorCode.PRESET_SYNCHRONIZATION_NOT_SUPPORTED)
|
||||||
await self.set_next_or_previous_preset(connection, True)
|
await self.set_next_or_previous_preset(True)
|
||||||
# TODO (low priority) inform other server of the change
|
if self.other_server_in_binaural_set:
|
||||||
|
await self.other_server_in_binaural_set.set_next_or_previous_preset(True)
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user