Coverage for src / bluetooth_sig / gatt / characteristics / rotational_speed.py: 100%
12 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"""Rotational Speed characteristic implementation."""
3from __future__ import annotations
5from ..context import CharacteristicContext
6from .base import BaseCharacteristic
7from .utils.data_parser import DataParser
10class RotationalSpeedCharacteristic(BaseCharacteristic[float]):
11 """Rotational Speed characteristic (0x2C09).
13 org.bluetooth.characteristic.rotational_speed
15 The Rotational Speed characteristic is used to represent the rotational speed of an object
16 rotating around a device-specific axis.
17 """
19 _manual_unit: str | None = "RPM" # YAML ID mismatch: has rotational_speed.*, should be angular_velocity.*
21 def _decode_value(self, data: bytearray, ctx: CharacteristicContext | None = None) -> float | None:
22 """Decode rotational speed characteristic.
24 Decodes a 32-bit signed integer representing speed in RPM
25 per Bluetooth SIG Rotational Speed characteristic specification.
27 Args:
28 data: Raw bytes from BLE characteristic (exactly 4 bytes, little-endian)
29 ctx: Optional context for parsing (device info, flags, etc.)
31 Returns:
32 Rotational speed in revolutions per minute (RPM), or None if value is not known
34 Raises:
35 InsufficientDataError: If data is not exactly 4 bytes
36 """
37 raw_value = DataParser.parse_int32(data, 0, signed=True)
38 return float(raw_value)
40 def _encode_value(self, data: float) -> bytearray:
41 """Encode rotational speed value."""
42 raw_value = int(data)
43 return DataParser.encode_int32(raw_value, signed=True)