From 26862b6979404cdf55bfdd1c387f56e70ed03b8a Mon Sep 17 00:00:00 2001 From: "Mathias L. Baumann" Date: Wed, 25 Jun 2025 15:50:10 +0200 Subject: [PATCH] Remove obsolete type `TargetComponents` Signed-off-by: Mathias L. Baumann --- RELEASE_NOTES.md | 2 +- src/frequenz/dispatch/__init__.py | 3 +-- src/frequenz/dispatch/_actor_dispatcher.py | 24 +++------------------- tests/test_managing_actor.py | 11 +++++----- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c04290fa..549c3bb6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -6,7 +6,7 @@ ## Upgrading - +The `frequenz.disptach.TargetComponents` tye was removed, use `frequenz.client.dispatch.TargetComponents` instead. ## New Features diff --git a/src/frequenz/dispatch/__init__.py b/src/frequenz/dispatch/__init__.py index 448e8a8a..ac4bafb2 100644 --- a/src/frequenz/dispatch/__init__.py +++ b/src/frequenz/dispatch/__init__.py @@ -15,7 +15,7 @@ """ -from ._actor_dispatcher import ActorDispatcher, DispatchInfo, TargetComponents +from ._actor_dispatcher import ActorDispatcher, DispatchInfo from ._bg_service import MergeStrategy from ._dispatch import Dispatch from ._dispatcher import Dispatcher @@ -34,5 +34,4 @@ "MergeStrategy", "MergeByType", "MergeByTypeTarget", - "TargetComponents", ] diff --git a/src/frequenz/dispatch/_actor_dispatcher.py b/src/frequenz/dispatch/_actor_dispatcher.py index 0be2606d..fef96409 100644 --- a/src/frequenz/dispatch/_actor_dispatcher.py +++ b/src/frequenz/dispatch/_actor_dispatcher.py @@ -8,13 +8,11 @@ from collections.abc import Callable from dataclasses import dataclass from datetime import timedelta -from typing import Any, Awaitable, cast +from typing import Any, Awaitable from frequenz.channels import Broadcast, Receiver, Sender, select from frequenz.channels.timer import SkipMissedAndDrift, Timer -from frequenz.client.common.microgrid.components import ComponentCategory, ComponentId -from frequenz.client.dispatch.types import DispatchId -from frequenz.client.dispatch.types import TargetComponents as ClientTargetComponents +from frequenz.client.dispatch.types import DispatchId, TargetComponents from frequenz.core.id import BaseId from frequenz.sdk.actor import Actor, BackgroundService @@ -22,12 +20,6 @@ _logger = logging.getLogger(__name__) -TargetComponents = list[ComponentId] | list[ComponentCategory] -"""One or more target components specifying which components a dispatch targets. - -It can be a list of component IDs or a list of categories. -""" - class DispatchActorId(BaseId, str_prefix="DA"): """ID for a dispatch actor.""" @@ -208,7 +200,7 @@ def start(self) -> None: async def _start_actor(self, dispatch: Dispatch) -> None: """Start the actor the given dispatch refers to.""" dispatch_update = DispatchInfo( - components=_convert_target_components(dispatch.target), + components=dispatch.target, dry_run=dispatch.dry_run, options=dispatch.payload, _src=dispatch, @@ -305,13 +297,3 @@ async def _handle_dispatch(self, dispatch: Dispatch) -> None: await self._start_actor(dispatch) else: await self._stop_actor(dispatch, "Dispatch stopped") - - -def _convert_target_components(target: ClientTargetComponents) -> TargetComponents: - if all(isinstance(comp, int) for comp in target): - # We've confirmed all elements are integers, so we can cast. - int_components = cast(list[int], target) - return [ComponentId(cid) for cid in int_components] - # If not all are ints, then it must be a list of ComponentCategory - # based on the definition of ClientTargetComponents. - return cast(list[ComponentCategory], target) diff --git a/tests/test_managing_actor.py b/tests/test_managing_actor.py index 024d81c4..078a3030 100644 --- a/tests/test_managing_actor.py +++ b/tests/test_managing_actor.py @@ -33,10 +33,7 @@ MergeByTypeTarget, MergeStrategy, ) -from frequenz.dispatch._actor_dispatcher import ( - DispatchActorId, - _convert_target_components, -) +from frequenz.dispatch._actor_dispatcher import DispatchActorId from frequenz.dispatch._bg_service import DispatchScheduler @@ -180,7 +177,9 @@ async def test_simple_start_stop( event = test_env.actor(1).initial_dispatch assert event.options == {"test": True} - assert event.components == [ComponentId(1), ComponentId(10), ComponentId(15)] + assert event.components == TargetIds( + ComponentId(1), ComponentId(10), ComponentId(15) + ) assert event.dry_run is False 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) event = test_env.actor(1).initial_dispatch assert event.dry_run is dispatch.dry_run - assert event.components == _convert_target_components(dispatch.target) + assert event.components == dispatch.target assert event.options == dispatch.payload assert test_env.actor(1).is_running is True