Coverage for src / bluetooth_sig / types / battery.py: 76%
50 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"""Battery-related enumerations for power state characteristics.
3Defines enums for battery charge states, charge levels, charging types,
4and fault reasons to replace string usage with type-safe alternatives.
5"""
7from __future__ import annotations
9from enum import IntEnum
12class PowerConnectionState(IntEnum):
13 """Power connection state enumeration."""
15 NO = 0
16 YES = 1
17 UNKNOWN = 2
18 RFU = 3
21class BatteryChargeState(IntEnum):
22 """Battery charge state enumeration."""
24 UNKNOWN = 0
25 CHARGING = 1
26 DISCHARGING = 2
27 NOT_CHARGING = 3
29 @classmethod
30 def from_byte(cls, byte_val: int) -> BatteryChargeState:
31 """Create enum from byte value with fallback."""
32 try:
33 return cls(byte_val)
34 except ValueError:
35 return cls.UNKNOWN
38class BatteryChargeLevel(IntEnum):
39 """Battery charge level enumeration."""
41 UNKNOWN = 0
42 GOOD = 1
43 LOW = 2
44 CRITICALLY_LOW = 3
46 @classmethod
47 def from_byte(cls, byte_val: int) -> BatteryChargeLevel:
48 """Create enum from byte value with fallback."""
49 try:
50 return cls(byte_val)
51 except ValueError:
52 return cls.UNKNOWN
55class BatteryChargingType(IntEnum):
56 """Battery charging type enumeration."""
58 UNKNOWN = 0
59 CONSTANT_CURRENT = 1
60 CONSTANT_VOLTAGE = 2
61 TRICKLE = 3
62 FLOAT = 4
64 @classmethod
65 def from_byte(cls, byte_val: int) -> BatteryChargingType:
66 """Create enum from byte value with fallback."""
67 try:
68 return cls(byte_val)
69 except ValueError:
70 return cls.UNKNOWN
73class ServiceRequiredState(IntEnum):
74 """Service required state enumeration."""
76 FALSE = 0
77 TRUE = 1
78 UNKNOWN = 2
79 RFU = 3
82class BatteryFaultReason(IntEnum):
83 """Battery fault reason enumeration."""
85 BATTERY_FAULT = 0
86 EXTERNAL_POWER_FAULT = 1
87 OTHER_FAULT = 2