Skip to content

Commit 8da8583

Browse files
Document class and module attributes (#618)
Add or amend docstrings for all classes and modules where needed. Fixes #74
2 parents 1229824 + f720979 commit 8da8583

36 files changed

+222
-58
lines changed

src/frequenz/sdk/_api_client/api_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ class ApiProtocol(Enum):
1111
"""Enumerated values of supported API types."""
1212

1313
GRPC = 1
14+
"""gRPC API."""
15+
1416
REST = 2
17+
"""REST API."""
18+
1519
FILESYSTEM = 3
20+
"""Filesystem API."""
1621

1722

1823
class ApiClient(ABC):

src/frequenz/sdk/_internal/_asyncio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def cancel_and_await(task: asyncio.Task[Any]) -> None:
1515
1616
Exits immediately if the task is already done.
1717
18-
The `CancelledError` is suppresed, but any other exception will be propagated.
18+
The `CancelledError` is suppressed, but any other exception will be propagated.
1919
2020
Args:
2121
task: The task to be cancelled and waited for.

src/frequenz/sdk/_internal/_singleton_meta.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ class SingletonMeta(type):
1111
"""This is a thread-safe implementation of Singleton."""
1212

1313
_instances: Dict[Any, type] = {}
14+
"""The dictionary of instances of the singleton classes."""
15+
1416
_lock: Lock = Lock()
17+
"""The lock to ensure thread safety.
18+
19+
The lock to acquire when creating a singleton instance, preventing
20+
multiple threads from creating instances simultaneously.
21+
"""
1522

1623
def __call__(cls, *args: Any, **kwargs: Any) -> type:
1724
"""Overload function call operator to return the singleton instance.

src/frequenz/sdk/actor/_data_sourcing/microgrid_api_source.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,13 @@ def __init__(
141141
instance.
142142
"""
143143
self._comp_categories_cache: Dict[int, ComponentCategory] = {}
144+
144145
self.comp_data_receivers: Dict[int, Receiver[Any]] = {}
146+
"""The dictionary of component IDs to data receivers."""
147+
145148
self.comp_data_tasks: Dict[int, asyncio.Task[None]] = {}
149+
"""The dictionary of component IDs to asyncio tasks."""
150+
146151
self._registry = registry
147152
self._req_streaming_metrics: Dict[
148153
int, Dict[ComponentMetricId, List[ComponentMetricRequest]]
@@ -343,10 +348,10 @@ def _get_metric_senders(
343348
self._get_data_extraction_method(category, metric),
344349
[
345350
self._registry.new_sender(request.get_channel_name())
346-
for request in reqlist
351+
for request in req_list
347352
],
348353
)
349-
for (metric, reqlist) in requests.items()
354+
for (metric, req_list) in requests.items()
350355
]
351356

352357
async def _handle_data_stream(

src/frequenz/sdk/actor/_resampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__( # pylint: disable=too-many-arguments
4343
the [`DataSourcingActor`][frequenz.sdk.actor.DataSourcingActor]
4444
to subscribe to component metrics.
4545
resampling_request_receiver: The receiver to use to receive new
46-
resampmling subscription requests.
46+
resampling subscription requests.
4747
config: The configuration for the resampler.
4848
name: The name of the actor. If `None`, `str(id(self))` will be used. This
4949
is used mostly for debugging purposes.

src/frequenz/sdk/actor/power_distributing/_battery_status.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from dataclasses import dataclass
1111
from datetime import datetime, timedelta, timezone
1212
from 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
1616
from 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
6764
class _ComponentStreamStatus:
6865
component_id: int
@@ -81,15 +78,23 @@ class _ComponentStreamStatus:
8178
@dataclass
8279
class _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,

src/frequenz/sdk/actor/power_distributing/power_distributing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,16 @@ def __init__(
146146

147147
# NOTE: power_distributor_exponent should be received from ConfigManager
148148
self.power_distributor_exponent: float = 1.0
149+
"""The exponent for the power distribution algorithm.
150+
151+
The exponent determines how fast the batteries should strive to the
152+
equal SoC level.
153+
"""
154+
149155
self.distribution_algorithm = DistributionAlgorithm(
150156
self.power_distributor_exponent
151157
)
158+
"""The distribution algorithm used to distribute power between batteries."""
152159

153160
self._bat_inv_map, self._inv_bat_map = self._get_components_pairs(
154161
connection_manager.get().component_graph

src/frequenz/sdk/actor/power_distributing/result.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,16 @@ class PowerBounds:
8484
"""Inclusion and exclusion power bounds for requested batteries."""
8585

8686
inclusion_lower: float
87+
"""The lower value of the inclusion power bounds for the requested batteries."""
88+
8789
exclusion_lower: float
90+
"""The lower value of the exclusion power bounds for the requested batteries."""
91+
8892
exclusion_upper: float
93+
"""The upper value of the exclusion power bounds for the requested batteries."""
94+
8995
inclusion_upper: float
96+
"""The upper value of the inclusion power bounds for the requested batteries."""
9097

9198

9299
@dataclasses.dataclass

src/frequenz/sdk/config/_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
_logger = logging.getLogger(__name__)
1313

1414
T = TypeVar("T")
15+
"""Type variable for validating configuration values."""
1516

1617

1718
class Config:

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@
5151
"""
5252

5353
_T = typing.TypeVar("_T")
54+
"""Type variable for generic actor types."""
5455

5556

5657
@dataclass
5758
class _ActorInfo(typing.Generic[_T]):
5859
"""Holds instances of core data pipeline actors and their request channels."""
5960

6061
actor: _T
62+
"""The actor instance."""
63+
6164
channel: Broadcast["ComponentMetricRequest"]
65+
"""The request channel for the actor."""
6266

6367

6468
class _DataPipeline:

0 commit comments

Comments
 (0)