hub.battery – Battery¶
The battery module lets you monitor the state and health of the battery.
-
hub.battery.voltage() → int¶ Gets the battery voltage.
- Returns
The voltage in in mV.
-
hub.battery.current() → int¶ Gets current flowing out of the battery.
- Returns
The current in in mA.
-
hub.battery.capacity_left() → int¶ Gets the remaining capacity as a percentage of a fully charged battery.
- Returns
The remaining battery capacity.
-
hub.battery.temperature() → float¶ Gets the temperature of the battery.
- Returns
The temperature in degrees Celsius.
-
hub.battery.charger_detect() → Union[bool, int]¶ Checks what type of charger was detected.
- Returns
See
charging constantsfor all possible return values. ReturnsFalseif it failed to detect a charger.
-
hub.battery.info() → dict¶ Gets status information about the battery.
This returns a dictionary of the form:
{ # Battery measurements as documented above. 'battery_capacity_left': 100 'temperature': 25.7, 'charge_current': 248, 'charge_voltage': 8294, # Filtered version of the battery voltage. 'charge_voltage_filtered': 8287, # A list of active errors. See constants given below. 'error_state': [0], # Charging state. See constants given below. 'charger_state': 2, }
- Returns
Battery status information.
Constants¶
Battery status values
-
hub.battery.BATTERY_NO_ERROR= 0¶ The battery is happy.
-
hub.battery.BATTERY_HUB_TEMPERATURE_CRITICAL_OUT_OF_RANGE= -1¶ The battery temperature is outside of the expected range.
-
hub.battery.BATTERY_TEMPERATURE_OUT_OF_RANGE= -2¶ The battery temperature is outside of the critical range.
-
hub.battery.BATTERY_TEMPERATURE_SENSOR_FAIL= -3¶ The battery temperature sensor is not working.
-
hub.battery.BATTERY_BAD_BATTERY= -4¶ Something is wrong with the battery.
-
hub.battery.BATTERY_VOLTAGE_TOO_LOW= -5¶ The battery voltage is too low.
-
hub.battery.BATTERY_MISSING= -6¶ No battery detected.
Charger types
-
hub.battery.USB_CH_PORT_NONE= 0¶ No charger detected.
-
hub.battery.USB_CH_PORT_SDP= 1¶ Standard downstream port (typical USB port).
-
hub.battery.USB_CH_PORT_CDP= 2¶ Charging Downstream Port (wall charger).
-
hub.battery.USB_CH_PORT_DCP= 3¶ Dedicated charging port (high current USB port).
Charging states
-
hub.battery.CHARGER_STATE_FAIL= -1¶ There was a problem charging the battery.
-
hub.battery.CHARGER_STATE_DISCHARGING= 0¶ The battery is discharging.
-
hub.battery.CHARGER_STATE_CHARGING_ONGOING= 1¶ The battery is charging.
-
hub.battery.CHARGER_STATE_CHARGING_COMPLETED= 2¶ The battery is fully charged.