Skip to content

Commit 4f8a27c

Browse files
Add formula engine pool to grid
The formula engine pool is needed to generate grid metrics. Signed-off-by: Daniel Zullo <[email protected]>
1 parent 338dee5 commit 4f8a27c

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/frequenz/sdk/timeseries/grid.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88
"""
99

1010
import logging
11+
import uuid
1112
from collections.abc import Iterable
1213
from dataclasses import dataclass
14+
from typing import TYPE_CHECKING
15+
16+
from frequenz.channels import Sender
1317

1418
from ..microgrid.component import Component
1519
from ..microgrid.component._component import ComponentCategory
1620
from . import Fuse
21+
from .formula_engine._formula_engine_pool import FormulaEnginePool
22+
23+
if TYPE_CHECKING:
24+
# Break circular import
25+
from ..actor import ChannelRegistry, ComponentMetricRequest
1726

1827
_logger = logging.getLogger(__name__)
1928

@@ -25,15 +34,26 @@ class Grid:
2534
fuse: Fuse
2635
"""The fuse protecting the grid connection point."""
2736

37+
_formula_pool: FormulaEnginePool
38+
"""The formula engine pool to generate grid metrics."""
39+
2840

2941
_GRID: Grid | None = None
3042

3143

32-
def initialize(components: Iterable[Component]) -> None:
44+
def initialize(
45+
components: Iterable[Component],
46+
channel_registry: ChannelRegistry,
47+
resampler_subscription_sender: Sender[ComponentMetricRequest],
48+
) -> None:
3349
"""Initialize the grid connection.
3450
3551
Args:
3652
components: The components in the microgrid.
53+
channel_registry: The channel registry instance shared with the
54+
resampling actor.
55+
resampler_subscription_sender: The sender for sending metric requests
56+
to the resampling actor.
3757
3858
Raises:
3959
RuntimeError: If there is more than 1 grid connection point in the
@@ -67,7 +87,14 @@ def initialize(components: Iterable[Component]) -> None:
6787
if fuse is None:
6888
raise RuntimeError("Grid fuse is None")
6989

70-
_GRID = Grid(fuse)
90+
namespace = f"grid-{uuid.uuid4()}"
91+
formula_pool = FormulaEnginePool(
92+
namespace,
93+
channel_registry,
94+
resampler_subscription_sender,
95+
)
96+
97+
_GRID = Grid(fuse, formula_pool)
7198

7299

73100
def get() -> Grid | None:

0 commit comments

Comments
 (0)