Skip to content

Commit b7cabac

Browse files
Add more metrics to ComponentData
Add battery: relay state, component state, errors. Add inverter: relay state, component state, errors. Signed-off-by: ela-kotulska-frequenz <[email protected]>
1 parent 9c0b590 commit b7cabac

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from abc import ABC, abstractmethod
88
from dataclasses import dataclass, field
99
from datetime import datetime
10-
from typing import Optional, Tuple
10+
from typing import List, Optional, Tuple
1111

12+
import frequenz.api.microgrid.battery_pb2 as battery_pb
13+
import frequenz.api.microgrid.inverter_pb2 as inverter_pb
1214
import frequenz.api.microgrid.microgrid_pb2 as microgrid_pb
1315
import pytz
1416

@@ -128,6 +130,9 @@ class BatteryData(ComponentData):
128130
charging is possible.
129131
temperature_max: the maximum temperature of all the blocks in a battery, in
130132
Celcius (°C).
133+
_relay_state: state of the battery relay.
134+
_component_state: state of the battery.
135+
_errors: list of errors in protobuf struct.
131136
"""
132137

133138
soc: float
@@ -137,6 +142,9 @@ class BatteryData(ComponentData):
137142
power_lower_bound: float
138143
power_upper_bound: float
139144
temperature_max: float
145+
_relay_state: battery_pb.RelayState.ValueType
146+
_component_state: battery_pb.ComponentState.ValueType
147+
_errors: List[battery_pb.Error]
140148

141149
@classmethod
142150
def from_proto(cls, raw: microgrid_pb.ComponentData) -> BatteryData:
@@ -158,6 +166,9 @@ def from_proto(cls, raw: microgrid_pb.ComponentData) -> BatteryData:
158166
power_lower_bound=raw.battery.data.dc.power.system_bounds.lower,
159167
power_upper_bound=raw.battery.data.dc.power.system_bounds.upper,
160168
temperature_max=raw.battery.data.temperature.max,
169+
_relay_state=raw.battery.state.relay_state,
170+
_component_state=raw.battery.state.component_state,
171+
_errors=list(raw.battery.errors),
161172
)
162173
battery_data._set_raw(raw=raw)
163174
return battery_data
@@ -178,11 +189,15 @@ class InverterData(ComponentData):
178189
active_power_upper_bound: the maximum charge power, in Watts, represented in
179190
the passive sign convention. This will be a positive number, or zero if no
180191
charging is possible.
192+
_component_state: state of the inverter.
193+
_errors: list of errors from the component.
181194
"""
182195

183196
active_power: float
184197
active_power_lower_bound: float
185198
active_power_upper_bound: float
199+
_component_state: inverter_pb.ComponentState.ValueType
200+
_errors: List[inverter_pb.Error]
186201

187202
@classmethod
188203
def from_proto(cls, raw: microgrid_pb.ComponentData) -> InverterData:
@@ -200,7 +215,10 @@ def from_proto(cls, raw: microgrid_pb.ComponentData) -> InverterData:
200215
active_power=raw.inverter.data.ac.power_active.value,
201216
active_power_lower_bound=raw.inverter.data.ac.power_active.system_bounds.lower,
202217
active_power_upper_bound=raw.inverter.data.ac.power_active.system_bounds.upper,
218+
_component_state=raw.inverter.state.component_state,
219+
_errors=list(raw.inverter.errors),
203220
)
221+
204222
inverter_data._set_raw(raw=raw)
205223
return inverter_data
206224

0 commit comments

Comments
 (0)