Coverage for src / bluetooth_sig / gatt / characteristics / alert_notification_control_point.py: 100%
22 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 Notification Control Point characteristic (0x2A44) implementation.
3Control point for enabling/disabling alert notifications and triggering immediate notifications.
4Used by Alert Notification Service (0x1811).
6Based on Bluetooth SIG GATT Specification:
7- Alert Notification Control Point: 2 bytes (Command ID + Category ID)
8"""
10from __future__ import annotations
12import msgspec
14from ...types import AlertCategoryID, AlertNotificationCommandID
15from ..context import CharacteristicContext
16from .base import BaseCharacteristic
17from .utils import DataParser
20class AlertNotificationControlPointData(msgspec.Struct):
21 """Alert Notification Control Point characteristic data structure."""
23 command_id: AlertNotificationCommandID
24 category_id: AlertCategoryID
27class AlertNotificationControlPointCharacteristic(BaseCharacteristic[AlertNotificationControlPointData]):
28 """Alert Notification Control Point characteristic (0x2A44).
30 Control point for enabling/disabling notifications and requesting immediate alerts.
32 Structure (2 bytes):
33 - Command ID: uint8 (0=Enable New Alert, 1=Enable Unread Status, etc.)
34 - Category ID: uint8 (0=Simple Alert, 1=Email, etc. - target category for command)
36 Commands:
37 - 0: Enable New Incoming Alert Notification
38 - 1: Enable Unread Category Status Notification
39 - 2: Disable New Incoming Alert Notification
40 - 3: Disable Unread Category Status Notification
41 - 4: Notify New Incoming Alert immediately
42 - 5: Notify Unread Category Status immediately
44 Used by Alert Notification Service (0x1811).
45 """
47 min_length: int = 2 # Command ID + Category ID
48 allow_variable_length: bool = True # Some commands may have additional data
50 def _decode_value(
51 self, data: bytearray, ctx: CharacteristicContext | None = None
52 ) -> AlertNotificationControlPointData:
53 """Decode Alert Notification Control Point data from bytes.
55 Args:
56 data: Raw characteristic data (2 bytes, length validated by BaseCharacteristic)
57 ctx: Optional characteristic context
59 Returns:
60 AlertNotificationControlPointData with all fields
62 Raises:
63 ValueError: If data contains invalid values
65 """
66 # Parse Command ID (1 byte)
67 command_id = AlertNotificationCommandID(DataParser.parse_int8(data, 0, signed=False))
69 # Parse Category ID (1 byte)
70 category_id_raw = DataParser.parse_int8(data, 1, signed=False)
71 category_id = AlertCategoryID(category_id_raw)
73 return AlertNotificationControlPointData(
74 command_id=command_id,
75 category_id=category_id,
76 )
78 def _encode_value(self, data: AlertNotificationControlPointData) -> bytearray:
79 """Encode Alert Notification Control Point data to bytes.
81 Args:
82 data: AlertNotificationControlPointData to encode
84 Returns:
85 Encoded alert notification control point (2 bytes)
87 Raises:
88 ValueError: If data contains invalid values
90 """
91 result = bytearray()
92 result.append(int(data.command_id))
93 result.append(int(data.category_id))
94 return result