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

1"""Rotational Speed characteristic implementation.""" 

2 

3from __future__ import annotations 

4 

5from ..context import CharacteristicContext 

6from .base import BaseCharacteristic 

7from .utils.data_parser import DataParser 

8 

9 

10class RotationalSpeedCharacteristic(BaseCharacteristic[float]): 

11 """Rotational Speed characteristic (0x2C09). 

12 

13 org.bluetooth.characteristic.rotational_speed 

14 

15 The Rotational Speed characteristic is used to represent the rotational speed of an object 

16 rotating around a device-specific axis. 

17 """ 

18 

19 _manual_unit: str | None = "RPM" # YAML ID mismatch: has rotational_speed.*, should be angular_velocity.* 

20 

21 def _decode_value(self, data: bytearray, ctx: CharacteristicContext | None = None) -> float | None: 

22 """Decode rotational speed characteristic. 

23 

24 Decodes a 32-bit signed integer representing speed in RPM 

25 per Bluetooth SIG Rotational Speed characteristic specification. 

26 

27 Args: 

28 data: Raw bytes from BLE characteristic (exactly 4 bytes, little-endian) 

29 ctx: Optional context for parsing (device info, flags, etc.) 

30 

31 Returns: 

32 Rotational speed in revolutions per minute (RPM), or None if value is not known 

33 

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) 

39 

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)