99import logging
1010import sys
1111from datetime import datetime , timedelta , timezone
12+ from typing import assert_never
1213
1314from frequenz .channels import Receiver , Sender , select , selected_from
1415from frequenz .channels .timer import SkipMissedAndDrift , Timer
2223from .. import _data_pipeline , _power_distributing
2324from ._base_classes import Algorithm , BaseAlgorithm , Proposal , ReportRequest , _Report
2425from ._matryoshka import Matryoshka
26+ from ._shifting_matryoshka import ShiftingMatryoshka
2527
2628_logger = logging .getLogger (__name__ )
2729
@@ -63,15 +65,7 @@ def __init__( # pylint: disable=too-many-arguments
6365 `None` when the component category is enough to uniquely identify the
6466 component.
6567 algorithm: The power management algorithm to use.
66-
67- Raises:
68- NotImplementedError: When an unknown algorithm is given.
6968 """
70- if algorithm is not Algorithm .MATRYOSHKA :
71- raise NotImplementedError (
72- f"PowerManagingActor: Unknown algorithm: { algorithm } "
73- )
74-
7569 self ._component_category = component_category
7670 self ._component_type = component_type
7771 self ._bounds_subscription_receiver = bounds_subscription_receiver
@@ -84,9 +78,17 @@ def __init__( # pylint: disable=too-many-arguments
8478 self ._bound_tracker_tasks : dict [frozenset [int ], asyncio .Task [None ]] = {}
8579 self ._subscriptions : dict [frozenset [int ], dict [int , Sender [_Report ]]] = {}
8680
87- self ._algorithm : BaseAlgorithm = Matryoshka (
88- max_proposal_age = timedelta (seconds = 60.0 )
89- )
81+ match algorithm :
82+ case Algorithm .MATRYOSHKA :
83+ self ._algorithm : BaseAlgorithm = Matryoshka (
84+ max_proposal_age = timedelta (seconds = 60.0 )
85+ )
86+ case Algorithm .SHIFTING_MATRYOSHKA :
87+ self ._algorithm = ShiftingMatryoshka (
88+ max_proposal_age = timedelta (seconds = 60.0 )
89+ )
90+ case _:
91+ assert_never (algorithm )
9092
9193 super ().__init__ ()
9294
0 commit comments