Skip to content

Commit fef271f

Browse files
committed
Replace batteriescomponents in PowerDistributor's result types
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 2a4ba92 commit fef271f

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

src/frequenz/sdk/actor/power_distributing/power_distributing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,17 +356,17 @@ async def _run(self) -> None: # pylint: disable=too-many-locals
356356
succeeded_power=Power.from_watts(
357357
distributed_power_value - failed_power
358358
),
359-
succeeded_batteries=succeed_batteries,
359+
succeeded_components=succeed_batteries,
360360
failed_power=Power.from_watts(failed_power),
361-
failed_batteries=failed_batteries,
361+
failed_components=failed_batteries,
362362
excess_power=Power.from_watts(distribution.remaining_power),
363363
)
364364
else:
365365
succeed_batteries = set(battery_distribution.keys())
366366
response = Success(
367367
request=request,
368368
succeeded_power=Power.from_watts(distributed_power_value),
369-
succeeded_batteries=succeed_batteries,
369+
succeeded_components=succeed_batteries,
370370
excess_power=Power.from_watts(distribution.remaining_power),
371371
)
372372

src/frequenz/sdk/actor/power_distributing/result.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class _BaseResultMixin:
2222

2323
@dataclasses.dataclass
2424
class _BaseSuccessMixin:
25-
"""Result returned when setting the power succeed for all batteries."""
25+
"""Result returned when setting the power succeed for all components."""
2626

2727
succeeded_power: Power
2828
"""The part of the requested power that was successfully set."""
2929

30-
succeeded_batteries: abc.Set[int]
31-
"""The subset of batteries for which power was set successfully."""
30+
succeeded_components: abc.Set[int]
31+
"""The subset of components for which power was set successfully."""
3232

3333
excess_power: Power
3434
"""The part of the requested power that could not be fulfilled.
@@ -45,17 +45,17 @@ class _BaseSuccessMixin:
4545

4646
@dataclasses.dataclass
4747
class Success(_BaseSuccessMixin, _BaseResultMixin): # Order matters here. See above.
48-
"""Result returned when setting the power succeeded for all batteries."""
48+
"""Result returned when setting the power was successful for all components."""
4949

5050

5151
@dataclasses.dataclass
5252
class PartialFailure(_BaseSuccessMixin, _BaseResultMixin):
53-
"""Result returned when any battery failed to perform the request."""
53+
"""Result returned when some of the components had an error setting the power."""
5454

5555
failed_power: Power
5656
"""The part of the requested power that failed to be set."""
5757

58-
failed_batteries: abc.Set[int]
58+
failed_components: abc.Set[int]
5959
"""The subset of batteries for which the request failed."""
6060

6161

@@ -69,31 +69,31 @@ class Error(_BaseResultMixin):
6969

7070
@dataclasses.dataclass
7171
class PowerBounds:
72-
"""Inclusion and exclusion power bounds for requested batteries."""
72+
"""Inclusion and exclusion power bounds for the requested components."""
7373

7474
inclusion_lower: float
75-
"""The lower value of the inclusion power bounds for the requested batteries."""
75+
"""The lower value of the inclusion power bounds for the requested components."""
7676

7777
exclusion_lower: float
78-
"""The lower value of the exclusion power bounds for the requested batteries."""
78+
"""The lower value of the exclusion power bounds for the requested components."""
7979

8080
exclusion_upper: float
81-
"""The upper value of the exclusion power bounds for the requested batteries."""
81+
"""The upper value of the exclusion power bounds for the requested components."""
8282

8383
inclusion_upper: float
84-
"""The upper value of the inclusion power bounds for the requested batteries."""
84+
"""The upper value of the inclusion power bounds for the requested components."""
8585

8686

8787
@dataclasses.dataclass
8888
class OutOfBounds(_BaseResultMixin):
8989
"""Result returned when the power was not set because it was out of bounds.
9090
9191
This result happens when the originating request was done with
92-
`adjust_power = False` and the requested power is not within the batteries bounds.
92+
`adjust_power = False` and the requested power is not within the available bounds.
9393
"""
9494

9595
bounds: PowerBounds
96-
"""The power bounds for the requested batteries.
96+
"""The power bounds for the requested components.
9797
9898
If the requested power negative, then this value is the lower bound.
9999
Otherwise it is upper bound.
@@ -135,26 +135,26 @@ def handle_power_request_result(result: Result) -> None:
135135
request = Request(
136136
namespace="TestChannel",
137137
power=Power.from_watts(123.4),
138-
batteries={8, 18},
138+
component_ids={8, 18},
139139
)
140140
141141
results: list[Result] = [
142142
Success(
143143
request,
144144
succeeded_power=Power.from_watts(123.4),
145-
succeeded_batteries={8, 18},
145+
succeeded_components={8, 18},
146146
excess_power=Power.zero(),
147147
),
148148
PartialFailure(
149149
request,
150150
succeeded_power=Power.from_watts(103.4),
151-
succeeded_batteries={8},
151+
succeeded_components={8},
152152
excess_power=Power.zero(),
153-
failed_batteries={18},
153+
failed_components={18},
154154
failed_power=Power.from_watts(20.0),
155155
),
156156
OutOfBounds(request, bounds=PowerBounds(0, 0, 0, 800)),
157-
Error(request, msg="The batteries are not available"),
157+
Error(request, msg="The components are not available"),
158158
]
159159
160160
for r in results:

tests/actor/power_distributing/test_power_distributing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ async def test_battery_soc_nan(self, mocker: MockerFixture) -> None:
864864

865865
result: Result = done.pop().result()
866866
assert isinstance(result, Success)
867-
assert result.succeeded_batteries == {19}
867+
assert result.succeeded_components == {19}
868868
assert result.succeeded_power.isclose(Power.from_watts(500.0))
869869
assert result.excess_power.isclose(Power.from_watts(700.0))
870870
assert result.request == request
@@ -921,7 +921,7 @@ async def test_battery_capacity_nan(self, mocker: MockerFixture) -> None:
921921

922922
result: Result = done.pop().result()
923923
assert isinstance(result, Success)
924-
assert result.succeeded_batteries == {19}
924+
assert result.succeeded_components == {19}
925925
assert result.succeeded_power.isclose(Power.from_watts(500.0))
926926
assert result.excess_power.isclose(Power.from_watts(700.0))
927927
assert result.request == request
@@ -993,7 +993,7 @@ async def test_battery_power_bounds_nan(self, mocker: MockerFixture) -> None:
993993

994994
result: Result = done.pop().result()
995995
assert isinstance(result, Success)
996-
assert result.succeeded_batteries == {19}
996+
assert result.succeeded_components == {19}
997997
assert result.succeeded_power.isclose(Power.from_kilowatts(1.0))
998998
assert result.excess_power.isclose(Power.from_watts(200.0))
999999
assert result.request == request
@@ -1247,7 +1247,7 @@ async def test_not_all_batteries_are_working(self, mocker: MockerFixture) -> Non
12471247
assert len(done) == 1
12481248
result = done.pop().result()
12491249
assert isinstance(result, Success)
1250-
assert result.succeeded_batteries == {19}
1250+
assert result.succeeded_components == {19}
12511251
assert result.excess_power.isclose(Power.from_watts(700.0))
12521252
assert result.succeeded_power.isclose(Power.from_watts(500.0))
12531253
assert result.request == request
@@ -1307,8 +1307,8 @@ async def test_partial_failure_result(self, mocker: MockerFixture) -> None:
13071307
assert len(done) == 1
13081308
result = done.pop().result()
13091309
assert isinstance(result, PartialFailure)
1310-
assert result.succeeded_batteries == batteries - failed_batteries
1311-
assert result.failed_batteries == failed_batteries
1310+
assert result.succeeded_components == batteries - failed_batteries
1311+
assert result.failed_components == failed_batteries
13121312
assert result.succeeded_power.isclose(Power.from_watts(1000.0))
13131313
assert result.failed_power.isclose(Power.from_watts(failed_power))
13141314
assert result.excess_power.isclose(Power.from_watts(200.0))

tests/timeseries/_battery_pool/test_battery_pool_control_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ async def side_effect(inv_id: int, _: float) -> None:
243243
expected_result_pred=lambda result: isinstance(
244244
result, power_distributing.PartialFailure
245245
)
246-
and result.failed_batteries == {mocks.microgrid.battery_ids[0]},
246+
and result.failed_components == {mocks.microgrid.battery_ids[0]},
247247
)
248248

249249
# There should be an automatic retry.

0 commit comments

Comments
 (0)