1010from dataclasses import dataclass
1111from datetime import datetime , timedelta , timezone
1212from enum import Enum
13- from typing import Iterable , Optional , Set , TypeVar , Union
13+ from typing import Iterable , Optional , Set , Union
1414
1515# pylint: disable=no-name-in-module
1616from frequenz .api .microgrid .battery_pb2 import ComponentState as BatteryComponentState
@@ -60,9 +60,6 @@ class SetPowerResult:
6060 """Set of the batteries that failed."""
6161
6262
63- T = TypeVar ("T" )
64-
65-
6663@dataclass
6764class _ComponentStreamStatus :
6865 component_id : int
@@ -81,15 +78,23 @@ class _ComponentStreamStatus:
8178@dataclass
8279class _BlockingStatus :
8380 min_duration_sec : float
81+ """The minimum blocking duration (in seconds)."""
82+
8483 max_duration_sec : float
84+ """The maximum blocking duration (in seconds)."""
85+
86+ last_blocking_duration_sec : float = 0.0
87+ """Last blocking duration (in seconds)."""
88+
89+ blocked_until : datetime | None = None
90+ """Until when the battery is blocked."""
8591
8692 def __post_init__ (self ) -> None :
8793 assert self .min_duration_sec <= self .max_duration_sec , (
8894 f"Minimum blocking duration ({ self .min_duration_sec } ) cannot be greater "
8995 f"than maximum blocking duration ({ self .max_duration_sec } )"
9096 )
91- self .last_blocking_duration_sec : float = self .min_duration_sec
92- self .blocked_until : Optional [datetime ] = None
97+ self .last_blocking_duration_sec = self .min_duration_sec
9398
9499 def block (self ) -> float :
95100 """Block battery.
@@ -150,21 +155,34 @@ class BatteryStatusTracker:
150155 Status updates are sent out only when there is a status change.
151156 """
152157
153- # Class attributes
154158 _battery_valid_relay : Set [BatteryRelayState .ValueType ] = {
155159 BatteryRelayState .RELAY_STATE_CLOSED
156160 }
161+ """The list of valid relay states of a battery.
162+
163+ A working battery in any other battery relay state will be reported as failing.
164+ """
165+
157166 _battery_valid_state : Set [BatteryComponentState .ValueType ] = {
158167 BatteryComponentState .COMPONENT_STATE_IDLE ,
159168 BatteryComponentState .COMPONENT_STATE_CHARGING ,
160169 BatteryComponentState .COMPONENT_STATE_DISCHARGING ,
161170 }
171+ """The list of valid states of a battery.
172+
173+ A working battery in any other battery state will be reported as failing.
174+ """
175+
162176 _inverter_valid_state : Set [InverterComponentState .ValueType ] = {
163177 InverterComponentState .COMPONENT_STATE_STANDBY ,
164178 InverterComponentState .COMPONENT_STATE_IDLE ,
165179 InverterComponentState .COMPONENT_STATE_CHARGING ,
166180 InverterComponentState .COMPONENT_STATE_DISCHARGING ,
167181 }
182+ """The list of valid states of an inverter.
183+
184+ A working inverter in any other inverter state will be reported as failing.
185+ """
168186
169187 def __init__ ( # pylint: disable=too-many-arguments
170188 self ,
0 commit comments