Utilities

This section shows general objects and helper functions that are used with this package.

Battery Discharge Characteristics

class balderhub.battery.lib.utils.battery_discharge_characteristic.BaseBatteryDischargeCharacteristic

Bases: ABC

Base Battery Discharge Characteristic that describes the discharge characteristic of a custom battery.

abstract get_inner_resistance_for(remaining_capacity_percent: float, with_load_ohm: float = 15000) float

This method returns the current battery inner resistance value in Ohm.

Parameters:
  • remaining_capacity_percent – the remaining capacity of the battery in percent (0..1)

  • with_load_ohm – the load resistance that is expected under that voltage

Returns:

abstract get_voltage_for(remaining_capacity_percent: float, with_load_ohm: float = 15000) float

This method returns the current battery voltage :param remaining_capacity_percent: the remaining capacity of the battery in percent (0..1) :param with_load_ohm: the load resistance that is expected under that voltage # TODO :return: the expected battery voltage in ohm

abstract reverse_get_level_for_voltage(voltage: float, with_load_ohm: float = 15000) float

This method is the reverse method of the BaseBatteryDischargeCharacteristic.get_voltage_for() method. It returns the expected level for the given voltage.

Parameters:
  • voltage – the voltage the expected level should be returned

  • with_load_ohm – the load resistance that is expected under that voltage # TODO

Returns:

the expected battery level (0..1)

class balderhub.battery.lib.utils.battery_discharge_characteristic.BaseDiscreteBatteryDischargeCharacteristic

Bases: BaseBatteryDischargeCharacteristic, ABC

Base discrete Battery Discharge Characteristic; needs to be overwritten and can be used for battery level tests without defining a full discharge characteristic model

abstract property edges: dict[float, tuple[float, float]]
Returns:

returns a dictionary with the battery level as key (0..1) and a tuple with the voltage and the inner resistance in Ohm as value

get_inner_resistance_for(remaining_capacity_percent: float, with_load_ohm: float = 15000) float

This method returns the current battery inner resistance value in Ohm.

Parameters:
  • remaining_capacity_percent – the remaining capacity of the battery in percent (0..1)

  • with_load_ohm – the load resistance that is expected under that voltage

Returns:

get_voltage_for(remaining_capacity_percent: float, with_load_ohm: float = 15000) float

This method returns the current battery voltage :param remaining_capacity_percent: the remaining capacity of the battery in percent (0..1) :param with_load_ohm: the load resistance that is expected under that voltage # TODO :return: the expected battery voltage in ohm

reverse_get_level_for_voltage(voltage: float, with_load_ohm: float = 15000) float

This method is the reverse method of the BaseBatteryDischargeCharacteristic.get_voltage_for() method. It returns the expected level for the given voltage.

Parameters:
  • voltage – the voltage the expected level should be returned

  • with_load_ohm – the load resistance that is expected under that voltage # TODO

Returns:

the expected battery level (0..1)

abstract property voltage_cut_off: float
Returns:

returns the CUT-OFF voltage at which the device should not work anymore

abstract property voltage_max: float
Returns:

returns the maximum voltage the battery can have (f.e. without any load)