Skip to content

result

frequenz.sdk.actor.power_distributing.result ¤

Results from PowerDistributingActor.

Attributes¤

frequenz.sdk.actor.power_distributing.result.Result module-attribute ¤

Power distribution result.

Example: Handling power distribution results

```python
from typing import assert_never

from frequenz.sdk.actor.power_distributing import (
    Error,
    OutOfBounds,
    PartialFailure,
    Result,
    Success,
)
from frequenz.sdk.actor.power_distributing.request import Request
from frequenz.sdk.actor.power_distributing.result import PowerBounds
from frequenz.sdk.timeseries._quantities import Power

def handle_power_request_result(result: Result) -> None:
    match result:
        case Success() as success:
            print(f"Power request was successful: {success}")
        case PartialFailure() as partial_failure:
            print(f"Power request was partially successful: {partial_failure}")
        case OutOfBounds() as out_of_bounds:
            print(f"Power request was out of bounds: {out_of_bounds}")
        case Error() as error:
            print(f"Power request failed: {error}")
        case _ as unreachable:
            assert_never(unreachable)

request = Request(
    namespace="TestChannel",
    power=Power.from_watts(123.4),
    component_ids={8, 18},
)

results: list[Result] = [
    Success(
        request,
        succeeded_power=Power.from_watts(123.4),
        succeeded_components={8, 18},
        excess_power=Power.zero(),
    ),
    PartialFailure(
        request,
        succeeded_power=Power.from_watts(103.4),
        succeeded_components={8},
        excess_power=Power.zero(),
        failed_components={18},
        failed_power=Power.from_watts(20.0),
    ),
    OutOfBounds(request, bounds=PowerBounds(0, 0, 0, 800)),
    Error(request, msg="The components are not available"),
]

for r in results:
    handle_power_request_result(r)
```

Classes¤

frequenz.sdk.actor.power_distributing.result.Error dataclass ¤

Bases: _BaseResultMixin

Result returned when an error occurred and power was not set at all.

Source code in frequenz/sdk/actor/power_distributing/result.py
@dataclasses.dataclass
class Error(_BaseResultMixin):
    """Result returned when an error occurred and power was not set at all."""

    msg: str
    """The error message explaining why error happened."""
Attributes¤
msg instance-attribute ¤
msg: str

The error message explaining why error happened.

request instance-attribute ¤
request: Request

The user's request to which this message responds.

frequenz.sdk.actor.power_distributing.result.OutOfBounds dataclass ¤

Bases: _BaseResultMixin

Result returned when the power was not set because it was out of bounds.

This result happens when the originating request was done with adjust_power = False and the requested power is not within the available bounds.

Source code in frequenz/sdk/actor/power_distributing/result.py
@dataclasses.dataclass
class OutOfBounds(_BaseResultMixin):
    """Result returned when the power was not set because it was out of bounds.

    This result happens when the originating request was done with
    `adjust_power = False` and the requested power is not within the available bounds.
    """

    bounds: PowerBounds
    """The power bounds for the requested components.

    If the requested power negative, then this value is the lower bound.
    Otherwise it is upper bound.
    """
Attributes¤
bounds instance-attribute ¤
bounds: PowerBounds

The power bounds for the requested components.

If the requested power negative, then this value is the lower bound. Otherwise it is upper bound.

request instance-attribute ¤
request: Request

The user's request to which this message responds.

frequenz.sdk.actor.power_distributing.result.PartialFailure dataclass ¤

Bases: _BaseSuccessMixin, _BaseResultMixin

Result returned when some of the components had an error setting the power.

Source code in frequenz/sdk/actor/power_distributing/result.py
@dataclasses.dataclass
class PartialFailure(_BaseSuccessMixin, _BaseResultMixin):
    """Result returned when some of the components had an error setting the power."""

    failed_power: Power
    """The part of the requested power that failed to be set."""

    failed_components: abc.Set[int]
    """The subset of batteries for which the request failed."""
Attributes¤
excess_power instance-attribute ¤
excess_power: Power

The part of the requested power that could not be fulfilled.

This happens when the requested power is outside the available power bounds.

failed_components instance-attribute ¤
failed_components: Set[int]

The subset of batteries for which the request failed.

failed_power instance-attribute ¤
failed_power: Power

The part of the requested power that failed to be set.

request instance-attribute ¤
request: Request

The user's request to which this message responds.

succeeded_components instance-attribute ¤
succeeded_components: Set[int]

The subset of components for which power was set successfully.

succeeded_power instance-attribute ¤
succeeded_power: Power

The part of the requested power that was successfully set.

frequenz.sdk.actor.power_distributing.result.PowerBounds dataclass ¤

Inclusion and exclusion power bounds for the requested components.

Source code in frequenz/sdk/actor/power_distributing/result.py
@dataclasses.dataclass
class PowerBounds:
    """Inclusion and exclusion power bounds for the requested components."""

    inclusion_lower: float
    """The lower value of the inclusion power bounds for the requested components."""

    exclusion_lower: float
    """The lower value of the exclusion power bounds for the requested components."""

    exclusion_upper: float
    """The upper value of the exclusion power bounds for the requested components."""

    inclusion_upper: float
    """The upper value of the inclusion power bounds for the requested components."""
Attributes¤
exclusion_lower instance-attribute ¤
exclusion_lower: float

The lower value of the exclusion power bounds for the requested components.

exclusion_upper instance-attribute ¤
exclusion_upper: float

The upper value of the exclusion power bounds for the requested components.

inclusion_lower instance-attribute ¤
inclusion_lower: float

The lower value of the inclusion power bounds for the requested components.

inclusion_upper instance-attribute ¤
inclusion_upper: float

The upper value of the inclusion power bounds for the requested components.

frequenz.sdk.actor.power_distributing.result.Success dataclass ¤

Bases: _BaseSuccessMixin, _BaseResultMixin

Result returned when setting the power was successful for all components.

Source code in frequenz/sdk/actor/power_distributing/result.py
@dataclasses.dataclass
class Success(_BaseSuccessMixin, _BaseResultMixin):  # Order matters here. See above.
    """Result returned when setting the power was successful for all components."""
Attributes¤
excess_power instance-attribute ¤
excess_power: Power

The part of the requested power that could not be fulfilled.

This happens when the requested power is outside the available power bounds.

request instance-attribute ¤
request: Request

The user's request to which this message responds.

succeeded_components instance-attribute ¤
succeeded_components: Set[int]

The subset of components for which power was set successfully.

succeeded_power instance-attribute ¤
succeeded_power: Power

The part of the requested power that was successfully set.