3.1.5.1.2. waf_tools.battery_config_validate_utils.parse_defines_to_dataclass

waf_tools.battery_config_validate_utils.parse_defines_to_dataclass(defines: dict[str, object], cls: type[T], prefix: str, error_cls: type[RuntimeError], infix: str = '') → T

Map a flat define dictionary to a typed dataclass instance.

Iterates over the fields of the target dataclass cls and resolves each field’s value from defines by constructing the expected define name from prefix, an optional infix, and the upper-cased field name. The resolved values are then validated against the declared field type by pydantic.

The define name is constructed as follows:

  • Without infix: <PREFIX>_<FIELD_NAME> (e.g. BC_VOLTAGE_MAX_MSL_MV).

  • With infix: <PREFIX>_<FIRST_FIELD_PART>_<INFIX>_<REMAINING_FIELD_PARTS> (e.g. for field max_msl_ddegc with prefix BC_TEMPERATURE and infix DISCHARGE: BC_TEMPERATURE_MAX_DISCHARGE_MSL_DDEGC).

The infix is inserted after the first underscore-separated part of the field name, which allows a single dataclass definition to be reused for multiple directional variants (e.g. charge/discharge).

Parameters:
  • defines – Flat dictionary of define names to raw values, as returned by extract_defines().

  • cls – The target dataclass type to instantiate. Its fields define which defines are required and what types are expected.

  • prefix – The common prefix for all define names in this group (e.g. "BC_VOLTAGE", "BS").

  • error_cls – The exception class to raise on missing defines or type mismatches.

  • infix – Optional directional or categorical infix inserted into the define name (e.g. DISCHARGE, CHARGE).

Returns:

A fully populated instance of cls.

Raises:

RuntimeError – If a required define is missing from defines or if one or more values do not match the declared field type. The concrete exception type is determined by error_cls. For type mismatches the message is produced by _format_validation_error().