Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Upgrading

<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
- Converting `Metric` enums from/to protobuf directly is not supported anymore, you need to use explicit conversion functions, like the ones in `frequenz.client.common.metrics.proto.v1alpha8`.

## New Features

Expand Down
167 changes: 71 additions & 96 deletions src/frequenz/client/common/metrics/_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

"""Supported metrics for microgrid components."""


import enum

from frequenz.api.common.v1alpha8.metrics import metrics_pb2


@enum.unique
class Metric(enum.Enum):
Expand Down Expand Up @@ -42,237 +39,215 @@ class Metric(enum.Enum):
period, and therefore can be inconsistent.
"""

UNSPECIFIED = metrics_pb2.METRIC_UNSPECIFIED
UNSPECIFIED = 0
"""The metric is unspecified (this should not be used)."""

DC_VOLTAGE = metrics_pb2.METRIC_DC_VOLTAGE
DC_VOLTAGE = 1
"""The DC voltage."""

DC_CURRENT = metrics_pb2.METRIC_DC_CURRENT
DC_CURRENT = 2
"""The DC current."""

DC_POWER = metrics_pb2.METRIC_DC_POWER
DC_POWER = 3
"""The DC power."""

AC_FREQUENCY = metrics_pb2.METRIC_AC_FREQUENCY
AC_FREQUENCY = 10
"""The AC frequency."""

AC_VOLTAGE = metrics_pb2.METRIC_AC_VOLTAGE
AC_VOLTAGE = 11
"""The AC electric potential difference."""

AC_VOLTAGE_PHASE_1_N = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_1_N
AC_VOLTAGE_PHASE_1_N = 12
"""The AC electric potential difference between phase 1 and neutral."""

AC_VOLTAGE_PHASE_2_N = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_2_N
AC_VOLTAGE_PHASE_2_N = 13
"""The AC electric potential difference between phase 2 and neutral."""

AC_VOLTAGE_PHASE_3_N = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_3_N
AC_VOLTAGE_PHASE_3_N = 14
"""The AC electric potential difference between phase 3 and neutral."""

AC_VOLTAGE_PHASE_1_PHASE_2 = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_1_PHASE_2
AC_VOLTAGE_PHASE_1_PHASE_2 = 15
"""The AC electric potential difference between phase 1 and phase 2."""

AC_VOLTAGE_PHASE_2_PHASE_3 = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_2_PHASE_3
AC_VOLTAGE_PHASE_2_PHASE_3 = 16
"""The AC electric potential difference between phase 2 and phase 3."""

AC_VOLTAGE_PHASE_3_PHASE_1 = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_3_PHASE_1
AC_VOLTAGE_PHASE_3_PHASE_1 = 17
"""The AC electric potential difference between phase 3 and phase 1."""

AC_CURRENT = metrics_pb2.METRIC_AC_CURRENT
AC_CURRENT = 18
"""The AC current."""

AC_CURRENT_PHASE_1 = metrics_pb2.METRIC_AC_CURRENT_PHASE_1
AC_CURRENT_PHASE_1 = 19
"""The AC current in phase 1."""

AC_CURRENT_PHASE_2 = metrics_pb2.METRIC_AC_CURRENT_PHASE_2
AC_CURRENT_PHASE_2 = 20
"""The AC current in phase 2."""

AC_CURRENT_PHASE_3 = metrics_pb2.METRIC_AC_CURRENT_PHASE_3
AC_CURRENT_PHASE_3 = 21
"""The AC current in phase 3."""

AC_POWER_APPARENT = metrics_pb2.METRIC_AC_POWER_APPARENT
AC_POWER_APPARENT = 22
"""The AC apparent power."""

AC_POWER_APPARENT_PHASE_1 = metrics_pb2.METRIC_AC_POWER_APPARENT_PHASE_1
AC_POWER_APPARENT_PHASE_1 = 23
"""The AC apparent power in phase 1."""

AC_POWER_APPARENT_PHASE_2 = metrics_pb2.METRIC_AC_POWER_APPARENT_PHASE_2
AC_POWER_APPARENT_PHASE_2 = 24
"""The AC apparent power in phase 2."""

AC_POWER_APPARENT_PHASE_3 = metrics_pb2.METRIC_AC_POWER_APPARENT_PHASE_3
AC_POWER_APPARENT_PHASE_3 = 25
"""The AC apparent power in phase 3."""

AC_POWER_ACTIVE = metrics_pb2.METRIC_AC_POWER_ACTIVE
AC_POWER_ACTIVE = 26
"""The AC active power."""

AC_POWER_ACTIVE_PHASE_1 = metrics_pb2.METRIC_AC_POWER_ACTIVE_PHASE_1
AC_POWER_ACTIVE_PHASE_1 = 27
"""The AC active power in phase 1."""

AC_POWER_ACTIVE_PHASE_2 = metrics_pb2.METRIC_AC_POWER_ACTIVE_PHASE_2
AC_POWER_ACTIVE_PHASE_2 = 28
"""The AC active power in phase 2."""

AC_POWER_ACTIVE_PHASE_3 = metrics_pb2.METRIC_AC_POWER_ACTIVE_PHASE_3
AC_POWER_ACTIVE_PHASE_3 = 29
"""The AC active power in phase 3."""

AC_POWER_REACTIVE = metrics_pb2.METRIC_AC_POWER_REACTIVE
AC_POWER_REACTIVE = 30
"""The AC reactive power."""

AC_POWER_REACTIVE_PHASE_1 = metrics_pb2.METRIC_AC_POWER_REACTIVE_PHASE_1
AC_POWER_REACTIVE_PHASE_1 = 31
"""The AC reactive power in phase 1."""

AC_POWER_REACTIVE_PHASE_2 = metrics_pb2.METRIC_AC_POWER_REACTIVE_PHASE_2
AC_POWER_REACTIVE_PHASE_2 = 32
"""The AC reactive power in phase 2."""

AC_POWER_REACTIVE_PHASE_3 = metrics_pb2.METRIC_AC_POWER_REACTIVE_PHASE_3
AC_POWER_REACTIVE_PHASE_3 = 33
"""The AC reactive power in phase 3."""

AC_POWER_FACTOR = metrics_pb2.METRIC_AC_POWER_FACTOR
AC_POWER_FACTOR = 40
"""The AC power factor."""

AC_POWER_FACTOR_PHASE_1 = metrics_pb2.METRIC_AC_POWER_FACTOR_PHASE_1
AC_POWER_FACTOR_PHASE_1 = 41
"""The AC power factor in phase 1."""

AC_POWER_FACTOR_PHASE_2 = metrics_pb2.METRIC_AC_POWER_FACTOR_PHASE_2
AC_POWER_FACTOR_PHASE_2 = 42
"""The AC power factor in phase 2."""

AC_POWER_FACTOR_PHASE_3 = metrics_pb2.METRIC_AC_POWER_FACTOR_PHASE_3
AC_POWER_FACTOR_PHASE_3 = 43
"""The AC power factor in phase 3."""

AC_ENERGY_APPARENT = metrics_pb2.METRIC_AC_ENERGY_APPARENT
AC_ENERGY_APPARENT = 50
"""The AC apparent energy."""

AC_ENERGY_APPARENT_PHASE_1 = metrics_pb2.METRIC_AC_ENERGY_APPARENT_PHASE_1
AC_ENERGY_APPARENT_PHASE_1 = 51
"""The AC apparent energy in phase 1."""

AC_ENERGY_APPARENT_PHASE_2 = metrics_pb2.METRIC_AC_ENERGY_APPARENT_PHASE_2
AC_ENERGY_APPARENT_PHASE_2 = 52
"""The AC apparent energy in phase 2."""

AC_ENERGY_APPARENT_PHASE_3 = metrics_pb2.METRIC_AC_ENERGY_APPARENT_PHASE_3
AC_ENERGY_APPARENT_PHASE_3 = 53
"""The AC apparent energy in phase 3."""

AC_ENERGY_ACTIVE = metrics_pb2.METRIC_AC_ENERGY_ACTIVE
AC_ENERGY_ACTIVE = 54
"""The AC active energy."""

AC_ENERGY_ACTIVE_PHASE_1 = metrics_pb2.METRIC_AC_ENERGY_ACTIVE_PHASE_1
AC_ENERGY_ACTIVE_PHASE_1 = 55
"""The AC active energy in phase 1."""

AC_ENERGY_ACTIVE_PHASE_2 = metrics_pb2.METRIC_AC_ENERGY_ACTIVE_PHASE_2
AC_ENERGY_ACTIVE_PHASE_2 = 56
"""The AC active energy in phase 2."""

AC_ENERGY_ACTIVE_PHASE_3 = metrics_pb2.METRIC_AC_ENERGY_ACTIVE_PHASE_3
AC_ENERGY_ACTIVE_PHASE_3 = 57
"""The AC active energy in phase 3."""

AC_ENERGY_ACTIVE_CONSUMED = metrics_pb2.METRIC_AC_ENERGY_ACTIVE_CONSUMED
AC_ENERGY_ACTIVE_CONSUMED = 58
"""The AC active energy consumed."""

AC_ENERGY_ACTIVE_CONSUMED_PHASE_1 = (
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_CONSUMED_PHASE_1
)
AC_ENERGY_ACTIVE_CONSUMED_PHASE_1 = 59
"""The AC active energy consumed in phase 1."""

AC_ENERGY_ACTIVE_CONSUMED_PHASE_2 = (
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_CONSUMED_PHASE_2
)
AC_ENERGY_ACTIVE_CONSUMED_PHASE_2 = 60
"""The AC active energy consumed in phase 2."""

AC_ENERGY_ACTIVE_CONSUMED_PHASE_3 = (
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_CONSUMED_PHASE_3
)
AC_ENERGY_ACTIVE_CONSUMED_PHASE_3 = 61
"""The AC active energy consumed in phase 3."""

AC_ENERGY_ACTIVE_DELIVERED = metrics_pb2.METRIC_AC_ENERGY_ACTIVE_DELIVERED
AC_ENERGY_ACTIVE_DELIVERED = 62
"""The AC active energy delivered."""

AC_ENERGY_ACTIVE_DELIVERED_PHASE_1 = (
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_DELIVERED_PHASE_1
)
AC_ENERGY_ACTIVE_DELIVERED_PHASE_1 = 63
"""The AC active energy delivered in phase 1."""

AC_ENERGY_ACTIVE_DELIVERED_PHASE_2 = (
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_DELIVERED_PHASE_2
)
AC_ENERGY_ACTIVE_DELIVERED_PHASE_2 = 64
"""The AC active energy delivered in phase 2."""

AC_ENERGY_ACTIVE_DELIVERED_PHASE_3 = (
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_DELIVERED_PHASE_3
)
AC_ENERGY_ACTIVE_DELIVERED_PHASE_3 = 65
"""The AC active energy delivered in phase 3."""

AC_ENERGY_REACTIVE = metrics_pb2.METRIC_AC_ENERGY_REACTIVE
AC_ENERGY_REACTIVE = 66
"""The AC reactive energy."""

AC_ENERGY_REACTIVE_PHASE_1 = metrics_pb2.METRIC_AC_ENERGY_REACTIVE_PHASE_1
AC_ENERGY_REACTIVE_PHASE_1 = 67
"""The AC reactive energy in phase 1."""

AC_ENERGY_REACTIVE_PHASE_2 = metrics_pb2.METRIC_AC_ENERGY_REACTIVE_PHASE_2
AC_ENERGY_REACTIVE_PHASE_2 = 68
"""The AC reactive energy in phase 2."""

AC_ENERGY_REACTIVE_PHASE_3 = metrics_pb2.METRIC_AC_ENERGY_REACTIVE_PHASE_3
AC_ENERGY_REACTIVE_PHASE_3 = 69
"""The AC reactive energy in phase 3."""

AC_TOTAL_HARMONIC_DISTORTION_CURRENT = (
metrics_pb2.METRIC_AC_TOTAL_HARMONIC_DISTORTION_CURRENT
)
AC_TOTAL_HARMONIC_DISTORTION_CURRENT = 80
"""The AC total harmonic distortion current."""

AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_1 = (
metrics_pb2.METRIC_AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_1
)
AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_1 = 81
"""The AC total harmonic distortion current in phase 1."""

AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_2 = (
metrics_pb2.METRIC_AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_2
)
AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_2 = 82
"""The AC total harmonic distortion current in phase 2."""

AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_3 = (
metrics_pb2.METRIC_AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_3
)
AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_3 = 83
"""The AC total harmonic distortion current in phase 3."""

BATTERY_CAPACITY = metrics_pb2.METRIC_BATTERY_CAPACITY
BATTERY_CAPACITY = 100
"""The capacity of the battery."""

BATTERY_SOC_PCT = metrics_pb2.METRIC_BATTERY_SOC_PCT
BATTERY_SOC_PCT = 101
"""The state of charge of the battery as a percentage."""

BATTERY_TEMPERATURE = metrics_pb2.METRIC_BATTERY_TEMPERATURE
BATTERY_TEMPERATURE = 102
"""The temperature of the battery."""

INVERTER_TEMPERATURE = metrics_pb2.METRIC_INVERTER_TEMPERATURE
INVERTER_TEMPERATURE = 120
"""The temperature of the inverter."""

INVERTER_TEMPERATURE_CABINET = metrics_pb2.METRIC_INVERTER_TEMPERATURE_CABINET
INVERTER_TEMPERATURE_CABINET = 121
"""The temperature of the inverter cabinet."""

INVERTER_TEMPERATURE_HEATSINK = metrics_pb2.METRIC_INVERTER_TEMPERATURE_HEATSINK
INVERTER_TEMPERATURE_HEATSINK = 122
"""The temperature of the inverter heatsink."""

INVERTER_TEMPERATURE_TRANSFORMER = (
metrics_pb2.METRIC_INVERTER_TEMPERATURE_TRANSFORMER
)
INVERTER_TEMPERATURE_TRANSFORMER = 123
"""The temperature of the inverter transformer."""

EV_CHARGER_TEMPERATURE = metrics_pb2.METRIC_EV_CHARGER_TEMPERATURE
EV_CHARGER_TEMPERATURE = 140
"""The temperature of the EV charger."""

SENSOR_WIND_SPEED = metrics_pb2.METRIC_SENSOR_WIND_SPEED
SENSOR_WIND_SPEED = 160
"""The speed of the wind measured."""

SENSOR_WIND_DIRECTION = metrics_pb2.METRIC_SENSOR_WIND_DIRECTION
SENSOR_WIND_DIRECTION = 161
"""The direction of the wind measured."""

SENSOR_TEMPERATURE = metrics_pb2.METRIC_SENSOR_TEMPERATURE
SENSOR_TEMPERATURE = 162
"""The temperature measured."""

SENSOR_RELATIVE_HUMIDITY = metrics_pb2.METRIC_SENSOR_RELATIVE_HUMIDITY
SENSOR_RELATIVE_HUMIDITY = 163
"""The relative humidity measured."""

SENSOR_DEW_POINT = metrics_pb2.METRIC_SENSOR_DEW_POINT
SENSOR_DEW_POINT = 164
"""The dew point measured."""

SENSOR_AIR_PRESSURE = metrics_pb2.METRIC_SENSOR_AIR_PRESSURE
SENSOR_AIR_PRESSURE = 165
"""The air pressure measured."""

SENSOR_IRRADIANCE = metrics_pb2.METRIC_SENSOR_IRRADIANCE
SENSOR_IRRADIANCE = 166
"""The irradiance measured."""
11 changes: 11 additions & 0 deletions src/frequenz/client/common/metrics/proto/v1alpha8/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# License: MIT
# Copyright © 2026 Frequenz Energy-as-a-Service GmbH

"""Conversion of Metric from/to protobuf v1alpha8."""

from ._metric import metric_from_proto, metric_to_proto

__all__ = [
"metric_from_proto",
"metric_to_proto",
]
34 changes: 34 additions & 0 deletions src/frequenz/client/common/metrics/proto/v1alpha8/_metric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# License: MIT
# Copyright © 2026 Frequenz Energy-as-a-Service GmbH

"""Coversion of Metric to/from protobuf v1alpha8."""


from frequenz.api.common.v1alpha8.metrics import metrics_pb2

from ....proto import enum_from_proto
from ..._metric import Metric


def metric_from_proto(message: metrics_pb2.Metric.ValueType) -> Metric | int:
"""Convert a protobuf Metric message to a Metric enum member.

Args:
message: A protobuf Metric message.

Returns:
The corresponding Metric enum member.
"""
return enum_from_proto(message, Metric)


def metric_to_proto(metric: Metric) -> metrics_pb2.Metric.ValueType:
"""Convert a Metric enum member to a protobuf Metric message.

Args:
metric: A Metric enum member.

Returns:
The corresponding protobuf Metric message.
"""
return metrics_pb2.Metric.ValueType(metric.value)
Loading