Coverage for src / bluetooth_sig / gatt / characteristics / supported_audio_contexts.py: 100%
20 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-03 16:41 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-03 16:41 +0000
1"""Supported Audio Contexts characteristic (0x2BCE)."""
3from __future__ import annotations
5import msgspec
7from bluetooth_sig.types.audio_context_type import AudioContextType
9from ..context import CharacteristicContext
10from .base import BaseCharacteristic
11from .utils import DataParser
14class SupportedAudioContextsData(msgspec.Struct, frozen=True, kw_only=True): # pylint: disable=too-few-public-methods
15 """Parsed data from Supported Audio Contexts characteristic.
17 Contains the supported sink and source audio contexts.
18 """
20 sink_audio_contexts: AudioContextType
21 source_audio_contexts: AudioContextType
24class SupportedAudioContextsCharacteristic(BaseCharacteristic[SupportedAudioContextsData]):
25 """Supported Audio Contexts characteristic (0x2BCE).
27 org.bluetooth.characteristic.supported_audio_contexts
29 Reports the supported audio contexts for sink and source.
30 """
32 expected_length = 4
34 def _decode_value(
35 self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True
36 ) -> SupportedAudioContextsData:
37 """Parse Supported Audio Contexts data.
39 Format: sink_audio_contexts (uint16 LE) + source_audio_contexts (uint16 LE).
40 """
41 sink = AudioContextType(DataParser.parse_int16(data, 0, signed=False))
42 source = AudioContextType(DataParser.parse_int16(data, 2, signed=False))
43 return SupportedAudioContextsData(
44 sink_audio_contexts=sink,
45 source_audio_contexts=source,
46 )
48 def _encode_value(self, data: SupportedAudioContextsData) -> bytearray:
49 """Encode Supported Audio Contexts data to bytes."""
50 result = bytearray()
51 result += DataParser.encode_int16(int(data.sink_audio_contexts))
52 result += DataParser.encode_int16(int(data.source_audio_contexts))
53 return result