From 18ad0bcdc41acf7d12648423e7837395398f8591 Mon Sep 17 00:00:00 2001 From: cwasicki <126617870+cwasicki@users.noreply.github.com> Date: Tue, 16 Dec 2025 14:07:00 +0100 Subject: [PATCH] Add back support for old active power formula config This supports old config formats to avoid breaking changes in downstream apps. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com> --- RELEASE_NOTES.md | 6 ++---- src/frequenz/gridpool/_microgrid_config.py | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 164ca76..b43e0f0 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -5,12 +5,10 @@ ## Upgrading -* Microgrid_config is updated from AC_ACTIVE_POWER to AC_POWER_ACTIVE in accordance with the update in client-reporting - v0.20.0 - -## New Features +* Add back support for old active power formula config `AC_ACTIVE_POWER`. -* Add CLI tool to print formulas from assets API component graph. +## New Features diff --git a/src/frequenz/gridpool/_microgrid_config.py b/src/frequenz/gridpool/_microgrid_config.py index 45f2060..a1a4fcc 100644 --- a/src/frequenz/gridpool/_microgrid_config.py +++ b/src/frequenz/gridpool/_microgrid_config.py @@ -41,11 +41,24 @@ class ComponentTypeConfig: def __post_init__(self) -> None: """Set the default formula if none is provided.""" self.formula = self.formula or {} - if "AC_POWER_ACTIVE" not in self.formula: - self.formula["AC_POWER_ACTIVE"] = "+".join( - [f"#{cid}" for cid in self._default_cids()] + if "AC_ACTIVE_POWER" in self.formula: + _logger.warning( + "ComponentTypeConfig: 'AC_ACTIVE_POWER' formula is deprecated, " + "please use 'AC_POWER_ACTIVE' instead." ) + if "AC_POWER_ACTIVE" not in self.formula: + if "AC_ACTIVE_POWER" in self.formula: + self.formula["AC_POWER_ACTIVE"] = self.formula["AC_ACTIVE_POWER"] + else: + _logger.warning( + "ComponentTypeConfig: No formula provided for 'AC_POWER_ACTIVE', " + "using default summation formula." + ) + self.formula["AC_POWER_ACTIVE"] = "+".join( + [f"#{cid}" for cid in self._default_cids()] + ) + def cids(self, metric: str = "") -> list[int]: """Get component IDs for this component.