Skip to content

Commit 69f5c06

Browse files
committed
Add functions to fetch current and power for individual ev chargers
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent f031cd9 commit 69f5c06

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/frequenz/sdk/timeseries/ev_charger_pool/_ev_charger_pool.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
logger = logging.getLogger(__name__)
2525

2626

27+
class EVChargerPoolError(Exception):
28+
"""An error that occurred in any of the EVChargerPool methods."""
29+
30+
2731
class EVChargerPool:
2832
"""Interactions with EV Chargers."""
2933

@@ -111,3 +115,50 @@ async def total_power(self) -> FormulaReceiver:
111115
EVChargerPowerFormula,
112116
FormulaGeneratorConfig(component_ids=self._component_ids),
113117
)
118+
119+
async def current(self, component_id: int) -> FormulaReceiver3Phase:
120+
"""Fetch the 3-phase current for the given ev_charger id.
121+
122+
Args:
123+
component_id: id of the ev charger to stream current values for.
124+
125+
Returns:
126+
A *new* receiver that will stream 3-phase current values for the given
127+
ev charger.
128+
129+
Raises:
130+
EVChargerPoolError: if the given component_id is not part of the pool.
131+
"""
132+
if component_id not in self._component_ids:
133+
raise EVChargerPoolError(
134+
f"{component_id=} is not part of the EVChargerPool"
135+
f" (with ids={self._component_ids})"
136+
)
137+
return await self._formula_pool.from_generator(
138+
f"ev_charger_current_{component_id}",
139+
EVChargerCurrentFormula,
140+
FormulaGeneratorConfig(component_ids={component_id}),
141+
)
142+
143+
async def power(self, component_id: int) -> FormulaReceiver:
144+
"""Fetch the power for the given ev_charger id.
145+
146+
Args:
147+
component_id: id of the ev charger to stream power values for.
148+
149+
Returns:
150+
A *new* receiver that will stream power values for the given ev charger.
151+
152+
Raises:
153+
EVChargerPoolError: if the given component_id is not part of the pool.
154+
"""
155+
if component_id not in self._component_ids:
156+
raise EVChargerPoolError(
157+
f"{component_id=} is not part of the EVChargerPool"
158+
f" (with ids={self._component_ids})"
159+
)
160+
return await self._formula_pool.from_generator(
161+
f"ev_charger_current_{component_id}",
162+
EVChargerPowerFormula,
163+
FormulaGeneratorConfig(component_ids={component_id}),
164+
)

0 commit comments

Comments
 (0)