|
8 | 8 | from collections.abc import Callable |
9 | 9 | from dataclasses import dataclass |
10 | 10 | from datetime import timedelta |
11 | | -from typing import Any, Awaitable, cast |
| 11 | +from typing import Any, Awaitable |
12 | 12 |
|
13 | 13 | from frequenz.channels import Broadcast, Receiver, Sender, select |
14 | 14 | 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 |
18 | 16 | from frequenz.core.id import BaseId |
19 | 17 | from frequenz.sdk.actor import Actor, BackgroundService |
20 | 18 |
|
21 | 19 | from ._dispatch import Dispatch |
22 | 20 |
|
23 | 21 | _logger = logging.getLogger(__name__) |
24 | 22 |
|
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 | | - |
31 | 23 |
|
32 | 24 | class DispatchActorId(BaseId, str_prefix="DA"): |
33 | 25 | """ID for a dispatch actor.""" |
@@ -208,7 +200,7 @@ def start(self) -> None: |
208 | 200 | async def _start_actor(self, dispatch: Dispatch) -> None: |
209 | 201 | """Start the actor the given dispatch refers to.""" |
210 | 202 | dispatch_update = DispatchInfo( |
211 | | - components=_convert_target_components(dispatch.target), |
| 203 | + components=dispatch.target, |
212 | 204 | dry_run=dispatch.dry_run, |
213 | 205 | options=dispatch.payload, |
214 | 206 | _src=dispatch, |
@@ -305,13 +297,3 @@ async def _handle_dispatch(self, dispatch: Dispatch) -> None: |
305 | 297 | await self._start_actor(dispatch) |
306 | 298 | else: |
307 | 299 | 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) |
0 commit comments