Skip to content

Add CLI command to generate configs#98

Open
cwasicki wants to merge 6 commits into
frequenz-floss:v0.x.xfrom
cwasicki:cfg
Open

Add CLI command to generate configs#98
cwasicki wants to merge 6 commits into
frequenz-floss:v0.x.xfrom
cwasicki:cfg

Conversation

@cwasicki

Copy link
Copy Markdown
Collaborator

Add a generate-config CLI command to derive a microgrid config from the Assets API and prints it as TOML (dotted-key syntax), optionally layering --default and --override files by precedence (--default < Assets API < --override).

For this, per-type component-ID query helpers are added to the graph generator (pv_meter_ids, battery_inverter_ids, etc.), which are useful beyond config generation.

The load_configs_from_api function now derives per-type formulas and meter/inverter/component IDs from the Assets API component graph, instead of only filling in formulas. The two steps fail independently: a microgrid whose metadata can't be fetched is skipped, while one whose graph can't be derived is still returned with metadata only. Both are logged rather than aborting the batch.

Also move CLI deps to an optional cli extra including asyncclick and the new tomlkit dep. Install the CLI with pip install frequenz-gridpool[cli]; the render-graph extra pulls it in automatically.

@cwasicki cwasicki requested review from a team as code owners June 22, 2026 17:24
@cwasicki cwasicki requested review from Linus404 and shsms and removed request for a team June 22, 2026 17:24
@github-actions github-actions Bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) labels Jun 22, 2026
cwasicki added 6 commits June 22, 2026 19:24
setuptools_scm 10.0.5 imports parse_version from vcs_versioning, which was
removed in vcs_versioning 2.x. Leaving the dependency unpinned made the
build backend fail with an ImportError during version inference. Pin it
below 2 until setuptools_scm is upgraded.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Add module-level query helpers to fetch the component IDs of asset meters,
inverters, etc.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
load_configs_from_api now builds each config's component-type map
straight from the component graph: per type it derives the
AC_POWER_ACTIVE formula (skipping empty/zero ones) and the
meter/inverter/component ID lists, in a single graph fetch.

Replaces the existing funtion to populate formulas.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
asyncclick is only used by the CLI, not the library, so move it out of
the core dependencies into a new optional `cli` extra. The render-graph
extra now pulls in cli (the render-graph command needs the CLI), and the
test extra pulls it in so the cli package stays covered. Install the CLI
with `pip install frequenz-gridpool[cli]`.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Fetch metadata, formulas and component IDs for the given microgrid IDs
and print dotted-key TOML to stdout. The command is a thin wrapper over
load_configs, supporting a default and override config file.
An override file keeps its values where it has them and the API only
fills gaps. A default file is overridden by the API.
Microgrid IDs default to those found in the files; files are only read.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
load_configs_from_api now derives component IDs alongside formulas (one
derive_from_graph flag), and a generate-config CLI command is added.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
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 part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant