Skip to content

Commit 155508c

Browse files
committed
Rename BatteryPool -> BatteryPoolReferenceStore
Also make it a private module. In a subsequent commit, the current `BatteryPoolWrapper` will be renamed to `BatteryPool`, as the only public interface. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 3123dbd commit 155508c

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
Request,
3939
Result,
4040
)
41-
from ..timeseries.battery_pool import BatteryPool, BatteryPoolWrapper
41+
from ..timeseries.battery_pool import BatteryPoolWrapper
42+
from ..timeseries.battery_pool._battery_pool_reference_store import (
43+
BatteryPoolReferenceStore,
44+
)
4245
from ..timeseries.ev_charger_pool import EVChargerPool
4346
from ..timeseries.logical_meter import LogicalMeter
4447

@@ -110,7 +113,7 @@ def __init__(
110113

111114
self._logical_meter: LogicalMeter | None = None
112115
self._ev_charger_pools: dict[frozenset[int], EVChargerPool] = {}
113-
self._battery_pools: dict[frozenset[int], BatteryPool] = {}
116+
self._battery_pools: dict[frozenset[int], BatteryPoolReferenceStore] = {}
114117
self._frequency_pool: dict[int, GridFrequency] = {}
115118

116119
def frequency(self, component: Component | None = None) -> GridFrequency:
@@ -206,7 +209,10 @@ def battery_pool(
206209
Returns:
207210
A BatteryPoolWrapper instance.
208211
"""
209-
from ..timeseries.battery_pool import BatteryPool, BatteryPoolWrapper
212+
from ..timeseries.battery_pool import BatteryPoolWrapper
213+
from ..timeseries.battery_pool._battery_pool_reference_store import (
214+
BatteryPoolReferenceStore,
215+
)
210216

211217
if not self._power_managing_actor:
212218
self._start_power_managing_actor()
@@ -217,7 +223,7 @@ def battery_pool(
217223
key = frozenset(battery_ids)
218224

219225
if key not in self._battery_pools:
220-
self._battery_pools[key] = BatteryPool(
226+
self._battery_pools[key] = BatteryPoolReferenceStore(
221227
channel_registry=self._channel_registry,
222228
resampler_subscription_sender=self._resampling_request_sender(),
223229
batteries_status_receiver=self._battery_status_channel.new_receiver(

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
from ._battery_pool_wrapper import BatteryPoolWrapper
77
from ._result_types import PowerMetrics
8-
from .battery_pool import BatteryPool
98

109
__all__ = [
11-
"BatteryPool",
1210
"BatteryPoolWrapper",
1311
"PowerMetrics",
1412
]

src/frequenz/sdk/timeseries/battery_pool/battery_pool.py renamed to src/frequenz/sdk/timeseries/battery_pool/_battery_pool_reference_store.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@
2121
from ._methods import MetricAggregator
2222

2323

24-
class BatteryPool: # pylint: disable=too-many-instance-attributes
25-
"""A class for maintaining the state/tasks for a set of pool of batteries.
24+
class BatteryPoolReferenceStore: # pylint: disable=too-many-instance-attributes
25+
"""A class for maintaining the shared state/tasks for a set of pool of batteries.
26+
27+
This includes ownership of
28+
- the formula engine pool and metric calculators.
29+
- the tasks for updating the battery status for the metric calculators.
30+
31+
These are independent of the priority of the actors, and can be shared between
32+
multiple users of the same set of batteries.
2633
2734
They are exposed through the BatteryPoolWrapper class.
2835
"""

src/frequenz/sdk/timeseries/battery_pool/_battery_pool_wrapper.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
FormulaGeneratorConfig,
2424
FormulaType,
2525
)
26+
from ._battery_pool_reference_store import BatteryPoolReferenceStore
2627
from ._methods import SendOnUpdate
2728
from ._metric_calculator import (
2829
CapacityCalculator,
@@ -31,29 +32,33 @@
3132
TemperatureCalculator,
3233
)
3334
from ._result_types import PowerMetrics
34-
from .battery_pool import BatteryPool
3535

3636
# pylint: disable=protected-access
3737

3838

3939
class BatteryPoolWrapper:
4040
"""The BatteryPoolWrapper is the external interface for the BatteryPool.
4141
42-
BatteryPool instances are unique to a set of batteries. The BatteryPoolWrapper
43-
provides an abstraction over actor priorities when multiple actors want to use the
44-
same set of batteries.
42+
BatteryPoolReferenceStore instances are unique to a set of batteries. The
43+
BatteryPoolWrapper provides an abstraction over actor priorities when multiple
44+
actors want to use the same set of batteries.
4545
"""
4646

47-
def __init__(self, battery_pool: BatteryPool, name: str | None, priority: int):
47+
def __init__(
48+
self,
49+
battery_pool_ref: BatteryPoolReferenceStore,
50+
name: str | None,
51+
priority: int,
52+
):
4853
"""Create a BatteryPoolWrapper instance.
4954
5055
Args:
51-
battery_pool: The battery pool to wrap.
56+
battery_pool_ref: The battery pool reference store instance.
5257
name: An optional name used to identify this instance of the pool or a
5358
corresponding actor in the logs.
5459
priority: The priority of the actor using this wrapper.
5560
"""
56-
self._battery_pool = battery_pool
61+
self._battery_pool = battery_pool_ref
5762
unique_id = str(uuid.uuid4())
5863
self._source_id = unique_id if name is None else f"{name}-{unique_id}"
5964
self._priority = priority

0 commit comments

Comments
 (0)