From 9d8b15c5c102c0dc2d077acec53a5c4adfd4fb46 Mon Sep 17 00:00:00 2001 From: cwasicki <126617870+cwasicki@users.noreply.github.com> Date: Fri, 21 Nov 2025 17:15:43 +0100 Subject: [PATCH 1/3] Add gridpool cli tool to print formulas Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com> --- pyproject.toml | 6 ++- src/frequenz/gridpool/cli/__init__.py | 1 + src/frequenz/gridpool/cli/__main__.py | 72 +++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/frequenz/gridpool/cli/__init__.py create mode 100644 src/frequenz/gridpool/cli/__main__.py diff --git a/pyproject.toml b/pyproject.toml index 81f450c..a85fc78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,13 +28,17 @@ classifiers = [ requires-python = ">= 3.11, < 4" # TODO(cookiecutter): Remove and add more dependencies if appropriate dependencies = [ - "marshmallow-dataclass>=8.7.1,<9", + "marshmallow-dataclass >= 8.7.1, < 9", + "asyncclick >= 8.3.0.4, < 9", "typing-extensions >= 4.14.1, < 5", "frequenz-microgrid-component-graph >= 0.2.0, < 0.3", "frequenz-client-assets >= 0.2.0, < 0.3", ] dynamic = ["version"] +[project.scripts] +gridpool-cli = "frequenz.gridpool.cli.__main__:main" + [[project.authors]] name = "Frequenz Energy-as-a-Service GmbH" email = "floss@frequenz.com" diff --git a/src/frequenz/gridpool/cli/__init__.py b/src/frequenz/gridpool/cli/__init__.py new file mode 100644 index 0000000..ffedaa5 --- /dev/null +++ b/src/frequenz/gridpool/cli/__init__.py @@ -0,0 +1 @@ +"""Package for CLI tool for gridpool functionality.""" diff --git a/src/frequenz/gridpool/cli/__main__.py b/src/frequenz/gridpool/cli/__main__.py new file mode 100644 index 0000000..96cf28a --- /dev/null +++ b/src/frequenz/gridpool/cli/__main__.py @@ -0,0 +1,72 @@ +# License: MIT +# Copyright © 2025 Frequenz Energy-as-a-Service GmbH + +"""CLI tool for gridpool functionality.""" + +import os + +import asyncclick as click +from frequenz.client.assets import AssetsApiClient +from frequenz.client.common.microgrid import MicrogridId + +from frequenz.gridpool import ComponentGraphGenerator + + +@click.group() +async def cli() -> None: + """CLI tool for gridpool functionality.""" + + +@cli.command() +@click.argument("microgrid_id", type=int) +@click.option( + "--prefix", + type=str, + default="{component}", + help="Prefix format for the output (Supports {microgrid_id} and {component} placeholders).", +) +async def print_formulas( + microgrid_id: int, + prefix: str, +) -> None: + """Fetch and print component graph formulas for a microgrid.""" + url = os.environ.get("ASSETS_API_URL") + key = os.environ.get("ASSETS_API_AUTH_KEY") + secret = os.environ.get("ASSETS_API_SIGN_SECRET") + if not url or not key or not secret: + raise click.ClickException( + "ASSETS_API_URL, ASSETS_API_AUTH_KEY, ASSETS_API_SIGN_SECRET must be set." + ) + + async with AssetsApiClient( + url, + auth_key=key, + sign_secret=secret, + ) as client: + cgg = ComponentGraphGenerator(client) + + graph = await cgg.get_component_graph(MicrogridId(microgrid_id)) + power_formulas = { + "consumption": graph.consumer_formula(), + "generation": graph.producer_formula(), + "grid": graph.grid_formula(), + "pv": graph.pv_formula(None), + "battery": graph.battery_formula(None), + "chp": graph.chp_formula(None), + "ev": graph.ev_charger_formula(None), + } + + for component, formula in power_formulas.items(): + print( + prefix.format(component=component, microgrid_id=microgrid_id) + + f' = "{formula}"' + ) + + +def main() -> None: + """Run the CLI tool.""" + cli(_anyio_backend="asyncio") + + +if __name__ == "__main__": + main() From ff111d88310a3b881e036bc94f63d7f8b57187a4 Mon Sep 17 00:00:00 2001 From: cwasicki <126617870+cwasicki@users.noreply.github.com> Date: Wed, 3 Dec 2025 22:21:24 +0100 Subject: [PATCH 2/3] Minor: Remove TODO comments from pyproject Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com> --- pyproject.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a85fc78..02b66f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,6 @@ description = "High-level interface to grid pools for the Frequenz platform." readme = "README.md" license = { text = "MIT" } keywords = ["frequenz", "python", "lib", "library", "gridpool"] -# TODO(cookiecutter): Remove and add more classifiers if appropriate classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", @@ -26,7 +25,6 @@ classifiers = [ "Typing :: Typed", ] requires-python = ">= 3.11, < 4" -# TODO(cookiecutter): Remove and add more dependencies if appropriate dependencies = [ "marshmallow-dataclass >= 8.7.1, < 9", "asyncclick >= 8.3.0.4, < 9", @@ -43,7 +41,6 @@ gridpool-cli = "frequenz.gridpool.cli.__main__:main" name = "Frequenz Energy-as-a-Service GmbH" email = "floss@frequenz.com" -# TODO(cookiecutter): Remove and add more optional dependencies if appropriate [project.optional-dependencies] dev-flake8 = [ "flake8 == 7.3.0", From 7402c80157b8b22e34299701885ab2f51bb6c4f3 Mon Sep 17 00:00:00 2001 From: cwasicki <126617870+cwasicki@users.noreply.github.com> Date: Fri, 21 Nov 2025 17:35:09 +0100 Subject: [PATCH 3/3] Update release notes Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com> --- RELEASE_NOTES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d466455..bec9d27 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -10,6 +10,8 @@ ## New Features +* Add CLI tool to print formulas from assets API component graph. + ## Bug Fixes