load
frequenz.gridpool.config.load ¤
Loading and merging of microgrid configurations.
Attributes¤
Classes¤
Functions:¤
frequenz.gridpool.config.load.load_configs
async
¤
load_configs(
default_files: (
str | Path | list[str | Path] | None
) = None,
assets_client: AssetsApiClient | None = None,
override_files: (
str | Path | list[str | Path] | None
) = None,
microgrid_ids: list[int] | None = None,
) -> dict[str, MicrogridConfig]
Load configs from up to three sources and merge them in layers.
Combines up to three sources, listed here from lowest to highest precedence: a default config file layer, the Assets API, and an override config file layer. Higher layers win on conflicts, while lower layers fill in anything the higher ones leave unset. This lets callers pick a strategy by choosing which sources to pass, for example:
default_files+assets_client: files provide defaults that the Assets API overrides.assets_client+override_files: the Assets API provides the base that files override.- all three: the Assets API sits between a default and an override file layer.
The microgrid IDs fetched from the Assets API are microgrid_ids when
given, otherwise the IDs found in the default and override files. This
lets the Assets API layer be used even when no files are given.
| PARAMETER | DESCRIPTION |
|---|---|
default_files
|
Optional path or list of paths to config files forming the lowest-precedence layer. |
assets_client
|
Optional Assets API client. When given, microgrid metadata and formulas are fetched and layered above the default files.
TYPE:
|
override_files
|
Optional path or list of paths to config files forming the highest-precedence layer. |
microgrid_ids
|
Optional explicit microgrid IDs to fetch from the Assets API. When given, these replace the IDs derived from the files, so the Assets API layer can be used without any files. |
| RETURNS | DESCRIPTION |
|---|---|
dict[str, MicrogridConfig]
|
dict[str, MicrogridConfig]:
Mapping from microgrid ID (as string) to the merged
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If none of the three sources is provided, or if
|
Source code in src/frequenz/gridpool/config/load.py
frequenz.gridpool.config.load.load_configs_from_api
async
¤
load_configs_from_api(
assets_client: AssetsApiClient, microgrid_ids: list[int]
) -> dict[str, MicrogridConfig]
Load microgrid configs from the Assets API.
For each microgrid, fetches its location metadata (latitude, longitude) and then derives the per-type formulas and meter/inverter/component IDs from its component graph. This is the canonical single-source loader so that callers (e.g. the forecast pipeline) do not have to re-implement this logic.
The two steps fail independently: a microgrid whose metadata cannot be fetched is skipped, while one whose component graph cannot be derived is still returned with metadata only. Both failures are logged as warnings.
| PARAMETER | DESCRIPTION |
|---|---|
assets_client
|
Assets API client used to fetch microgrid metadata and the component graph.
TYPE:
|
microgrid_ids
|
List of microgrid IDs to load configurations for. |
| RETURNS | DESCRIPTION |
|---|---|
dict[str, MicrogridConfig]
|
dict[str, MicrogridConfig]:
Mapping from microgrid ID (as string) to the loaded
|
Source code in src/frequenz/gridpool/config/load.py
frequenz.gridpool.config.load.load_configs_from_files ¤
load_configs_from_files(
microgrid_config_files: (
str | Path | list[str | Path] | None
) = None,
) -> dict[str, MicrogridConfig]
Load multiple microgrid configurations from one or more files.
Configs for a single microgrid are expected to be in a single file. Later files with the same microgrid ID will overwrite the previous configs.
| PARAMETER | DESCRIPTION |
|---|---|
microgrid_config_files
|
Path to a single microgrid config file or list of paths. |
| RETURNS | DESCRIPTION |
|---|---|
dict[str, MicrogridConfig]
|
Dictionary of single microgrid formula configs with microgrid IDs as keys. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no config files are provided, or if no config files are found. |