Coverage for src / bluetooth_sig / gatt / characteristics / call_state.py: 100%

32 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-03 16:41 +0000

1"""Call State characteristic (0x2BBC).""" 

2 

3from __future__ import annotations 

4 

5import msgspec 

6 

7from ..context import CharacteristicContext 

8from .base import BaseCharacteristic 

9from .bearer_list_current_calls import CallFlags, CallState 

10 

11_CALL_STATE_ENTRY_SIZE = 3 # call_index(1) + state(1) + flags(1) 

12 

13 

14class CallStateEntry(msgspec.Struct, frozen=True, kw_only=True): 

15 """A single call state entry.""" 

16 

17 call_index: int 

18 state: CallState 

19 call_flags: CallFlags 

20 

21 

22class CallStateData(msgspec.Struct, frozen=True, kw_only=True): 

23 """Parsed data from Call State characteristic.""" 

24 

25 entries: tuple[CallStateEntry, ...] 

26 

27 

28class CallStateCharacteristic(BaseCharacteristic[CallStateData]): 

29 """Call State characteristic (0x2BBC). 

30 

31 org.bluetooth.characteristic.call_state 

32 

33 List of call states for all current calls. 

34 """ 

35 

36 min_length = 0 

37 allow_variable_length = True 

38 

39 def _decode_value( 

40 self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True 

41 ) -> CallStateData: 

42 entries: list[CallStateEntry] = [] 

43 offset = 0 

44 

45 while offset + _CALL_STATE_ENTRY_SIZE <= len(data): 

46 call_index = data[offset] 

47 state = CallState(data[offset + 1]) 

48 call_flags = CallFlags(data[offset + 2]) 

49 entries.append( 

50 CallStateEntry( 

51 call_index=call_index, 

52 state=state, 

53 call_flags=call_flags, 

54 ) 

55 ) 

56 offset += _CALL_STATE_ENTRY_SIZE 

57 

58 return CallStateData(entries=tuple(entries)) 

59 

60 def _encode_value(self, data: CallStateData) -> bytearray: 

61 result = bytearray() 

62 for entry in data.entries: 

63 result.append(entry.call_index) 

64 result.append(int(entry.state)) 

65 result.append(int(entry.call_flags)) 

66 return result