Add config load assets api#87
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the microgrid configuration subsystem to support loading configuration-related data directly from the Assets API and introduces reusable merge utilities to combine configuration sources more predictably.
Changes:
- Added
MicrogridConfig.load_configs_from_assets_api(...)to fetch microgrid location metadata from Assets API and optionally populate formulas. - Added
merge_microgrid_configs(...)andmerge_config_maps(...)helpers for deep-merging configs while preventingNoneoverrides. - Exported the new merge helpers in the public package API and updated release notes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/frequenz/gridpool/_microgrid_config.py |
Adds an Assets API config loader plus config-merge utilities. |
src/frequenz/gridpool/__init__.py |
Exposes the new merge helpers as part of the public API. |
RELEASE_NOTES.md |
Documents the new loader/merge helpers and includes an upgrade note that needs alignment with actual code changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if populate_formulas: | ||
| await populate_missing_formulas( | ||
| microgrid_id=microgrid_id, | ||
| config=cfg, | ||
| assets_client=client, |
| def merge_microgrid_configs( | ||
| base: MicrogridConfig, | ||
| override: MicrogridConfig, | ||
| ) -> MicrogridConfig: | ||
| """Merge two :class:`MicrogridConfig` objects. |
There was a problem hiding this comment.
Agree that tests would be good
| This release adds a new Assets API based configuration loader, introduces helpers to merge microgrid configs, and updates PV curtailability behavior to support unspecified values. | ||
|
|
||
| ## Upgrading | ||
|
|
||
| * Change the `curtailable` flag default of the PV config to `None`. | ||
| * The `PVConfig.curtailable` field now defaults to `None` and its type changed from `bool` to `bool | None`. | ||
|
|
| async def load_configs_from_assets_api( | ||
| assets_url: str, | ||
| assets_auth_key: str, | ||
| assets_sign_secret: str, | ||
| microgrid_ids: list[int], | ||
| populate_formulas: bool = True, | ||
| ) -> dict[str, "MicrogridConfig"]: |
| def merge_microgrid_configs( | ||
| base: MicrogridConfig, | ||
| override: MicrogridConfig, | ||
| ) -> MicrogridConfig: | ||
| """Merge two :class:`MicrogridConfig` objects. |
There was a problem hiding this comment.
Agree that tests would be good
| populate_formulas: | ||
| When ``True`` (default), formulas are derived from the component | ||
| graph and written into each config via | ||
| :func:`populate_missing_formulas`. Set to ``False`` to load |
There was a problem hiding this comment.
These keywords are not rendered as expected in our docs
| Returns: | ||
| dict[str, MicrogridConfig]: | ||
| Mapping from microgrid ID (as string) to the populated | ||
| ``MicrogridConfig`` instance. |
There was a problem hiding this comment.
We use markdown so single ticks are sufficient.
Signed-off-by: Mohammad Tayyab <Mohammad.Tayyab@neustrom.de>
Signed-off-by: Mohammad Tayyab <Mohammad.Tayyab@neustrom.de>
b5a50d8 to
d2306bd
Compare
Replace `:func:`/`:class:` cross-reference roles and ``double-backtick`` literals with plain single-backtick Markdown, per the project docstring style. Docs-only change, no behaviour change. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Wrap each microgrid's fetch-and-populate in load_configs_from_assets_api in a try/except: a microgrid that cannot be loaded is logged as a warning and skipped, instead of aborting the whole batch. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Cover merge_microgrid_configs and merge_config_maps. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
`generation` is not yet supported. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Formulas for all these metrics are the same. The formula name should be renamed to something more generic in the future. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
The assets-API loader calls populate_missing_formulas on a config with an empty ctype map and no explicit component_types, so the previous default (component types already present in the config) matched nothing and no formulas were ever written. Default to every derivable component type and create a ComponentTypeConfig for types not yet in the config. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Component types absent from a microgrid yield an empty formula or a bare zero constant; now that all types are derived by default, guard against storing those no-op formulas. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
|
Rebased and addressed some of the comments (while Tayyab is on vacation). @cyiallou Could you have a look at this please. |
|
LGTM! |
This PR improves how microgrid configuration data is loaded and managed (picked up functions from forecast repo). It adds support for fetching configuration-related information from Assets, including optional formula population from the component graph. It also introduces utilities to combine configuration sources more reliably through merge behavior.