API
BatteryClient
Primary class for battery interaction:
connect(),disconnect()- Manual connection managementread_once()- Synchronous convenience wrapperread_once_async()- Coroutine performing the BLE exchangestream(interval_s)- Async generator yielding repeated readssession()- Async context manager (connect/disconnect)sync()- Synchronous context manager intended for scripts/CLI
Device Discovery (New in 0.2.0)
Functions for finding Li-Time batteries and BLE devices:
discover_devices(timeout=8.0)- Async: scan for all BLE devicesdiscover_devices_sync(timeout=8.0)- Sync: scan for all BLE devicesfind_litime_batteries(timeout=8.0)- Async: find only Li-Time batteriesfind_litime_batteries_sync(timeout=8.0)- Sync: find only Li-Time batteriesformat_device_info(device, show_services=False)- Format device info for display
Logging (New in 0.2.0)
Configurable logging system:
configure_logging(level)- Set logging levelDEBUG,INFO,WARNING,ERROR- Log level constants
BatteryStatus
Dataclass with battery state fields:
voltage_v: float- Battery voltage in voltscurrent_a: float- Current in amperes (+ charging, - discharging)power_w: float- Power in wattsremaining_ah: float- Remaining capacity in amp-hourscapacity_ah: float- Total capacity in amp-hourssoc_percent: float- State of charge percentagecell_volts_v: list[float]- Individual cell voltagescell_temp_c: float- Cell temperature in Celsiusbms_temp_c: float- BMS temperature in Celsiuscharge_state: ChargeState- Enum (idle/charging/discharging)
Methods:
to_dict()- Convert to dictionaryjson()- Serialize to JSON string
ChargeState
Enum representing battery charging state:
ChargeState.IDLE- Not charging or dischargingChargeState.CHARGING- Currently chargingChargeState.DISCHARGING- Currently discharging
Exceptions
Hierarchy of battery-related exceptions:
BatteryError- Base exception for all battery operationsBatteryConnectionError- Connection/disconnection failuresProtocolError- BLE protocol or data parsing errorsBatteryTimeoutError- Operation timeout errors