Skip to content

Commit fc484bd

Browse files
committed
Expose EVChargerComponentState through the ev_charger_data method
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 46df017 commit fc484bd

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/frequenz/sdk/microgrid/component/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
InverterData,
1515
MeterData,
1616
)
17-
from ._component_states import EVChargerCableState
17+
from ._component_states import EVChargerCableState, EVChargerComponentState
1818

1919
__all__ = [
2020
"BatteryData",
@@ -23,6 +23,7 @@
2323
"ComponentCategory",
2424
"ComponentMetricId",
2525
"EVChargerCableState",
26+
"EVChargerComponentState",
2627
"EVChargerData",
2728
"InverterData",
2829
"InverterType",

src/frequenz/sdk/microgrid/component/_component_data.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import frequenz.api.microgrid.microgrid_pb2 as microgrid_pb
1515
import pytz
1616

17-
from ._component_states import EVChargerCableState
17+
from ._component_states import EVChargerCableState, EVChargerComponentState
1818

1919

2020
@dataclass(frozen=True)
@@ -257,6 +257,9 @@ class EVChargerData(ComponentData):
257257
cable_state: EVChargerCableState
258258
"""The state of the ev charger's cable."""
259259

260+
component_state: EVChargerComponentState
261+
"""The state of the ev charger."""
262+
260263
@classmethod
261264
def from_proto(cls, raw: microgrid_pb.ComponentData) -> EVChargerData:
262265
"""Create EVChargerData from a protobuf message.
@@ -282,6 +285,9 @@ def from_proto(cls, raw: microgrid_pb.ComponentData) -> EVChargerData:
282285
raw.ev_charger.data.ac.phase_3.voltage.value,
283286
),
284287
cable_state=EVChargerCableState.from_pb(raw.ev_charger.state.cable_state),
288+
component_state=EVChargerComponentState.from_pb(
289+
raw.ev_charger.state.component_state
290+
),
285291
)
286292
ev_charger_data._set_raw(raw=raw)
287293
return ev_charger_data

src/frequenz/sdk/microgrid/component/_component_states.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,36 @@ def from_pb(
3939
return cls.UNSPECIFIED
4040

4141
return EVChargerCableState(evc_state)
42+
43+
44+
class EVChargerComponentState(Enum):
45+
"""Component State of an EV Charger."""
46+
47+
UNSPECIFIED = ev_charger_pb.ComponentState.COMPONENT_STATE_UNSPECIFIED
48+
STARTING = ev_charger_pb.ComponentState.COMPONENT_STATE_STARTING
49+
NOT_READY = ev_charger_pb.ComponentState.COMPONENT_STATE_NOT_READY
50+
READY = ev_charger_pb.ComponentState.COMPONENT_STATE_READY
51+
CHARGING = ev_charger_pb.ComponentState.COMPONENT_STATE_CHARGING
52+
DISCHARGING = ev_charger_pb.ComponentState.COMPONENT_STATE_DISCHARGING
53+
ERROR = ev_charger_pb.ComponentState.COMPONENT_STATE_ERROR
54+
AUTHORIZATION_REJECTED = (
55+
ev_charger_pb.ComponentState.COMPONENT_STATE_AUTHORIZATION_REJECTED
56+
)
57+
INTERRUPTED = ev_charger_pb.ComponentState.COMPONENT_STATE_INTERRUPTED
58+
59+
@classmethod
60+
def from_pb(
61+
cls, evc_state: ev_charger_pb.ComponentState.ValueType
62+
) -> EVChargerComponentState:
63+
"""Convert a protobuf ComponentState value to EVChargerComponentState enum.
64+
65+
Args:
66+
evc_state: protobuf component state to convert.
67+
68+
Returns:
69+
Enum value corresponding to the protobuf message.
70+
"""
71+
if not any(t.value == evc_state for t in EVChargerComponentState):
72+
return cls.UNSPECIFIED
73+
74+
return EVChargerComponentState(evc_state)

0 commit comments

Comments
 (0)