Skip to content

Commit 837c087

Browse files
committed
Add EVChargerPool.new_bounds_sender method for streaming bounds
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent f0d14ce commit 837c087

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"""Interactions with EV Chargers."""
55

66
from ._ev_charger_pool import EVChargerData, EVChargerPool, EVChargerPoolError
7+
from ._set_current_bounds import ComponentCurrentLimit
78
from ._state_tracker import EVChargerState
89

910
__all__ = [
11+
"ComponentCurrentLimit",
1012
"EVChargerPool",
1113
"EVChargerData",
1214
"EVChargerPoolError",

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
EVChargerPowerFormula,
2626
FormulaGeneratorConfig,
2727
)
28-
from ._set_current_bounds import BoundsSetter
28+
from ._set_current_bounds import BoundsSetter, ComponentCurrentLimit
2929
from ._state_tracker import EVChargerState, StateTracker
3030

3131
logger = logging.getLogger(__name__)
@@ -179,6 +179,19 @@ async def set_bounds(self, component_id: int, max_amps: float) -> None:
179179
self._bounds_setter = BoundsSetter(self._repeat_interval)
180180
await self._bounds_setter.set(component_id, max_amps)
181181

182+
def new_bounds_sender(self) -> Sender[ComponentCurrentLimit]:
183+
"""Return a `Sender` for setting EV Charger current bounds with.
184+
185+
Bounds are used to limit the max current drawn by an EV, although the exact
186+
value will be determined by the EV.
187+
188+
Returns:
189+
A new `Sender`.
190+
"""
191+
if not self._bounds_setter:
192+
self._bounds_setter = BoundsSetter(self._repeat_interval)
193+
return self._bounds_setter.new_bounds_sender()
194+
182195
async def stop(self) -> None:
183196
"""Stop all tasks and channels owned by the EVChargerPool."""
184197
if self._bounds_setter:

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from datetime import timedelta
1010
from typing import Dict
1111

12-
from frequenz.channels import Broadcast
12+
from frequenz.channels import Broadcast, Sender
1313
from frequenz.channels.util import Select, Timer
1414

1515
from ..._internal.asyncio import cancel_and_await
@@ -59,6 +59,14 @@ async def set(self, component_id: int, max_amps: float) -> None:
5959
"""
6060
await self._bounds_tx.send(ComponentCurrentLimit(component_id, max_amps))
6161

62+
def new_bounds_sender(self) -> Sender[ComponentCurrentLimit]:
63+
"""Return a `Sender` for setting EV Charger current bounds with.
64+
65+
Returns:
66+
A new `Sender`.
67+
"""
68+
return self._bounds_chan.new_sender()
69+
6270
async def stop(self) -> None:
6371
"""Stop the BoundsSetter."""
6472
await self._bounds_chan.close()

0 commit comments

Comments
 (0)