Skip to content

Commit 74a9b92

Browse files
committed
Add inclusion/exclusion bounds to low-level component data types
These follow the inclusion/exclusion bounds in the microgrid api. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent aba0576 commit 74a9b92

File tree

2 files changed

+96
-28
lines changed

2 files changed

+96
-28
lines changed

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

Lines changed: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,43 @@ class BatteryData(ComponentData):
130130
capacity: float
131131
"""The capacity of the battery in Wh (Watt-hour)."""
132132

133-
power_lower_bound: float
134-
"""The maximum discharge power, in watts, represented in the passive sign
135-
convention. this will be a negative number, or zero if no discharging is
136-
possible.
133+
# pylint: disable=line-too-long
134+
power_inclusion_lower_bound: float
135+
"""Lower inclusion bound for battery power in watts.
136+
137+
This is the lower limit of the range within which power requests are allowed for the
138+
battery.
139+
140+
More details [here](https://github.com/frequenz-floss/frequenz-api-common/blob/v0.3.0/proto/frequenz/api/common/metrics.proto#L37-L91).
141+
"""
142+
143+
power_exclusion_lower_bound: float
144+
"""Lower exclusion bound for battery power in watts.
145+
146+
This is the lower limit of the range within which power requests are not allowed for
147+
the battery.
148+
149+
More details [here](https://github.com/frequenz-floss/frequenz-api-common/blob/v0.3.0/proto/frequenz/api/common/metrics.proto#L37-L91).
137150
"""
138151

139-
power_upper_bound: float
140-
"""The maximum charge power, in Watts, represented in the passive sign convention.
141-
This will be a positive number, or zero if no charging is possible.
152+
power_inclusion_upper_bound: float
153+
"""Upper inclusion bound for battery power in watts.
154+
155+
This is the upper limit of the range within which power requests are allowed for the
156+
battery.
157+
158+
More details [here](https://github.com/frequenz-floss/frequenz-api-common/blob/v0.3.0/proto/frequenz/api/common/metrics.proto#L37-L91).
159+
"""
160+
161+
power_exclusion_upper_bound: float
162+
"""Upper exclusion bound for battery power in watts.
163+
164+
This is the upper limit of the range within which power requests are not allowed for
165+
the battery.
166+
167+
More details [here](https://github.com/frequenz-floss/frequenz-api-common/blob/v0.3.0/proto/frequenz/api/common/metrics.proto#L37-L91).
142168
"""
169+
# pylint: enable=line-too-long
143170

144171
temperature: float
145172
"""The (average) temperature reported by the battery, in Celcius (°C)."""
@@ -163,15 +190,18 @@ def from_proto(cls, raw: microgrid_pb.ComponentData) -> BatteryData:
163190
Returns:
164191
Instance of BatteryData created from the protobuf message.
165192
"""
193+
raw_power = raw.battery.data.dc.power
166194
battery_data = cls(
167195
component_id=raw.id,
168196
timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
169197
soc=raw.battery.data.soc.avg,
170-
soc_lower_bound=raw.battery.data.soc.system_bounds.lower,
171-
soc_upper_bound=raw.battery.data.soc.system_bounds.upper,
198+
soc_lower_bound=raw.battery.data.soc.system_inclusion_bounds.lower,
199+
soc_upper_bound=raw.battery.data.soc.system_inclusion_bounds.upper,
172200
capacity=raw.battery.properties.capacity,
173-
power_lower_bound=raw.battery.data.dc.power.system_bounds.lower,
174-
power_upper_bound=raw.battery.data.dc.power.system_bounds.upper,
201+
power_inclusion_lower_bound=raw_power.system_inclusion_bounds.lower,
202+
power_exclusion_lower_bound=raw_power.system_exclusion_bounds.lower,
203+
power_inclusion_upper_bound=raw_power.system_inclusion_bounds.upper,
204+
power_exclusion_upper_bound=raw_power.system_exclusion_bounds.upper,
175205
temperature=raw.battery.data.temperature.avg,
176206
_relay_state=raw.battery.state.relay_state,
177207
_component_state=raw.battery.state.component_state,
@@ -191,16 +221,43 @@ class InverterData(ComponentData):
191221
-ve current means supply into the grid.
192222
"""
193223

194-
active_power_lower_bound: float
195-
"""The maximum discharge power, in Watts, represented in the passive sign
196-
convention. This will be a negative number, or zero if no discharging is
197-
possible.
224+
# pylint: disable=line-too-long
225+
active_power_inclusion_lower_bound: float
226+
"""Lower inclusion bound for inverter power in watts.
227+
228+
This is the lower limit of the range within which power requests are allowed for the
229+
inverter.
230+
231+
More details [here](https://github.com/frequenz-floss/frequenz-api-common/blob/v0.3.0/proto/frequenz/api/common/metrics.proto#L37-L91).
232+
"""
233+
234+
active_power_exclusion_lower_bound: float
235+
"""Lower exclusion bound for inverter power in watts.
236+
237+
This is the lower limit of the range within which power requests are not allowed for
238+
the inverter.
239+
240+
More details [here](https://github.com/frequenz-floss/frequenz-api-common/blob/v0.3.0/proto/frequenz/api/common/metrics.proto#L37-L91).
198241
"""
199242

200-
active_power_upper_bound: float
201-
"""The maximum charge power, in Watts, represented in the passive sign convention.
202-
This will be a positive number, or zero if no charging is possible.
243+
active_power_inclusion_upper_bound: float
244+
"""Upper inclusion bound for inverter power in watts.
245+
246+
This is the upper limit of the range within which power requests are allowed for the
247+
inverter.
248+
249+
More details [here](https://github.com/frequenz-floss/frequenz-api-common/blob/v0.3.0/proto/frequenz/api/common/metrics.proto#L37-L91).
250+
"""
251+
252+
active_power_exclusion_upper_bound: float
253+
"""Upper exclusion bound for inverter power in watts.
254+
255+
This is the upper limit of the range within which power requests are not allowed for
256+
the inverter.
257+
258+
More details [here](https://github.com/frequenz-floss/frequenz-api-common/blob/v0.3.0/proto/frequenz/api/common/metrics.proto#L37-L91).
203259
"""
260+
# pylint: enable=line-too-long
204261

205262
_component_state: inverter_pb.ComponentState.ValueType
206263
"""State of the inverter."""
@@ -218,12 +275,15 @@ def from_proto(cls, raw: microgrid_pb.ComponentData) -> InverterData:
218275
Returns:
219276
Instance of InverterData created from the protobuf message.
220277
"""
278+
raw_power = raw.inverter.data.ac.power_active
221279
inverter_data = cls(
222280
component_id=raw.id,
223281
timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
224282
active_power=raw.inverter.data.ac.power_active.value,
225-
active_power_lower_bound=raw.inverter.data.ac.power_active.system_bounds.lower,
226-
active_power_upper_bound=raw.inverter.data.ac.power_active.system_bounds.upper,
283+
active_power_inclusion_lower_bound=raw_power.system_inclusion_bounds.lower,
284+
active_power_exclusion_lower_bound=raw_power.system_exclusion_bounds.lower,
285+
active_power_inclusion_upper_bound=raw_power.system_inclusion_bounds.upper,
286+
active_power_exclusion_upper_bound=raw_power.system_exclusion_bounds.upper,
227287
_component_state=raw.inverter.state.component_state,
228288
_errors=list(raw.inverter.errors),
229289
)

tests/utils/component_data_wrapper.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ def __init__( # pylint: disable=too-many-arguments
4141
soc_lower_bound: float = math.nan,
4242
soc_upper_bound: float = math.nan,
4343
capacity: float = math.nan,
44-
power_lower_bound: float = math.nan,
45-
power_upper_bound: float = math.nan,
44+
power_inclusion_lower_bound: float = math.nan,
45+
power_exclusion_lower_bound: float = math.nan,
46+
power_inclusion_upper_bound: float = math.nan,
47+
power_exclusion_upper_bound: float = math.nan,
4648
temperature: float = math.nan,
4749
_relay_state: battery_pb.RelayState.ValueType = (
4850
battery_pb.RelayState.RELAY_STATE_UNSPECIFIED
@@ -64,8 +66,10 @@ def __init__( # pylint: disable=too-many-arguments
6466
soc_lower_bound=soc_lower_bound,
6567
soc_upper_bound=soc_upper_bound,
6668
capacity=capacity,
67-
power_lower_bound=power_lower_bound,
68-
power_upper_bound=power_upper_bound,
69+
power_inclusion_lower_bound=power_inclusion_lower_bound,
70+
power_exclusion_lower_bound=power_exclusion_lower_bound,
71+
power_inclusion_upper_bound=power_inclusion_upper_bound,
72+
power_exclusion_upper_bound=power_exclusion_upper_bound,
6973
temperature=temperature,
7074
_relay_state=_relay_state,
7175
_component_state=_component_state,
@@ -96,8 +100,10 @@ def __init__( # pylint: disable=too-many-arguments
96100
component_id: int,
97101
timestamp: datetime,
98102
active_power: float = math.nan,
99-
active_power_lower_bound: float = math.nan,
100-
active_power_upper_bound: float = math.nan,
103+
active_power_inclusion_lower_bound: float = math.nan,
104+
active_power_exclusion_lower_bound: float = math.nan,
105+
active_power_inclusion_upper_bound: float = math.nan,
106+
active_power_exclusion_upper_bound: float = math.nan,
101107
_component_state: inverter_pb.ComponentState.ValueType = (
102108
inverter_pb.ComponentState.COMPONENT_STATE_UNSPECIFIED
103109
),
@@ -112,8 +118,10 @@ def __init__( # pylint: disable=too-many-arguments
112118
component_id=component_id,
113119
timestamp=timestamp,
114120
active_power=active_power,
115-
active_power_lower_bound=active_power_lower_bound,
116-
active_power_upper_bound=active_power_upper_bound,
121+
active_power_inclusion_lower_bound=active_power_inclusion_lower_bound,
122+
active_power_exclusion_lower_bound=active_power_exclusion_lower_bound,
123+
active_power_inclusion_upper_bound=active_power_inclusion_upper_bound,
124+
active_power_exclusion_upper_bound=active_power_exclusion_upper_bound,
117125
_component_state=_component_state,
118126
_errors=_errors if _errors else [],
119127
)

0 commit comments

Comments
 (0)