1313from frequenz .client .microgrid import (
1414 BatteryData ,
1515 ComponentCategory ,
16- ComponentMetricId ,
1716 EVChargerData ,
1817 InverterData ,
1918 MeterData ,
2019)
20+ from frequenz .client .microgrid .metrics import Metric
2121from frequenz .quantities import Quantity
2222
2323from ..._internal ._asyncio import run_forever
2424from ..._internal ._channels import ChannelRegistry
2525from ...microgrid import connection_manager
2626from ...timeseries import Sample
27+ from .._old_component_data import (
28+ TransitionalMetric ,
29+ )
2730from ._component_metric_request import ComponentMetricRequest
2831
2932_logger = logging .getLogger (__name__ )
3033
31- _MeterDataMethods : dict [ComponentMetricId , Callable [[MeterData ], float ]] = {
32- ComponentMetricId .ACTIVE_POWER : lambda msg : msg .active_power ,
33- ComponentMetricId .ACTIVE_POWER_PHASE_1 : lambda msg : msg .active_power_per_phase [0 ],
34- ComponentMetricId .ACTIVE_POWER_PHASE_2 : lambda msg : msg .active_power_per_phase [1 ],
35- ComponentMetricId .ACTIVE_POWER_PHASE_3 : lambda msg : msg .active_power_per_phase [2 ],
36- ComponentMetricId .CURRENT_PHASE_1 : lambda msg : msg .current_per_phase [0 ],
37- ComponentMetricId .CURRENT_PHASE_2 : lambda msg : msg .current_per_phase [1 ],
38- ComponentMetricId .CURRENT_PHASE_3 : lambda msg : msg .current_per_phase [2 ],
39- ComponentMetricId .VOLTAGE_PHASE_1 : lambda msg : msg .voltage_per_phase [0 ],
40- ComponentMetricId .VOLTAGE_PHASE_2 : lambda msg : msg .voltage_per_phase [1 ],
41- ComponentMetricId .VOLTAGE_PHASE_3 : lambda msg : msg .voltage_per_phase [2 ],
42- ComponentMetricId .FREQUENCY : lambda msg : msg .frequency ,
43- ComponentMetricId .REACTIVE_POWER : lambda msg : msg .reactive_power ,
44- ComponentMetricId .REACTIVE_POWER_PHASE_1 : lambda msg : msg .reactive_power_per_phase [
45- 0
46- ],
47- ComponentMetricId .REACTIVE_POWER_PHASE_2 : lambda msg : msg .reactive_power_per_phase [
48- 1
49- ],
50- ComponentMetricId .REACTIVE_POWER_PHASE_3 : lambda msg : msg .reactive_power_per_phase [
51- 2
52- ],
34+ _MeterDataMethods : dict [Metric | TransitionalMetric , Callable [[MeterData ], float ]] = {
35+ Metric .AC_ACTIVE_POWER : lambda msg : msg .active_power ,
36+ Metric .AC_ACTIVE_POWER_PHASE_1 : lambda msg : msg .active_power_per_phase [0 ],
37+ Metric .AC_ACTIVE_POWER_PHASE_2 : lambda msg : msg .active_power_per_phase [1 ],
38+ Metric .AC_ACTIVE_POWER_PHASE_3 : lambda msg : msg .active_power_per_phase [2 ],
39+ Metric .AC_CURRENT_PHASE_1 : lambda msg : msg .current_per_phase [0 ],
40+ Metric .AC_CURRENT_PHASE_2 : lambda msg : msg .current_per_phase [1 ],
41+ Metric .AC_CURRENT_PHASE_3 : lambda msg : msg .current_per_phase [2 ],
42+ Metric .AC_VOLTAGE_PHASE_1_N : lambda msg : msg .voltage_per_phase [0 ],
43+ Metric .AC_VOLTAGE_PHASE_2_N : lambda msg : msg .voltage_per_phase [1 ],
44+ Metric .AC_VOLTAGE_PHASE_3_N : lambda msg : msg .voltage_per_phase [2 ],
45+ Metric .AC_FREQUENCY : lambda msg : msg .frequency ,
46+ Metric .AC_REACTIVE_POWER : lambda msg : msg .reactive_power ,
47+ Metric .AC_REACTIVE_POWER_PHASE_1 : lambda msg : msg .reactive_power_per_phase [0 ],
48+ Metric .AC_REACTIVE_POWER_PHASE_2 : lambda msg : msg .reactive_power_per_phase [1 ],
49+ Metric .AC_REACTIVE_POWER_PHASE_3 : lambda msg : msg .reactive_power_per_phase [2 ],
5350}
5451
55- _BatteryDataMethods : dict [ComponentMetricId , Callable [[BatteryData ], float ]] = {
56- ComponentMetricId .SOC : lambda msg : msg .soc ,
57- ComponentMetricId .SOC_LOWER_BOUND : lambda msg : msg .soc_lower_bound ,
58- ComponentMetricId .SOC_UPPER_BOUND : lambda msg : msg .soc_upper_bound ,
59- ComponentMetricId .CAPACITY : lambda msg : msg .capacity ,
60- ComponentMetricId .POWER_INCLUSION_LOWER_BOUND : lambda msg : (
52+ _BatteryDataMethods : dict [
53+ Metric | TransitionalMetric , Callable [[BatteryData ], float ]
54+ ] = {
55+ Metric .BATTERY_SOC_PCT : lambda msg : msg .soc ,
56+ TransitionalMetric .SOC_LOWER_BOUND : lambda msg : msg .soc_lower_bound ,
57+ TransitionalMetric .SOC_UPPER_BOUND : lambda msg : msg .soc_upper_bound ,
58+ Metric .BATTERY_CAPACITY : lambda msg : msg .capacity ,
59+ TransitionalMetric .POWER_INCLUSION_LOWER_BOUND : lambda msg : (
6160 msg .power_inclusion_lower_bound
6261 ),
63- ComponentMetricId .POWER_EXCLUSION_LOWER_BOUND : lambda msg : (
62+ TransitionalMetric .POWER_EXCLUSION_LOWER_BOUND : lambda msg : (
6463 msg .power_exclusion_lower_bound
6564 ),
66- ComponentMetricId .POWER_EXCLUSION_UPPER_BOUND : lambda msg : (
65+ TransitionalMetric .POWER_EXCLUSION_UPPER_BOUND : lambda msg : (
6766 msg .power_exclusion_upper_bound
6867 ),
69- ComponentMetricId .POWER_INCLUSION_UPPER_BOUND : lambda msg : (
68+ TransitionalMetric .POWER_INCLUSION_UPPER_BOUND : lambda msg : (
7069 msg .power_inclusion_upper_bound
7170 ),
72- ComponentMetricId . TEMPERATURE : lambda msg : msg .temperature ,
71+ Metric . BATTERY_TEMPERATURE : lambda msg : msg .temperature ,
7372}
7473
75- _InverterDataMethods : dict [ComponentMetricId , Callable [[InverterData ], float ]] = {
76- ComponentMetricId .ACTIVE_POWER : lambda msg : msg .active_power ,
77- ComponentMetricId .ACTIVE_POWER_PHASE_1 : lambda msg : msg .active_power_per_phase [0 ],
78- ComponentMetricId .ACTIVE_POWER_PHASE_2 : lambda msg : msg .active_power_per_phase [1 ],
79- ComponentMetricId .ACTIVE_POWER_PHASE_3 : lambda msg : msg .active_power_per_phase [2 ],
80- ComponentMetricId .ACTIVE_POWER_INCLUSION_LOWER_BOUND : lambda msg : (
74+ _InverterDataMethods : dict [
75+ Metric | TransitionalMetric , Callable [[InverterData ], float ]
76+ ] = {
77+ Metric .AC_ACTIVE_POWER : lambda msg : msg .active_power ,
78+ Metric .AC_ACTIVE_POWER_PHASE_1 : lambda msg : msg .active_power_per_phase [0 ],
79+ Metric .AC_ACTIVE_POWER_PHASE_2 : lambda msg : msg .active_power_per_phase [1 ],
80+ Metric .AC_ACTIVE_POWER_PHASE_3 : lambda msg : msg .active_power_per_phase [2 ],
81+ TransitionalMetric .ACTIVE_POWER_INCLUSION_LOWER_BOUND : lambda msg : (
8182 msg .active_power_inclusion_lower_bound
8283 ),
83- ComponentMetricId .ACTIVE_POWER_EXCLUSION_LOWER_BOUND : lambda msg : (
84+ TransitionalMetric .ACTIVE_POWER_EXCLUSION_LOWER_BOUND : lambda msg : (
8485 msg .active_power_exclusion_lower_bound
8586 ),
86- ComponentMetricId .ACTIVE_POWER_EXCLUSION_UPPER_BOUND : lambda msg : (
87+ TransitionalMetric .ACTIVE_POWER_EXCLUSION_UPPER_BOUND : lambda msg : (
8788 msg .active_power_exclusion_upper_bound
8889 ),
89- ComponentMetricId .ACTIVE_POWER_INCLUSION_UPPER_BOUND : lambda msg : (
90+ TransitionalMetric .ACTIVE_POWER_INCLUSION_UPPER_BOUND : lambda msg : (
9091 msg .active_power_inclusion_upper_bound
9192 ),
92- ComponentMetricId .CURRENT_PHASE_1 : lambda msg : msg .current_per_phase [0 ],
93- ComponentMetricId .CURRENT_PHASE_2 : lambda msg : msg .current_per_phase [1 ],
94- ComponentMetricId .CURRENT_PHASE_3 : lambda msg : msg .current_per_phase [2 ],
95- ComponentMetricId .VOLTAGE_PHASE_1 : lambda msg : msg .voltage_per_phase [0 ],
96- ComponentMetricId .VOLTAGE_PHASE_2 : lambda msg : msg .voltage_per_phase [1 ],
97- ComponentMetricId .VOLTAGE_PHASE_3 : lambda msg : msg .voltage_per_phase [2 ],
98- ComponentMetricId .FREQUENCY : lambda msg : msg .frequency ,
99- ComponentMetricId .REACTIVE_POWER : lambda msg : msg .reactive_power ,
100- ComponentMetricId .REACTIVE_POWER_PHASE_1 : lambda msg : msg .reactive_power_per_phase [
101- 0
102- ],
103- ComponentMetricId .REACTIVE_POWER_PHASE_2 : lambda msg : msg .reactive_power_per_phase [
104- 1
105- ],
106- ComponentMetricId .REACTIVE_POWER_PHASE_3 : lambda msg : msg .reactive_power_per_phase [
107- 2
108- ],
93+ Metric .AC_CURRENT_PHASE_1 : lambda msg : msg .current_per_phase [0 ],
94+ Metric .AC_CURRENT_PHASE_2 : lambda msg : msg .current_per_phase [1 ],
95+ Metric .AC_CURRENT_PHASE_3 : lambda msg : msg .current_per_phase [2 ],
96+ Metric .AC_VOLTAGE_PHASE_1_N : lambda msg : msg .voltage_per_phase [0 ],
97+ Metric .AC_VOLTAGE_PHASE_2_N : lambda msg : msg .voltage_per_phase [1 ],
98+ Metric .AC_VOLTAGE_PHASE_3_N : lambda msg : msg .voltage_per_phase [2 ],
99+ Metric .AC_FREQUENCY : lambda msg : msg .frequency ,
100+ Metric .AC_REACTIVE_POWER : lambda msg : msg .reactive_power ,
101+ Metric .AC_REACTIVE_POWER_PHASE_1 : lambda msg : msg .reactive_power_per_phase [0 ],
102+ Metric .AC_REACTIVE_POWER_PHASE_2 : lambda msg : msg .reactive_power_per_phase [1 ],
103+ Metric .AC_REACTIVE_POWER_PHASE_3 : lambda msg : msg .reactive_power_per_phase [2 ],
109104}
110105
111- _EVChargerDataMethods : dict [ComponentMetricId , Callable [[EVChargerData ], float ]] = {
112- ComponentMetricId .ACTIVE_POWER : lambda msg : msg .active_power ,
113- ComponentMetricId .ACTIVE_POWER_PHASE_1 : lambda msg : msg .active_power_per_phase [0 ],
114- ComponentMetricId .ACTIVE_POWER_PHASE_2 : lambda msg : msg .active_power_per_phase [1 ],
115- ComponentMetricId .ACTIVE_POWER_PHASE_3 : lambda msg : msg .active_power_per_phase [2 ],
116- ComponentMetricId .CURRENT_PHASE_1 : lambda msg : msg .current_per_phase [0 ],
117- ComponentMetricId .CURRENT_PHASE_2 : lambda msg : msg .current_per_phase [1 ],
118- ComponentMetricId .CURRENT_PHASE_3 : lambda msg : msg .current_per_phase [2 ],
119- ComponentMetricId .VOLTAGE_PHASE_1 : lambda msg : msg .voltage_per_phase [0 ],
120- ComponentMetricId .VOLTAGE_PHASE_2 : lambda msg : msg .voltage_per_phase [1 ],
121- ComponentMetricId .VOLTAGE_PHASE_3 : lambda msg : msg .voltage_per_phase [2 ],
122- ComponentMetricId .FREQUENCY : lambda msg : msg .frequency ,
123- ComponentMetricId .REACTIVE_POWER : lambda msg : msg .reactive_power ,
124- ComponentMetricId .REACTIVE_POWER_PHASE_1 : lambda msg : msg .reactive_power_per_phase [
125- 0
126- ],
127- ComponentMetricId .REACTIVE_POWER_PHASE_2 : lambda msg : msg .reactive_power_per_phase [
128- 1
129- ],
130- ComponentMetricId .REACTIVE_POWER_PHASE_3 : lambda msg : msg .reactive_power_per_phase [
131- 2
132- ],
106+ _EVChargerDataMethods : dict [
107+ Metric | TransitionalMetric , Callable [[EVChargerData ], float ]
108+ ] = {
109+ Metric .AC_ACTIVE_POWER : lambda msg : msg .active_power ,
110+ Metric .AC_ACTIVE_POWER_PHASE_1 : lambda msg : msg .active_power_per_phase [0 ],
111+ Metric .AC_ACTIVE_POWER_PHASE_2 : lambda msg : msg .active_power_per_phase [1 ],
112+ Metric .AC_ACTIVE_POWER_PHASE_3 : lambda msg : msg .active_power_per_phase [2 ],
113+ Metric .AC_CURRENT_PHASE_1 : lambda msg : msg .current_per_phase [0 ],
114+ Metric .AC_CURRENT_PHASE_2 : lambda msg : msg .current_per_phase [1 ],
115+ Metric .AC_CURRENT_PHASE_3 : lambda msg : msg .current_per_phase [2 ],
116+ Metric .AC_VOLTAGE_PHASE_1_N : lambda msg : msg .voltage_per_phase [0 ],
117+ Metric .AC_VOLTAGE_PHASE_2_N : lambda msg : msg .voltage_per_phase [1 ],
118+ Metric .AC_VOLTAGE_PHASE_3_N : lambda msg : msg .voltage_per_phase [2 ],
119+ Metric .AC_FREQUENCY : lambda msg : msg .frequency ,
120+ Metric .AC_REACTIVE_POWER : lambda msg : msg .reactive_power ,
121+ Metric .AC_REACTIVE_POWER_PHASE_1 : lambda msg : msg .reactive_power_per_phase [0 ],
122+ Metric .AC_REACTIVE_POWER_PHASE_2 : lambda msg : msg .reactive_power_per_phase [1 ],
123+ Metric .AC_REACTIVE_POWER_PHASE_3 : lambda msg : msg .reactive_power_per_phase [2 ],
133124}
134125
135126
@@ -159,7 +150,7 @@ def __init__(
159150
160151 self ._registry = registry
161152 self ._req_streaming_metrics : dict [
162- ComponentId , dict [ComponentMetricId , list [ComponentMetricRequest ]]
153+ ComponentId , dict [Metric | TransitionalMetric , list [ComponentMetricRequest ]]
163154 ] = {}
164155
165156 async def _get_component_category (
@@ -189,7 +180,7 @@ async def _get_component_category(
189180 async def _check_battery_request (
190181 self ,
191182 comp_id : ComponentId ,
192- requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
183+ requests : dict [Metric | TransitionalMetric , list [ComponentMetricRequest ]],
193184 ) -> None :
194185 """Check if the requests are valid Battery metrics.
195186
@@ -214,7 +205,7 @@ async def _check_battery_request(
214205 async def _check_ev_charger_request (
215206 self ,
216207 comp_id : ComponentId ,
217- requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
208+ requests : dict [Metric | TransitionalMetric , list [ComponentMetricRequest ]],
218209 ) -> None :
219210 """Check if the requests are valid EV Charger metrics.
220211
@@ -239,7 +230,7 @@ async def _check_ev_charger_request(
239230 async def _check_inverter_request (
240231 self ,
241232 comp_id : ComponentId ,
242- requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
233+ requests : dict [Metric | TransitionalMetric , list [ComponentMetricRequest ]],
243234 ) -> None :
244235 """Check if the requests are valid Inverter metrics.
245236
@@ -264,7 +255,7 @@ async def _check_inverter_request(
264255 async def _check_meter_request (
265256 self ,
266257 comp_id : ComponentId ,
267- requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
258+ requests : dict [Metric | TransitionalMetric , list [ComponentMetricRequest ]],
268259 ) -> None :
269260 """Check if the requests are valid Meter metrics.
270261
@@ -290,7 +281,7 @@ async def _check_requested_component_and_metrics(
290281 self ,
291282 comp_id : ComponentId ,
292283 category : ComponentCategory ,
293- requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
284+ requests : dict [Metric | TransitionalMetric , list [ComponentMetricRequest ]],
294285 ) -> None :
295286 """Check if the requested component and metrics are valid.
296287
@@ -321,7 +312,7 @@ async def _check_requested_component_and_metrics(
321312 raise ValueError (err )
322313
323314 def _get_data_extraction_method (
324- self , category : ComponentCategory , metric : ComponentMetricId
315+ self , category : ComponentCategory , metric : Metric | TransitionalMetric
325316 ) -> Callable [[Any ], float ]:
326317 """Get the data extraction method for the given metric.
327318
@@ -351,7 +342,7 @@ def _get_data_extraction_method(
351342 def _get_metric_senders (
352343 self ,
353344 category : ComponentCategory ,
354- requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
345+ requests : dict [Metric | TransitionalMetric , list [ComponentMetricRequest ]],
355346 ) -> list [tuple [Callable [[Any ], float ], list [Sender [Sample [Quantity ]]]]]:
356347 """Get channel senders from the channel registry for each requested metric.
357348
@@ -484,15 +475,15 @@ async def add_metric(self, request: ComponentMetricRequest) -> None:
484475 return
485476
486477 self ._req_streaming_metrics .setdefault (comp_id , {}).setdefault (
487- request .metric_id , []
478+ request .metric , []
488479 )
489480
490- for existing_request in self ._req_streaming_metrics [comp_id ][request .metric_id ]:
481+ for existing_request in self ._req_streaming_metrics [comp_id ][request .metric ]:
491482 if existing_request .get_channel_name () == request .get_channel_name ():
492483 # the requested metric is already being handled, so nothing to do.
493484 return
494485
495- self ._req_streaming_metrics [comp_id ][request .metric_id ].append (request )
486+ self ._req_streaming_metrics [comp_id ][request .metric ].append (request )
496487
497488 await self ._update_streams (
498489 comp_id ,
0 commit comments