Skip to content

Commit 73b00c1

Browse files
Document class and module attributes
Add or amend docstrings for all classes and modules where needed. Signed-off-by: Daniel Zullo <[email protected]>
1 parent f74221a commit 73b00c1

File tree

25 files changed

+202
-7
lines changed

25 files changed

+202
-7
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/_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: 5 additions & 0 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]]

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,21 @@ class _ComponentStreamStatus:
7878
@dataclass
7979
class _BlockingStatus:
8080
min_duration_sec: float
81+
"""The minimum blocking duration (in seconds)."""
82+
8183
max_duration_sec: float
84+
"""The maximum blocking duration (in seconds)."""
8285

8386
def __post_init__(self) -> None:
8487
assert self.min_duration_sec <= self.max_duration_sec, (
8588
f"Minimum blocking duration ({self.min_duration_sec}) cannot be greater "
8689
f"than maximum blocking duration ({self.max_duration_sec})"
8790
)
8891
self.last_blocking_duration_sec: float = self.min_duration_sec
92+
"""Last blocking duration (in seconds).""" # pylint: disable=pointless-string-statement
93+
8994
self.blocked_until: Optional[datetime] = None
95+
"""Until when battery is blocked.""" # pylint: disable=pointless-string-statement
9096

9197
def block(self) -> float:
9298
"""Block battery.
@@ -147,21 +153,34 @@ class BatteryStatusTracker:
147153
Status updates are sent out only when there is a status change.
148154
"""
149155

150-
# Class attributes
151156
_battery_valid_relay: Set[BatteryRelayState.ValueType] = {
152157
BatteryRelayState.RELAY_STATE_CLOSED
153158
}
159+
"""The list of valid relay states of a battery.
160+
161+
A working battery in any other battery relay state will be reported as failing.
162+
"""
163+
154164
_battery_valid_state: Set[BatteryComponentState.ValueType] = {
155165
BatteryComponentState.COMPONENT_STATE_IDLE,
156166
BatteryComponentState.COMPONENT_STATE_CHARGING,
157167
BatteryComponentState.COMPONENT_STATE_DISCHARGING,
158168
}
169+
"""The list of valid states of a battery.
170+
171+
A working battery in any other battery state will be reported as failing.
172+
"""
173+
159174
_inverter_valid_state: Set[InverterComponentState.ValueType] = {
160175
InverterComponentState.COMPONENT_STATE_STANDBY,
161176
InverterComponentState.COMPONENT_STATE_IDLE,
162177
InverterComponentState.COMPONENT_STATE_CHARGING,
163178
InverterComponentState.COMPONENT_STATE_DISCHARGING,
164179
}
180+
"""The list of valid states of an inverter.
181+
182+
A working inverter in any other inverter state will be reported as failing.
183+
"""
165184

166185
def __init__( # pylint: disable=too-many-arguments
167186
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:

src/frequenz/sdk/microgrid/client/_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
from ._connection import Connection
4343
from ._retry import LinearBackoff, RetryStrategy
4444

45-
# Default timeout applied to all gRPC calls
4645
DEFAULT_GRPC_CALL_TIMEOUT = 60.0
46+
"""The default timeout for gRPC calls made by this client (in seconds)."""
4747

4848
# A generic type for representing various component data types, used in the
4949
# generic function `MicrogridGrpcClient._component_data_task` that fetches
@@ -55,6 +55,7 @@
5555
InverterData,
5656
EVChargerData,
5757
)
58+
"""Type variable for representing various component data types."""
5859

5960
_logger = logging.getLogger(__name__)
6061

@@ -215,7 +216,11 @@ def __init__(
215216
method gets lost.
216217
"""
217218
self.target = target
219+
"""The location (as "host:port") of the microgrid API gRPC server."""
220+
218221
self.api = MicrogridStub(grpc_channel)
222+
"""The gRPC stub for the microgrid API."""
223+
219224
self._component_streams: Dict[int, Broadcast[Any]] = {}
220225
self._streaming_tasks: Dict[int, asyncio.Task[None]] = {}
221226
self._retry_spec = retry_spec

src/frequenz/sdk/microgrid/client/_connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ class Connection(NamedTuple):
1010
"""Metadata for a connection between microgrid components."""
1111

1212
start: int
13+
"""The component ID that represents the start component of the connection."""
14+
1315
end: int
16+
"""The component ID that represents the end component of the connection."""
1417

1518
def is_valid(self) -> bool:
1619
"""Check if this instance contains valid data.

0 commit comments

Comments
 (0)