Coverage for src / bluetooth_sig / gatt / characteristics / alert_category_id_bit_mask.py: 100%
13 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 20:14 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 20:14 +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(self, data: bytearray, ctx: CharacteristicContext | None = None) -> AlertCategoryBitMask:
41 """Decode Alert Category ID Bit Mask data from bytes.
43 Args:
44 data: Raw characteristic data (2 bytes)
45 ctx: Optional characteristic context
47 Returns:
48 AlertCategoryBitMask flags
50 Raises:
51 ValueError: If data is insufficient
53 """
54 mask_value = DataParser.parse_int16(data, 0, signed=False)
55 return AlertCategoryBitMask(mask_value)
57 def _encode_value(self, data: AlertCategoryBitMask | int) -> bytearray:
58 """Encode Alert Category ID Bit Mask data to bytes.
60 Args:
61 data: AlertCategoryBitMask or int value
63 Returns:
64 Encoded alert category ID bit mask (2 bytes)
66 """
67 int_value = int(data) if isinstance(data, AlertCategoryBitMask) else data
68 return DataParser.encode_int16(int_value, signed=False)