77import uuid
88from collections import abc
99
10- from frequenz .channels import Broadcast , Receiver , Sender
11- from frequenz .client .microgrid import ComponentCategory
12-
1310from ..._internal ._channels import ReceiverFetcher
14- from ...actor import ChannelRegistry , ComponentMetricRequest
15- from ...actor .power_distributing import ComponentPoolStatus
16- from ...microgrid import connection_manager
1711from .._base_types import SystemBounds
1812from .._quantities import Current , Power
1913from ..formula_engine import FormulaEngine , FormulaEngine3Phase
20- from ..formula_engine ._formula_engine_pool import FormulaEnginePool
2114from ..formula_engine ._formula_generators import (
2215 EVChargerCurrentFormula ,
2316 EVChargerPowerFormula ,
2417 FormulaGeneratorConfig ,
2518)
26- from ._system_bounds_tracker import EVCSystemBoundsTracker
19+ from ._ev_charger_pool_reference_store import EVChargerPoolReferenceStore
2720
2821
2922class EVChargerPoolError (Exception ):
@@ -47,10 +40,9 @@ class EVChargerPool:
4740
4841 def __init__ ( # pylint: disable=too-many-arguments
4942 self ,
50- channel_registry : ChannelRegistry ,
51- resampler_subscription_sender : Sender [ComponentMetricRequest ],
52- status_receiver : Receiver [ComponentPoolStatus ],
53- component_ids : abc .Set [int ] | None = None ,
43+ ev_charger_pool_ref : EVChargerPoolReferenceStore ,
44+ name : str | None ,
45+ priority : int ,
5446 ) -> None :
5547 """Create an `EVChargerPool` instance.
5648
@@ -60,46 +52,15 @@ def __init__( # pylint: disable=too-many-arguments
6052 method for creating `EVChargerPool` instances.
6153
6254 Args:
63- channel_registry: A channel registry instance shared with the resampling
64- actor.
65- resampler_subscription_sender: A sender for sending metric requests to the
66- resampling actor.
67- status_receiver: A receiver that streams the status of the EV Chargers in
68- the pool.
69- component_ids: An optional list of component_ids belonging to this pool. If
70- not specified, IDs of all EV Chargers in the microgrid will be fetched
71- from the component graph.
55+ ev_charger_pool_ref: The EV charger pool reference store instance.
56+ name: An optional name used to identify this instance of the pool or a
57+ corresponding actor in the logs.
58+ priority: The priority of the actor using this wrapper.
7259 """
73- self ._channel_registry : ChannelRegistry = channel_registry
74- self ._resampler_subscription_sender : Sender [ComponentMetricRequest ] = (
75- resampler_subscription_sender
76- )
77- self ._status_receiver : Receiver [ComponentPoolStatus ] = status_receiver
78- self ._component_ids : abc .Set [int ] = set ()
79- if component_ids is not None :
80- self ._component_ids = component_ids
81- else :
82- graph = connection_manager .get ().component_graph
83- self ._component_ids = {
84- evc .component_id
85- for evc in graph .components (
86- component_categories = {ComponentCategory .EV_CHARGER }
87- )
88- }
89- self ._namespace : str = f"ev-charger-pool-{ uuid .uuid4 ()} "
90- self ._formula_pool : FormulaEnginePool = FormulaEnginePool (
91- self ._namespace ,
92- self ._channel_registry ,
93- self ._resampler_subscription_sender ,
94- )
95-
96- self ._bounds_channel : Broadcast [SystemBounds ] = Broadcast (
97- name = f"System Bounds for EV Chargers: { component_ids } "
98- )
99- self ._bounds_tracker : EVCSystemBoundsTracker = EVCSystemBoundsTracker (
100- self .component_ids , self ._status_receiver , self ._bounds_channel .new_sender ()
101- )
102- self ._bounds_tracker .start ()
60+ self ._ev_charger_pool = ev_charger_pool_ref
61+ unique_id = uuid .uuid4 ()
62+ self ._source_id = unique_id if name is None else f"{ name } -{ unique_id } "
63+ self ._priority = priority
10364
10465 @property
10566 def component_ids (self ) -> abc .Set [int ]:
@@ -108,7 +69,7 @@ def component_ids(self) -> abc.Set[int]:
10869 Returns:
10970 Set of managed component IDs.
11071 """
111- return self ._component_ids
72+ return self ._ev_charger_pool . component_ids
11273
11374 @property
11475 def current (self ) -> FormulaEngine3Phase [Current ]:
@@ -126,10 +87,14 @@ def current(self) -> FormulaEngine3Phase[Current]:
12687 A FormulaEngine that will calculate and stream the total current of all EV
12788 Chargers.
12889 """
129- engine = self ._formula_pool .from_3_phase_current_formula_generator (
130- "ev_charger_total_current" ,
131- EVChargerCurrentFormula ,
132- FormulaGeneratorConfig (component_ids = self ._component_ids ),
90+ engine = (
91+ self ._ev_charger_pool .formula_pool .from_3_phase_current_formula_generator (
92+ "ev_charger_total_current" ,
93+ EVChargerCurrentFormula ,
94+ FormulaGeneratorConfig (
95+ component_ids = self ._ev_charger_pool .component_ids
96+ ),
97+ )
13398 )
13499 assert isinstance (engine , FormulaEngine3Phase )
135100 return engine
@@ -150,21 +115,21 @@ def power(self) -> FormulaEngine[Power]:
150115 A FormulaEngine that will calculate and stream the total power of all EV
151116 Chargers.
152117 """
153- engine = self ._formula_pool .from_power_formula_generator (
118+ engine = self ._ev_charger_pool . formula_pool .from_power_formula_generator (
154119 "ev_charger_power" ,
155120 EVChargerPowerFormula ,
156121 FormulaGeneratorConfig (
157- component_ids = self ._component_ids ,
122+ component_ids = self ._ev_charger_pool . component_ids ,
158123 ),
159124 )
160125 assert isinstance (engine , FormulaEngine )
161126 return engine
162127
163128 async def stop (self ) -> None :
164129 """Stop all tasks and channels owned by the EVChargerPool."""
165- await self ._formula_pool .stop ()
130+ await self ._ev_charger_pool .stop ()
166131
167132 @property
168133 def _system_power_bounds (self ) -> ReceiverFetcher [SystemBounds ]:
169134 """Return a receiver for the system power bounds."""
170- return self ._bounds_channel
135+ return self ._ev_charger_pool . bounds_channel
0 commit comments