55
66import asyncio
77import logging
8- from typing import Any , Callable , Dict , List , Optional , Tuple
8+ from collections .abc import Callable
9+ from typing import Any , Dict , List , Optional , Tuple
910
1011from frequenz .channels import Receiver , Sender
1112
2324from .._channel_registry import ChannelRegistry
2425from ._component_metric_request import ComponentMetricRequest
2526
26- _MeterDataMethods : Dict [ComponentMetricId , Callable [[MeterData ], float ]] = {
27+ _MeterDataMethods : dict [ComponentMetricId , Callable [[MeterData ], float ]] = {
2728 ComponentMetricId .ACTIVE_POWER : lambda msg : msg .active_power ,
2829 ComponentMetricId .CURRENT_PHASE_1 : lambda msg : msg .current_per_phase [0 ],
2930 ComponentMetricId .CURRENT_PHASE_2 : lambda msg : msg .current_per_phase [1 ],
3435 ComponentMetricId .FREQUENCY : lambda msg : msg .frequency ,
3536}
3637
37- _BatteryDataMethods : Dict [ComponentMetricId , Callable [[BatteryData ], float ]] = {
38+ _BatteryDataMethods : dict [ComponentMetricId , Callable [[BatteryData ], float ]] = {
3839 ComponentMetricId .SOC : lambda msg : msg .soc ,
3940 ComponentMetricId .SOC_LOWER_BOUND : lambda msg : msg .soc_lower_bound ,
4041 ComponentMetricId .SOC_UPPER_BOUND : lambda msg : msg .soc_upper_bound ,
5455 ComponentMetricId .TEMPERATURE : lambda msg : msg .temperature ,
5556}
5657
57- _InverterDataMethods : Dict [ComponentMetricId , Callable [[InverterData ], float ]] = {
58+ _InverterDataMethods : dict [ComponentMetricId , Callable [[InverterData ], float ]] = {
5859 ComponentMetricId .ACTIVE_POWER : lambda msg : msg .active_power ,
5960 ComponentMetricId .ACTIVE_POWER_INCLUSION_LOWER_BOUND : lambda msg : (
6061 msg .active_power_inclusion_lower_bound
7172 ComponentMetricId .FREQUENCY : lambda msg : msg .frequency ,
7273}
7374
74- _EVChargerDataMethods : Dict [ComponentMetricId , Callable [[EVChargerData ], float ]] = {
75+ _EVChargerDataMethods : dict [ComponentMetricId , Callable [[EVChargerData ], float ]] = {
7576 ComponentMetricId .ACTIVE_POWER : lambda msg : msg .active_power ,
7677 ComponentMetricId .CURRENT_PHASE_1 : lambda msg : msg .current_per_phase [0 ],
7778 ComponentMetricId .CURRENT_PHASE_2 : lambda msg : msg .current_per_phase [1 ],
@@ -99,22 +100,20 @@ def __init__(
99100 registry: A channel registry. To be replaced by a singleton
100101 instance.
101102 """
102- self ._comp_categories_cache : Dict [int , ComponentCategory ] = {}
103+ self ._comp_categories_cache : dict [int , ComponentCategory ] = {}
103104
104- self .comp_data_receivers : Dict [int , Receiver [Any ]] = {}
105+ self .comp_data_receivers : dict [int , Receiver [Any ]] = {}
105106 """The dictionary of component IDs to data receivers."""
106107
107- self .comp_data_tasks : Dict [int , asyncio .Task [None ]] = {}
108+ self .comp_data_tasks : dict [int , asyncio .Task [None ]] = {}
108109 """The dictionary of component IDs to asyncio tasks."""
109110
110111 self ._registry = registry
111- self ._req_streaming_metrics : Dict [
112- int , Dict [ComponentMetricId , List [ComponentMetricRequest ]]
112+ self ._req_streaming_metrics : dict [
113+ int , dict [ComponentMetricId , list [ComponentMetricRequest ]]
113114 ] = {}
114115
115- async def _get_component_category (
116- self , comp_id : int
117- ) -> Optional [ComponentCategory ]:
116+ async def _get_component_category (self , comp_id : int ) -> ComponentCategory | None :
118117 """Get the component category of the given component.
119118
120119 Args:
@@ -139,7 +138,7 @@ async def _get_component_category(
139138 async def _check_battery_request (
140139 self ,
141140 comp_id : int ,
142- requests : Dict [ComponentMetricId , List [ComponentMetricRequest ]],
141+ requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
143142 ) -> None :
144143 """Check if the requests are valid Battery metrics.
145144
@@ -162,7 +161,7 @@ async def _check_battery_request(
162161 async def _check_ev_charger_request (
163162 self ,
164163 comp_id : int ,
165- requests : Dict [ComponentMetricId , List [ComponentMetricRequest ]],
164+ requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
166165 ) -> None :
167166 """Check if the requests are valid EV Charger metrics.
168167
@@ -185,7 +184,7 @@ async def _check_ev_charger_request(
185184 async def _check_inverter_request (
186185 self ,
187186 comp_id : int ,
188- requests : Dict [ComponentMetricId , List [ComponentMetricRequest ]],
187+ requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
189188 ) -> None :
190189 """Check if the requests are valid Inverter metrics.
191190
@@ -208,7 +207,7 @@ async def _check_inverter_request(
208207 async def _check_meter_request (
209208 self ,
210209 comp_id : int ,
211- requests : Dict [ComponentMetricId , List [ComponentMetricRequest ]],
210+ requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
212211 ) -> None :
213212 """Check if the requests are valid Meter metrics.
214213
@@ -232,7 +231,7 @@ async def _check_requested_component_and_metrics(
232231 self ,
233232 comp_id : int ,
234233 category : ComponentCategory ,
235- requests : Dict [ComponentMetricId , List [ComponentMetricRequest ]],
234+ requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
236235 ) -> None :
237236 """Check if the requested component and metrics are valid.
238237
@@ -289,8 +288,8 @@ def _get_data_extraction_method(
289288 def _get_metric_senders (
290289 self ,
291290 category : ComponentCategory ,
292- requests : Dict [ComponentMetricId , List [ComponentMetricRequest ]],
293- ) -> List [ Tuple [Callable [[Any ], float ], List [Sender [Sample [Quantity ]]]]]:
291+ requests : dict [ComponentMetricId , list [ComponentMetricRequest ]],
292+ ) -> list [ tuple [Callable [[Any ], float ], list [Sender [Sample [Quantity ]]]]]:
294293 """Get channel senders from the channel registry for each requested metric.
295294
296295 Args:
0 commit comments