Coverage for src / bluetooth_sig / gatt / characteristics / magnetic_declination.py: 100%
14 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"""Magnetic Declination characteristic implementation."""
3from __future__ import annotations
5from ...types.units import AngleUnit
6from .base import BaseCharacteristic
7from .templates import ScaledUint16Template
10class MagneticDeclinationCharacteristic(BaseCharacteristic[float]):
11 """Magnetic Declination characteristic (0x2A2C).
13 org.bluetooth.characteristic.magnetic_declination
15 Magnetic declination characteristic.
17 Represents the magnetic declination - the angle on the horizontal plane
18 between the direction of True North (geographic) and the direction of
19 Magnetic North, measured clockwise from True North to Magnetic North.
20 """
22 _template = ScaledUint16Template.from_letter_method(M=1, d=-2, b=0)
24 _characteristic_name: str = "Magnetic Declination"
25 _manual_unit: str = AngleUnit.DEGREES.value # Override template's "units" default
27 # Template configuration
28 resolution: float = 0.01 # 0.01 degree resolution
30 expected_type: type = float
32 def _encode_value(self, data: float) -> bytearray:
33 """Encode magnetic declination value back to bytes.
35 Args:
36 data: Magnetic declination in degrees
38 Returns:
39 Encoded bytes representing the magnetic declination (uint16, 0.01 degrees resolution)
41 """
42 declination = float(data)
44 # Normalize to 0-360 range if needed (magnetic declination can be 0-360)
45 declination = declination % 360.0
47 # Use template encoding after normalization
48 return super()._encode_value(declination)