Skip to content

Commit a7e380b

Browse files
authored
Remove obsolete type TargetComponents (#167)
2 parents c7ee3cc + 26862b6 commit a7e380b

File tree

4 files changed

+10
-30
lines changed

4 files changed

+10
-30
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Upgrading
88

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
9+
The `frequenz.disptach.TargetComponents` tye was removed, use `frequenz.client.dispatch.TargetComponents` instead.
1010

1111
## New Features
1212

src/frequenz/dispatch/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
"""
1717

18-
from ._actor_dispatcher import ActorDispatcher, DispatchInfo, TargetComponents
18+
from ._actor_dispatcher import ActorDispatcher, DispatchInfo
1919
from ._bg_service import MergeStrategy
2020
from ._dispatch import Dispatch
2121
from ._dispatcher import Dispatcher
@@ -34,5 +34,4 @@
3434
"MergeStrategy",
3535
"MergeByType",
3636
"MergeByTypeTarget",
37-
"TargetComponents",
3837
]

src/frequenz/dispatch/_actor_dispatcher.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,18 @@
88
from collections.abc import Callable
99
from dataclasses import dataclass
1010
from datetime import timedelta
11-
from typing import Any, Awaitable, cast
11+
from typing import Any, Awaitable
1212

1313
from frequenz.channels import Broadcast, Receiver, Sender, select
1414
from frequenz.channels.timer import SkipMissedAndDrift, Timer
15-
from frequenz.client.common.microgrid.components import ComponentCategory, ComponentId
16-
from frequenz.client.dispatch.types import DispatchId
17-
from frequenz.client.dispatch.types import TargetComponents as ClientTargetComponents
15+
from frequenz.client.dispatch.types import DispatchId, TargetComponents
1816
from frequenz.core.id import BaseId
1917
from frequenz.sdk.actor import Actor, BackgroundService
2018

2119
from ._dispatch import Dispatch
2220

2321
_logger = logging.getLogger(__name__)
2422

25-
TargetComponents = list[ComponentId] | list[ComponentCategory]
26-
"""One or more target components specifying which components a dispatch targets.
27-
28-
It can be a list of component IDs or a list of categories.
29-
"""
30-
3123

3224
class DispatchActorId(BaseId, str_prefix="DA"):
3325
"""ID for a dispatch actor."""
@@ -208,7 +200,7 @@ def start(self) -> None:
208200
async def _start_actor(self, dispatch: Dispatch) -> None:
209201
"""Start the actor the given dispatch refers to."""
210202
dispatch_update = DispatchInfo(
211-
components=_convert_target_components(dispatch.target),
203+
components=dispatch.target,
212204
dry_run=dispatch.dry_run,
213205
options=dispatch.payload,
214206
_src=dispatch,
@@ -305,13 +297,3 @@ async def _handle_dispatch(self, dispatch: Dispatch) -> None:
305297
await self._start_actor(dispatch)
306298
else:
307299
await self._stop_actor(dispatch, "Dispatch stopped")
308-
309-
310-
def _convert_target_components(target: ClientTargetComponents) -> TargetComponents:
311-
if all(isinstance(comp, int) for comp in target):
312-
# We've confirmed all elements are integers, so we can cast.
313-
int_components = cast(list[int], target)
314-
return [ComponentId(cid) for cid in int_components]
315-
# If not all are ints, then it must be a list of ComponentCategory
316-
# based on the definition of ClientTargetComponents.
317-
return cast(list[ComponentCategory], target)

tests/test_managing_actor.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
MergeByTypeTarget,
3434
MergeStrategy,
3535
)
36-
from frequenz.dispatch._actor_dispatcher import (
37-
DispatchActorId,
38-
_convert_target_components,
39-
)
36+
from frequenz.dispatch._actor_dispatcher import DispatchActorId
4037
from frequenz.dispatch._bg_service import DispatchScheduler
4138

4239

@@ -180,7 +177,9 @@ async def test_simple_start_stop(
180177

181178
event = test_env.actor(1).initial_dispatch
182179
assert event.options == {"test": True}
183-
assert event.components == [ComponentId(1), ComponentId(10), ComponentId(15)]
180+
assert event.components == TargetIds(
181+
ComponentId(1), ComponentId(10), ComponentId(15)
182+
)
184183
assert event.dry_run is False
185184

186185
assert test_env.actor(1).is_running is True
@@ -310,7 +309,7 @@ async def test_dry_run(test_env: _TestEnv, fake_time: time_machine.Coordinates)
310309
event = test_env.actor(1).initial_dispatch
311310

312311
assert event.dry_run is dispatch.dry_run
313-
assert event.components == _convert_target_components(dispatch.target)
312+
assert event.components == dispatch.target
314313
assert event.options == dispatch.payload
315314
assert test_env.actor(1).is_running is True
316315

0 commit comments

Comments
 (0)