Rework microgrid config loading API#96
Merged
Merged
Conversation
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>
Mohammad-Tayyab-Frequenz
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This release reworks the microgrid configuration loading API: the loaders are now module-level functions exported from
frequenz.gridpoolfor 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
MicrogridConfigstatic methods — they are module-level functions exported fromfrequenz.gridpool, and their signatures have changed:MicrogridConfig.load_configs(files, dir)→load_configs_from_files(files). Themicrogrid_config_dirargument 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 nameload_configsnow 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 anAssetsApiClientyou 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
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.merge_microgrid_configs(...)for deep-merging twoMicrogridConfigobjects where override values take precedence andNonedoes not overwrite base values.merge_config_maps(...)for merging two dictionaries of microgrid configs by microgrid ID.