Skip to content

component

frequenz.sdk.microgrid.component ¤

Microgrid component abstractions.

This package provides classes to operate con microgrid components.

Classes¤

frequenz.sdk.microgrid.component.BatteryData dataclass ¤

Bases: ComponentData

A wrapper class for holding battery data.

Source code in frequenz/sdk/microgrid/component/_component_data.py
@dataclass(frozen=True)
class BatteryData(ComponentData):
    """A wrapper class for holding battery data."""

    soc: float
    """Battery's overall SoC in percent (%)."""

    soc_lower_bound: float
    """The SoC below which discharge commands will be blocked by the system,
        in percent (%).
    """

    soc_upper_bound: float
    """The SoC above which charge commands will be blocked by the system,
        in percent (%).
    """

    capacity: float
    """The capacity of the battery in Wh (Watt-hour)."""

    # pylint: disable=line-too-long
    power_inclusion_lower_bound: float
    """Lower inclusion bound for battery power in watts.

    This is the lower limit of the range within which power requests are allowed for the
    battery.

    See [`frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds`][] and
    [`frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds`][] for more
    details.
    """

    power_exclusion_lower_bound: float
    """Lower exclusion bound for battery power in watts.

    This is the lower limit of the range within which power requests are not allowed for
    the battery.

    See [`frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds`][] and
    [`frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds`][] for more
    details.
    """

    power_inclusion_upper_bound: float
    """Upper inclusion bound for battery power in watts.

    This is the upper limit of the range within which power requests are allowed for the
    battery.

    See [`frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds`][] and
    [`frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds`][] for more
    details.
    """

    power_exclusion_upper_bound: float
    """Upper exclusion bound for battery power in watts.

    This is the upper limit of the range within which power requests are not allowed for
    the battery.

    See [`frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds`][] and
    [`frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds`][] for more
    details.
    """
    # pylint: enable=line-too-long

    temperature: float
    """The (average) temperature reported by the battery, in Celcius (°C)."""

    _relay_state: battery_pb.RelayState.ValueType
    """State of the battery relay."""

    _component_state: battery_pb.ComponentState.ValueType
    """State of the battery."""

    _errors: List[battery_pb.Error]
    """List of errors in protobuf struct."""

    @classmethod
    def from_proto(cls, raw: microgrid_pb.ComponentData) -> BatteryData:
        """Create BatteryData from a protobuf message.

        Args:
            raw: raw component data as decoded from the wire.

        Returns:
            Instance of BatteryData created from the protobuf message.
        """
        raw_power = raw.battery.data.dc.power
        battery_data = cls(
            component_id=raw.id,
            timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
            soc=raw.battery.data.soc.avg,
            soc_lower_bound=raw.battery.data.soc.system_inclusion_bounds.lower,
            soc_upper_bound=raw.battery.data.soc.system_inclusion_bounds.upper,
            capacity=raw.battery.properties.capacity,
            power_inclusion_lower_bound=raw_power.system_inclusion_bounds.lower,
            power_exclusion_lower_bound=raw_power.system_exclusion_bounds.lower,
            power_inclusion_upper_bound=raw_power.system_inclusion_bounds.upper,
            power_exclusion_upper_bound=raw_power.system_exclusion_bounds.upper,
            temperature=raw.battery.data.temperature.avg,
            _relay_state=raw.battery.state.relay_state,
            _component_state=raw.battery.state.component_state,
            _errors=list(raw.battery.errors),
        )
        battery_data._set_raw(raw=raw)
        return battery_data
Attributes¤
capacity: float instance-attribute ¤

The capacity of the battery in Wh (Watt-hour).

power_exclusion_lower_bound: float instance-attribute ¤

Lower exclusion bound for battery power in watts.

This is the lower limit of the range within which power requests are not allowed for the battery.

See frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds and frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds for more details.

power_exclusion_upper_bound: float instance-attribute ¤

Upper exclusion bound for battery power in watts.

This is the upper limit of the range within which power requests are not allowed for the battery.

See frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds and frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds for more details.

power_inclusion_lower_bound: float instance-attribute ¤

Lower inclusion bound for battery power in watts.

This is the lower limit of the range within which power requests are allowed for the battery.

See frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds and frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds for more details.

power_inclusion_upper_bound: float instance-attribute ¤

Upper inclusion bound for battery power in watts.

This is the upper limit of the range within which power requests are allowed for the battery.

See frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds and frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds for more details.

soc: float instance-attribute ¤

Battery's overall SoC in percent (%).

soc_lower_bound: float instance-attribute ¤

The SoC below which discharge commands will be blocked by the system, in percent (%).

soc_upper_bound: float instance-attribute ¤

The SoC above which charge commands will be blocked by the system, in percent (%).

temperature: float instance-attribute ¤

The (average) temperature reported by the battery, in Celcius (°C).

Functions¤
from_proto(raw) classmethod ¤

Create BatteryData from a protobuf message.

PARAMETER DESCRIPTION
raw

raw component data as decoded from the wire.

TYPE: ComponentData

RETURNS DESCRIPTION
BatteryData

Instance of BatteryData created from the protobuf message.

Source code in frequenz/sdk/microgrid/component/_component_data.py
@classmethod
def from_proto(cls, raw: microgrid_pb.ComponentData) -> BatteryData:
    """Create BatteryData from a protobuf message.

    Args:
        raw: raw component data as decoded from the wire.

    Returns:
        Instance of BatteryData created from the protobuf message.
    """
    raw_power = raw.battery.data.dc.power
    battery_data = cls(
        component_id=raw.id,
        timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
        soc=raw.battery.data.soc.avg,
        soc_lower_bound=raw.battery.data.soc.system_inclusion_bounds.lower,
        soc_upper_bound=raw.battery.data.soc.system_inclusion_bounds.upper,
        capacity=raw.battery.properties.capacity,
        power_inclusion_lower_bound=raw_power.system_inclusion_bounds.lower,
        power_exclusion_lower_bound=raw_power.system_exclusion_bounds.lower,
        power_inclusion_upper_bound=raw_power.system_inclusion_bounds.upper,
        power_exclusion_upper_bound=raw_power.system_exclusion_bounds.upper,
        temperature=raw.battery.data.temperature.avg,
        _relay_state=raw.battery.state.relay_state,
        _component_state=raw.battery.state.component_state,
        _errors=list(raw.battery.errors),
    )
    battery_data._set_raw(raw=raw)
    return battery_data

frequenz.sdk.microgrid.component.Component dataclass ¤

Metadata for a single microgrid component.

Source code in frequenz/sdk/microgrid/component/_component.py
@dataclass(frozen=True)
class Component:
    """Metadata for a single microgrid component."""

    component_id: int
    category: ComponentCategory
    type: Optional[ComponentType] = None

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

        Returns:
            `True` if `id > 0` and `type` is a valid `ComponentCategory`, or if `id
                == 0` and `type` is `GRID`, `False` otherwise
        """
        return (
            self.component_id > 0 and any(t == self.category for t in ComponentCategory)
        ) or (self.component_id == 0 and self.category == ComponentCategory.GRID)
Functions¤
is_valid() ¤

Check if this instance contains valid data.

RETURNS DESCRIPTION
bool

True if id > 0 and type is a valid ComponentCategory, or if id == 0 and type is GRID, False otherwise

Source code in frequenz/sdk/microgrid/component/_component.py
def is_valid(self) -> bool:
    """Check if this instance contains valid data.

    Returns:
        `True` if `id > 0` and `type` is a valid `ComponentCategory`, or if `id
            == 0` and `type` is `GRID`, `False` otherwise
    """
    return (
        self.component_id > 0 and any(t == self.category for t in ComponentCategory)
    ) or (self.component_id == 0 and self.category == ComponentCategory.GRID)

frequenz.sdk.microgrid.component.ComponentCategory ¤

Bases: Enum

Possible types of microgrid component.

Source code in frequenz/sdk/microgrid/component/_component.py
class ComponentCategory(Enum):
    """Possible types of microgrid component."""

    NONE = components_pb.ComponentCategory.COMPONENT_CATEGORY_UNSPECIFIED
    GRID = components_pb.ComponentCategory.COMPONENT_CATEGORY_GRID
    METER = components_pb.ComponentCategory.COMPONENT_CATEGORY_METER
    INVERTER = components_pb.ComponentCategory.COMPONENT_CATEGORY_INVERTER
    BATTERY = components_pb.ComponentCategory.COMPONENT_CATEGORY_BATTERY
    EV_CHARGER = components_pb.ComponentCategory.COMPONENT_CATEGORY_EV_CHARGER
    CHP = components_pb.ComponentCategory.COMPONENT_CATEGORY_CHP

    # types not yet supported by the API but which can be inferred
    # from available graph info
    PV_ARRAY = 1000001

frequenz.sdk.microgrid.component.ComponentData dataclass ¤

Bases: ABC

A private base class for strongly typed component data classes.

Source code in frequenz/sdk/microgrid/component/_component_data.py
@dataclass(frozen=True)
class ComponentData(ABC):
    """A private base class for strongly typed component data classes."""

    component_id: int
    """The ID identifying this component in the microgrid."""

    timestamp: datetime
    """The timestamp of when the data was measured."""

    # The `raw` attribute is excluded from the constructor as it can only be provided
    # when instantiating `ComponentData` using the `from_proto` method, which reads
    # data from a protobuf message. The whole protobuf message is stored as the `raw`
    # attribute. When `ComponentData` is not instantiated from a protobuf message,
    # i.e. using the constructor, `raw` will be set to `None`.
    raw: Optional[microgrid_pb.ComponentData] = field(default=None, init=False)
    """Raw component data as decoded from the wire."""

    def _set_raw(self, raw: microgrid_pb.ComponentData) -> None:
        """Store raw protobuf message.

        It is preferred to keep the dataclasses immutable (frozen) and make the `raw`
            attribute read-only, which is why the approach of writing to `__dict__`
            was used, instead of mutating the `self.raw = raw` attribute directly.

        Args:
            raw: raw component data as decoded from the wire.
        """
        self.__dict__["raw"] = raw

    @classmethod
    @abstractmethod
    def from_proto(cls, raw: microgrid_pb.ComponentData) -> ComponentData:
        """Create ComponentData from a protobuf message.

        Args:
            raw: raw component data as decoded from the wire.
        """
Attributes¤
component_id: int instance-attribute ¤

The ID identifying this component in the microgrid.

raw: Optional[microgrid_pb.ComponentData] = field(default=None, init=False) class-attribute instance-attribute ¤

Raw component data as decoded from the wire.

timestamp: datetime instance-attribute ¤

The timestamp of when the data was measured.

Functions¤
from_proto(raw) abstractmethod classmethod ¤

Create ComponentData from a protobuf message.

PARAMETER DESCRIPTION
raw

raw component data as decoded from the wire.

TYPE: ComponentData

Source code in frequenz/sdk/microgrid/component/_component_data.py
@classmethod
@abstractmethod
def from_proto(cls, raw: microgrid_pb.ComponentData) -> ComponentData:
    """Create ComponentData from a protobuf message.

    Args:
        raw: raw component data as decoded from the wire.
    """

frequenz.sdk.microgrid.component.ComponentMetricId ¤

Bases: Enum

An enum representing the various metrics available in the microgrid.

Source code in frequenz/sdk/microgrid/component/_component.py
class ComponentMetricId(Enum):
    """An enum representing the various metrics available in the microgrid."""

    ACTIVE_POWER = "active_power"

    CURRENT_PHASE_1 = "current_phase_1"
    CURRENT_PHASE_2 = "current_phase_2"
    CURRENT_PHASE_3 = "current_phase_3"

    VOLTAGE_PHASE_1 = "voltage_phase_1"
    VOLTAGE_PHASE_2 = "voltage_phase_2"
    VOLTAGE_PHASE_3 = "voltage_phase_3"

    SOC = "soc"
    SOC_LOWER_BOUND = "soc_lower_bound"
    SOC_UPPER_BOUND = "soc_upper_bound"
    CAPACITY = "capacity"

    POWER_INCLUSION_LOWER_BOUND = "power_inclusion_lower_bound"
    POWER_EXCLUSION_LOWER_BOUND = "power_exclusion_lower_bound"
    POWER_EXCLUSION_UPPER_BOUND = "power_exclusion_upper_bound"
    POWER_INCLUSION_UPPER_BOUND = "power_inclusion_upper_bound"

    ACTIVE_POWER_INCLUSION_LOWER_BOUND = "active_power_inclusion_lower_bound"
    ACTIVE_POWER_EXCLUSION_LOWER_BOUND = "active_power_exclusion_lower_bound"
    ACTIVE_POWER_EXCLUSION_UPPER_BOUND = "active_power_exclusion_upper_bound"
    ACTIVE_POWER_INCLUSION_UPPER_BOUND = "active_power_inclusion_upper_bound"

    TEMPERATURE = "temperature"

frequenz.sdk.microgrid.component.EVChargerCableState ¤

Bases: Enum

Cable states of an EV Charger.

Source code in frequenz/sdk/microgrid/component/_component_states.py
class EVChargerCableState(Enum):
    """Cable states of an EV Charger."""

    UNSPECIFIED = ev_charger_pb.CableState.CABLE_STATE_UNSPECIFIED
    UNPLUGGED = ev_charger_pb.CableState.CABLE_STATE_UNPLUGGED
    CHARGING_STATION_PLUGGED = (
        ev_charger_pb.CableState.CABLE_STATE_CHARGING_STATION_PLUGGED
    )
    CHARGING_STATION_LOCKED = (
        ev_charger_pb.CableState.CABLE_STATE_CHARGING_STATION_LOCKED
    )
    EV_PLUGGED = ev_charger_pb.CableState.CABLE_STATE_EV_PLUGGED
    EV_LOCKED = ev_charger_pb.CableState.CABLE_STATE_EV_LOCKED

    @classmethod
    def from_pb(
        cls, evc_state: ev_charger_pb.CableState.ValueType
    ) -> EVChargerCableState:
        """Convert a protobuf CableState value to EVChargerCableState enum.

        Args:
            evc_state: protobuf cable state to convert.

        Returns:
            Enum value corresponding to the protobuf message.
        """
        if not any(t.value == evc_state for t in EVChargerCableState):
            return cls.UNSPECIFIED

        return EVChargerCableState(evc_state)
Functions¤
from_pb(evc_state) classmethod ¤

Convert a protobuf CableState value to EVChargerCableState enum.

PARAMETER DESCRIPTION
evc_state

protobuf cable state to convert.

TYPE: ValueType

RETURNS DESCRIPTION
EVChargerCableState

Enum value corresponding to the protobuf message.

Source code in frequenz/sdk/microgrid/component/_component_states.py
@classmethod
def from_pb(
    cls, evc_state: ev_charger_pb.CableState.ValueType
) -> EVChargerCableState:
    """Convert a protobuf CableState value to EVChargerCableState enum.

    Args:
        evc_state: protobuf cable state to convert.

    Returns:
        Enum value corresponding to the protobuf message.
    """
    if not any(t.value == evc_state for t in EVChargerCableState):
        return cls.UNSPECIFIED

    return EVChargerCableState(evc_state)

frequenz.sdk.microgrid.component.EVChargerComponentState ¤

Bases: Enum

Component State of an EV Charger.

Source code in frequenz/sdk/microgrid/component/_component_states.py
class EVChargerComponentState(Enum):
    """Component State of an EV Charger."""

    UNSPECIFIED = ev_charger_pb.ComponentState.COMPONENT_STATE_UNSPECIFIED
    STARTING = ev_charger_pb.ComponentState.COMPONENT_STATE_STARTING
    NOT_READY = ev_charger_pb.ComponentState.COMPONENT_STATE_NOT_READY
    READY = ev_charger_pb.ComponentState.COMPONENT_STATE_READY
    CHARGING = ev_charger_pb.ComponentState.COMPONENT_STATE_CHARGING
    DISCHARGING = ev_charger_pb.ComponentState.COMPONENT_STATE_DISCHARGING
    ERROR = ev_charger_pb.ComponentState.COMPONENT_STATE_ERROR
    AUTHORIZATION_REJECTED = (
        ev_charger_pb.ComponentState.COMPONENT_STATE_AUTHORIZATION_REJECTED
    )
    INTERRUPTED = ev_charger_pb.ComponentState.COMPONENT_STATE_INTERRUPTED

    @classmethod
    def from_pb(
        cls, evc_state: ev_charger_pb.ComponentState.ValueType
    ) -> EVChargerComponentState:
        """Convert a protobuf ComponentState value to EVChargerComponentState enum.

        Args:
            evc_state: protobuf component state to convert.

        Returns:
            Enum value corresponding to the protobuf message.
        """
        if not any(t.value == evc_state for t in EVChargerComponentState):
            return cls.UNSPECIFIED

        return EVChargerComponentState(evc_state)
Functions¤
from_pb(evc_state) classmethod ¤

Convert a protobuf ComponentState value to EVChargerComponentState enum.

PARAMETER DESCRIPTION
evc_state

protobuf component state to convert.

TYPE: ValueType

RETURNS DESCRIPTION
EVChargerComponentState

Enum value corresponding to the protobuf message.

Source code in frequenz/sdk/microgrid/component/_component_states.py
@classmethod
def from_pb(
    cls, evc_state: ev_charger_pb.ComponentState.ValueType
) -> EVChargerComponentState:
    """Convert a protobuf ComponentState value to EVChargerComponentState enum.

    Args:
        evc_state: protobuf component state to convert.

    Returns:
        Enum value corresponding to the protobuf message.
    """
    if not any(t.value == evc_state for t in EVChargerComponentState):
        return cls.UNSPECIFIED

    return EVChargerComponentState(evc_state)

frequenz.sdk.microgrid.component.EVChargerData dataclass ¤

Bases: ComponentData

A wrapper class for holding ev_charger data.

Source code in frequenz/sdk/microgrid/component/_component_data.py
@dataclass(frozen=True)
class EVChargerData(ComponentData):
    """A wrapper class for holding ev_charger data."""

    active_power: float
    """The 3-phase active power, in Watts, represented in the passive sign convention.
        +ve current means consumption, away from the grid.
        -ve current means supply into the grid.
    """

    current_per_phase: Tuple[float, float, float]
    """AC current in Amperes (A) for phase/line 1,2 and 3 respectively.
        +ve current means consumption, away from the grid.
        -ve current means supply into the grid.
    """

    voltage_per_phase: Tuple[float, float, float]
    """The AC voltage in Volts (V) between the line and the neutral
        wire for phase/line 1,2 and 3 respectively.
    """

    cable_state: EVChargerCableState
    """The state of the ev charger's cable."""

    component_state: EVChargerComponentState
    """The state of the ev charger."""

    @classmethod
    def from_proto(cls, raw: microgrid_pb.ComponentData) -> EVChargerData:
        """Create EVChargerData from a protobuf message.

        Args:
            raw: raw component data as decoded from the wire.

        Returns:
            Instance of EVChargerData created from the protobuf message.
        """
        ev_charger_data = cls(
            component_id=raw.id,
            timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
            active_power=raw.ev_charger.data.ac.power_active.value,
            current_per_phase=(
                raw.ev_charger.data.ac.phase_1.current.value,
                raw.ev_charger.data.ac.phase_2.current.value,
                raw.ev_charger.data.ac.phase_3.current.value,
            ),
            voltage_per_phase=(
                raw.ev_charger.data.ac.phase_1.voltage.value,
                raw.ev_charger.data.ac.phase_2.voltage.value,
                raw.ev_charger.data.ac.phase_3.voltage.value,
            ),
            cable_state=EVChargerCableState.from_pb(raw.ev_charger.state.cable_state),
            component_state=EVChargerComponentState.from_pb(
                raw.ev_charger.state.component_state
            ),
        )
        ev_charger_data._set_raw(raw=raw)
        return ev_charger_data
Attributes¤
active_power: float instance-attribute ¤

The 3-phase active power, in Watts, represented in the passive sign convention. +ve current means consumption, away from the grid. -ve current means supply into the grid.

cable_state: EVChargerCableState instance-attribute ¤

The state of the ev charger's cable.

component_state: EVChargerComponentState instance-attribute ¤

The state of the ev charger.

current_per_phase: Tuple[float, float, float] instance-attribute ¤

AC current in Amperes (A) for phase/line 1,2 and 3 respectively. +ve current means consumption, away from the grid. -ve current means supply into the grid.

voltage_per_phase: Tuple[float, float, float] instance-attribute ¤

The AC voltage in Volts (V) between the line and the neutral wire for phase/line 1,2 and 3 respectively.

Functions¤
from_proto(raw) classmethod ¤

Create EVChargerData from a protobuf message.

PARAMETER DESCRIPTION
raw

raw component data as decoded from the wire.

TYPE: ComponentData

RETURNS DESCRIPTION
EVChargerData

Instance of EVChargerData created from the protobuf message.

Source code in frequenz/sdk/microgrid/component/_component_data.py
@classmethod
def from_proto(cls, raw: microgrid_pb.ComponentData) -> EVChargerData:
    """Create EVChargerData from a protobuf message.

    Args:
        raw: raw component data as decoded from the wire.

    Returns:
        Instance of EVChargerData created from the protobuf message.
    """
    ev_charger_data = cls(
        component_id=raw.id,
        timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
        active_power=raw.ev_charger.data.ac.power_active.value,
        current_per_phase=(
            raw.ev_charger.data.ac.phase_1.current.value,
            raw.ev_charger.data.ac.phase_2.current.value,
            raw.ev_charger.data.ac.phase_3.current.value,
        ),
        voltage_per_phase=(
            raw.ev_charger.data.ac.phase_1.voltage.value,
            raw.ev_charger.data.ac.phase_2.voltage.value,
            raw.ev_charger.data.ac.phase_3.voltage.value,
        ),
        cable_state=EVChargerCableState.from_pb(raw.ev_charger.state.cable_state),
        component_state=EVChargerComponentState.from_pb(
            raw.ev_charger.state.component_state
        ),
    )
    ev_charger_data._set_raw(raw=raw)
    return ev_charger_data

frequenz.sdk.microgrid.component.InverterData dataclass ¤

Bases: ComponentData

A wrapper class for holding inverter data.

Source code in frequenz/sdk/microgrid/component/_component_data.py
@dataclass(frozen=True)
class InverterData(ComponentData):
    """A wrapper class for holding inverter data."""

    active_power: float
    """The 3-phase active power, in Watts, represented in the passive sign convention.
            +ve current means consumption, away from the grid.
            -ve current means supply into the grid.
    """

    # pylint: disable=line-too-long
    active_power_inclusion_lower_bound: float
    """Lower inclusion bound for inverter power in watts.

    This is the lower limit of the range within which power requests are allowed for the
    inverter.

    See [`frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds`][] and
    [`frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds`][] for more
    details.
    """

    active_power_exclusion_lower_bound: float
    """Lower exclusion bound for inverter power in watts.

    This is the lower limit of the range within which power requests are not allowed for
    the inverter.

    See [`frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds`][] and
    [`frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds`][] for more
    details.
    """

    active_power_inclusion_upper_bound: float
    """Upper inclusion bound for inverter power in watts.

    This is the upper limit of the range within which power requests are allowed for the
    inverter.

    See [`frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds`][] and
    [`frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds`][] for more
    details.
    """

    active_power_exclusion_upper_bound: float
    """Upper exclusion bound for inverter power in watts.

    This is the upper limit of the range within which power requests are not allowed for
    the inverter.

    See [`frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds`][] and
    [`frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds`][] for more
    details.
    """
    # pylint: enable=line-too-long

    _component_state: inverter_pb.ComponentState.ValueType
    """State of the inverter."""

    _errors: List[inverter_pb.Error]
    """List of errors from the component."""

    @classmethod
    def from_proto(cls, raw: microgrid_pb.ComponentData) -> InverterData:
        """Create InverterData from a protobuf message.

        Args:
            raw: raw component data as decoded from the wire.

        Returns:
            Instance of InverterData created from the protobuf message.
        """
        raw_power = raw.inverter.data.ac.power_active
        inverter_data = cls(
            component_id=raw.id,
            timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
            active_power=raw.inverter.data.ac.power_active.value,
            active_power_inclusion_lower_bound=raw_power.system_inclusion_bounds.lower,
            active_power_exclusion_lower_bound=raw_power.system_exclusion_bounds.lower,
            active_power_inclusion_upper_bound=raw_power.system_inclusion_bounds.upper,
            active_power_exclusion_upper_bound=raw_power.system_exclusion_bounds.upper,
            _component_state=raw.inverter.state.component_state,
            _errors=list(raw.inverter.errors),
        )

        inverter_data._set_raw(raw=raw)
        return inverter_data
Attributes¤
active_power: float instance-attribute ¤

The 3-phase active power, in Watts, represented in the passive sign convention. +ve current means consumption, away from the grid. -ve current means supply into the grid.

active_power_exclusion_lower_bound: float instance-attribute ¤

Lower exclusion bound for inverter power in watts.

This is the lower limit of the range within which power requests are not allowed for the inverter.

See frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds and frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds for more details.

active_power_exclusion_upper_bound: float instance-attribute ¤

Upper exclusion bound for inverter power in watts.

This is the upper limit of the range within which power requests are not allowed for the inverter.

See frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds and frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds for more details.

active_power_inclusion_lower_bound: float instance-attribute ¤

Lower inclusion bound for inverter power in watts.

This is the lower limit of the range within which power requests are allowed for the inverter.

See frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds and frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds for more details.

active_power_inclusion_upper_bound: float instance-attribute ¤

Upper inclusion bound for inverter power in watts.

This is the upper limit of the range within which power requests are allowed for the inverter.

See frequenz.api.common.metrics_pb2.Metric.system_inclusion_bounds and frequenz.api.common.metrics_pb2.Metric.system_exclusion_bounds for more details.

Functions¤
from_proto(raw) classmethod ¤

Create InverterData from a protobuf message.

PARAMETER DESCRIPTION
raw

raw component data as decoded from the wire.

TYPE: ComponentData

RETURNS DESCRIPTION
InverterData

Instance of InverterData created from the protobuf message.

Source code in frequenz/sdk/microgrid/component/_component_data.py
@classmethod
def from_proto(cls, raw: microgrid_pb.ComponentData) -> InverterData:
    """Create InverterData from a protobuf message.

    Args:
        raw: raw component data as decoded from the wire.

    Returns:
        Instance of InverterData created from the protobuf message.
    """
    raw_power = raw.inverter.data.ac.power_active
    inverter_data = cls(
        component_id=raw.id,
        timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
        active_power=raw.inverter.data.ac.power_active.value,
        active_power_inclusion_lower_bound=raw_power.system_inclusion_bounds.lower,
        active_power_exclusion_lower_bound=raw_power.system_exclusion_bounds.lower,
        active_power_inclusion_upper_bound=raw_power.system_inclusion_bounds.upper,
        active_power_exclusion_upper_bound=raw_power.system_exclusion_bounds.upper,
        _component_state=raw.inverter.state.component_state,
        _errors=list(raw.inverter.errors),
    )

    inverter_data._set_raw(raw=raw)
    return inverter_data

frequenz.sdk.microgrid.component.InverterType ¤

Bases: ComponentType

Enum representing inverter types.

Source code in frequenz/sdk/microgrid/component/_component.py
class InverterType(ComponentType):
    """Enum representing inverter types."""

    NONE = inverter_pb.Type.TYPE_UNSPECIFIED
    BATTERY = inverter_pb.Type.TYPE_BATTERY
    SOLAR = inverter_pb.Type.TYPE_SOLAR
    HYBRID = inverter_pb.Type.TYPE_HYBRID

frequenz.sdk.microgrid.component.MeterData dataclass ¤

Bases: ComponentData

A wrapper class for holding meter data.

Source code in frequenz/sdk/microgrid/component/_component_data.py
@dataclass(frozen=True)
class MeterData(ComponentData):
    """A wrapper class for holding meter data."""

    active_power: float
    """The 3-phase active power, in Watts, represented in the passive sign convention.
            +ve current means consumption, away from the grid.
            -ve current means supply into the grid.
    """

    current_per_phase: Tuple[float, float, float]
    """AC current in Amperes (A) for phase/line 1,2 and 3 respectively.
            +ve current means consumption, away from the grid.
            -ve current means supply into the grid.
    """

    voltage_per_phase: Tuple[float, float, float]
    """The ac voltage in volts (v) between the line and the neutral wire for phase/line
        1,2 and 3 respectively.
    """

    frequency: float
    """The AC power frequency in Hertz (Hz)."""

    @classmethod
    def from_proto(cls, raw: microgrid_pb.ComponentData) -> MeterData:
        """Create MeterData from a protobuf message.

        Args:
            raw: raw component data as decoded from the wire.

        Returns:
            Instance of MeterData created from the protobuf message.
        """
        meter_data = cls(
            component_id=raw.id,
            timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
            active_power=raw.meter.data.ac.power_active.value,
            current_per_phase=(
                raw.meter.data.ac.phase_1.current.value,
                raw.meter.data.ac.phase_2.current.value,
                raw.meter.data.ac.phase_3.current.value,
            ),
            voltage_per_phase=(
                raw.meter.data.ac.phase_1.voltage.value,
                raw.meter.data.ac.phase_2.voltage.value,
                raw.meter.data.ac.phase_3.voltage.value,
            ),
            frequency=raw.meter.data.ac.frequency.value,
        )
        meter_data._set_raw(raw=raw)
        return meter_data
Attributes¤
active_power: float instance-attribute ¤

The 3-phase active power, in Watts, represented in the passive sign convention. +ve current means consumption, away from the grid. -ve current means supply into the grid.

current_per_phase: Tuple[float, float, float] instance-attribute ¤

AC current in Amperes (A) for phase/line 1,2 and 3 respectively. +ve current means consumption, away from the grid. -ve current means supply into the grid.

frequency: float instance-attribute ¤

The AC power frequency in Hertz (Hz).

voltage_per_phase: Tuple[float, float, float] instance-attribute ¤

The ac voltage in volts (v) between the line and the neutral wire for phase/line 1,2 and 3 respectively.

Functions¤
from_proto(raw) classmethod ¤

Create MeterData from a protobuf message.

PARAMETER DESCRIPTION
raw

raw component data as decoded from the wire.

TYPE: ComponentData

RETURNS DESCRIPTION
MeterData

Instance of MeterData created from the protobuf message.

Source code in frequenz/sdk/microgrid/component/_component_data.py
@classmethod
def from_proto(cls, raw: microgrid_pb.ComponentData) -> MeterData:
    """Create MeterData from a protobuf message.

    Args:
        raw: raw component data as decoded from the wire.

    Returns:
        Instance of MeterData created from the protobuf message.
    """
    meter_data = cls(
        component_id=raw.id,
        timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
        active_power=raw.meter.data.ac.power_active.value,
        current_per_phase=(
            raw.meter.data.ac.phase_1.current.value,
            raw.meter.data.ac.phase_2.current.value,
            raw.meter.data.ac.phase_3.current.value,
        ),
        voltage_per_phase=(
            raw.meter.data.ac.phase_1.voltage.value,
            raw.meter.data.ac.phase_2.voltage.value,
            raw.meter.data.ac.phase_3.voltage.value,
        ),
        frequency=raw.meter.data.ac.frequency.value,
    )
    meter_data._set_raw(raw=raw)
    return meter_data