Skip to content

Commit 3959b2e

Browse files
committed
Remove component type field from ComponentTypeConfig
This is redundant with the key of the dict entry. We may introduce it back later but at the moment it's not set in the config files. This also removes the default formula for battery SoC. This is intended as it's preferred that users explicitly set a formula for this metric instead of defaulting to a formula that only works for very specific microgrids (namely where all battery components have the same effective capacity). Signed-off-by: cwasicki <[email protected]>
1 parent b1c4300 commit 3959b2e

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/frequenz/data/microgrid/config.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
class ComponentTypeConfig:
2626
"""Configuration of a microgrid component type."""
2727

28-
component_type: ComponentType
29-
"""Type of the component."""
30-
3128
meter: list[int] | None = None
3229
"""List of meter IDs for this component."""
3330

@@ -47,12 +44,6 @@ def __post_init__(self) -> None:
4744
self.formula["AC_ACTIVE_POWER"] = "+".join(
4845
[f"#{cid}" for cid in self._default_cids()]
4946
)
50-
if self.component_type == "battery" and "BATTERY_SOC_PCT" not in self.formula:
51-
if self.component:
52-
cids = self.component
53-
form = "+".join([f"#{cid}" for cid in cids])
54-
form = f"({form})/({len(cids)})"
55-
self.formula["BATTERY_SOC_PCT"] = form
5647

5748
def cids(self, metric: str = "") -> list[int]:
5849
"""Get component IDs for this component.
@@ -76,9 +67,7 @@ def cids(self, metric: str = "") -> list[int]:
7667
raise ValueError("Formula must be a dictionary.")
7768
formula = self.formula.get(metric)
7869
if not formula:
79-
raise ValueError(
80-
f"{metric} does not have a formula for {self.component_type}"
81-
)
70+
raise ValueError(f"{metric} does not have a formula")
8271
# Extract component IDs from the formula which are given as e.g. #123
8372
pattern = r"#(\d+)"
8473
return [int(e) for e in re.findall(pattern, self.formula[metric])]
@@ -104,7 +93,7 @@ def _default_cids(self) -> list[int]:
10493
if self.component:
10594
return self.component
10695

107-
raise ValueError(f"No IDs available for {self.component_type}")
96+
raise ValueError("No IDs available")
10897

10998
@classmethod
11099
def is_valid_type(cls, ctype: str) -> bool:
@@ -222,7 +211,7 @@ def __init__(self, config_dict: dict[str, Any]) -> None:
222211
self.battery = config_dict.get("battery") or {}
223212

224213
self.ctype = {
225-
ctype: ComponentTypeConfig(component_type=cast(ComponentType, ctype), **cfg)
214+
ctype: ComponentTypeConfig(**cfg)
226215
for ctype, cfg in config_dict.get("ctype", {}).items()
227216
if ComponentTypeConfig.is_valid_type(ctype)
228217
}

0 commit comments

Comments
 (0)