Skip to content

Rework microgrid config loading API#96

Merged
cwasicki merged 11 commits into
frequenz-floss:v0.x.xfrom
cwasicki:cfg
Jun 16, 2026
Merged

Rework microgrid config loading API#96
cwasicki merged 11 commits into
frequenz-floss:v0.x.xfrom
cwasicki:cfg

Conversation

@cwasicki

Copy link
Copy Markdown
Collaborator

This release reworks the microgrid configuration loading API: the loaders are now module-level functions exported from frequenz.gridpool for loading configs from files, from the Assets API, or from both layered together.

This is also a preparation for a new CLI tool feature to simplify config file maintenance.

Upgrading

The configuration loaders are no longer MicrogridConfig static methods — they are module-level functions exported from frequenz.gridpool, and their signatures have changed:

  • MicrogridConfig.load_configs(files, dir)load_configs_from_files(files). The microgrid_config_dir argument has been removed; pass an explicit list of files instead, e.g. load_configs_from_files(list(Path(my_dir).glob("*.toml"))). Note that the name load_configs now refers to the new merge wrapper (see New Features), not the file loader.
  • MicrogridConfig.load_configs_with_formulas(assets_url, assets_auth_key, assets_sign_secret, files, dir)load_configs(default_files=files, assets_client=client, override_files=...). It now takes an AssetsApiClient you construct instead of raw credentials, and layers its sources by explicit precedence (default files < Assets API < override files) rather than the old "load files, then fill in missing formulas" behavior.

New Features

  • Added config loading functions, exported from frequenz.gridpool:
    • load_configs_from_files(...) loads microgrid configs from one or more TOML files.
    • load_configs_from_api(...) loads microgrid metadata (latitude/longitude) from the Assets API and optionally populates formulas from the component graph. Formulas are derived for all supported component types by default, and a microgrid that cannot be loaded is logged and skipped rather than aborting the whole batch.
    • load_configs(...) loads from up to three layered sources — default files, the Assets API, and override files — and merges them, with higher layers winning on conflicts. The microgrid IDs fetched from the Assets API can be given explicitly or are otherwise taken from the files.
  • Added merge_microgrid_configs(...) for deep-merging two MicrogridConfig objects where override values take precedence and None does not overwrite base values.
  • Added merge_config_maps(...) for merging two dictionaries of microgrid configs by microgrid ID.

@cwasicki cwasicki requested review from a team as code owners June 16, 2026 09:43
@cwasicki cwasicki requested review from llucax and malteschaaf and removed request for a team June 16, 2026 09:43
@github-actions github-actions Bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests labels Jun 16, 2026
cwasicki added 11 commits June 16, 2026 11:44
Both load_configs_from_assets_api and load_configs_with_formulas now
accept an AssetsApiClient instead of creating their own instance,
leaving client construction and lifecycle to the caller.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Move the metadata building into its own helper function similarly
to the formula population.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Name the file-only loader by its source, mirroring
load_configs_from_assets_api, so the loaders read as a consistent set.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
The old opaque loader will be replaced with a layered merge
wrapper shortly.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
…_from_api

The "assets_api" suffix was redundant with the module's purpose; the
shorter name reads better at call sites.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
load_configs_from_files and load_configs_from_api are static and return a
map of configs rather than an instance, so they were loader functions
wearing MicrogridConfig as a namespace. Make them module-level functions
and export them from the package.

This is a behaviour-preserving move: the function bodies are unchanged. The
only edits beyond relocating the code are the mechanical consequences of the
move.

load_from_file stays a classmethod, since it is single-file deserialization
of the model. This also sets up splitting the data model and the loading
logic into separate modules.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
A thin wrapper that composes the source loaders and combines them via
merge_config_maps in explicit layers supporting a default, API and
override structure.

The caller picks a strategy by choosing which sources to pass. The Assets
API is fetched for the IDs in microgrid_ids when given, otherwise the IDs
found in the files, so it works with no files at all. File values win over
the Assets API only where they are set; everything else is filled in.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Move the microgrid config module into a config package split along
the data model and load helpers.

The package's init re-exports the public surface so import paths are
unchanged for callers.

No behavioral change.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
It is an internal helper of the Assets API loader, not part of the public
API, so prefix it with an underscore and update the call site in
load_configs_from_api.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
The microgrid_config_dir option was just a short version of passing a
list with the file content of a folder.
Dropping it leaves the loader one clear input and removes a baked-in
"*.toml", non-recursive glob convention, letting callers choose how to
collect their files.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
@cwasicki cwasicki added this pull request to the merge queue Jun 16, 2026
Merged via the queue into frequenz-floss:v0.x.x with commit b56f06b Jun 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants