Coverage for src / bluetooth_sig / gatt / characteristics / alert_category_id_bit_mask.py: 100%
13 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-18 11:17 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-18 11:17 +0000
1"""Alert Category ID Bit Mask characteristic implementation."""
3from __future__ import annotations
5from ...types import AlertCategoryBitMask
6from ..context import CharacteristicContext
7from .base import BaseCharacteristic
8from .utils import DataParser
11class AlertCategoryIdBitMaskCharacteristic(BaseCharacteristic[AlertCategoryBitMask]):
12 """Alert Category ID Bit Mask characteristic (0x2A42).
14 org.bluetooth.characteristic.alert_category_id_bit_mask
16 The Alert Category ID Bit Mask characteristic is used to represent
17 support for predefined categories of alerts and messages using a bit mask.
19 Structure (2 bytes):
20 - Category ID Bit Mask: uint16 (bit field where each bit represents support for a category)
21 Bit 0: Simple Alert
22 Bit 1: Email
23 Bit 2: News
24 Bit 3: Call
25 Bit 4: Missed Call
26 Bit 5: SMS/MMS
27 Bit 6: Voice Mail
28 Bit 7: Schedule
29 Bit 8: High Prioritized Alert
30 Bit 9: Instant Message
31 Bits 10-15: Reserved for Future Use
33 Used by Alert Notification Service (0x1811).
35 Spec: Bluetooth SIG GATT Specification Supplement, Alert Category ID Bit Mask
36 """
38 expected_length: int | None = 2
40 def _decode_value(
41 self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True
42 ) -> AlertCategoryBitMask:
43 """Decode Alert Category ID Bit Mask data from bytes.
45 Args:
46 data: Raw characteristic data (2 bytes)
47 ctx: Optional characteristic context
48 validate: Whether to validate ranges (default True)
50 Returns:
51 AlertCategoryBitMask flags
53 Raises:
54 ValueError: If data is insufficient
56 """
57 mask_value = DataParser.parse_int16(data, 0, signed=False)
58 return AlertCategoryBitMask(mask_value)
60 def _encode_value(self, data: AlertCategoryBitMask | int) -> bytearray:
61 """Encode Alert Category ID Bit Mask data to bytes.
63 Args:
64 data: AlertCategoryBitMask or int value
66 Returns:
67 Encoded alert category ID bit mask (2 bytes)
69 """
70 int_value = int(data) if isinstance(data, AlertCategoryBitMask) else data
71 return DataParser.encode_int16(int_value, signed=False)