Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DataSourcingActor to accept current requests for inverters #759

Merged
merged 5 commits into from
Nov 1, 2023
Merged
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
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ This version ships an experimental version of the **Power Manager**, adds prelim
- Fix rendering of diagrams in the documentation.
- The `__getitem__` magic of the `MovingWindow` is fixed to support the same functionality that the `window` method provides.
- Fixes incorrect implementation of single element access in `__getitem__` magic of `MovingWindow`.
- Fix incorrect grid current calculations in locations where the calculations depended on current measurements from an inverter.
27 changes: 21 additions & 6 deletions src/frequenz/sdk/actor/_data_sourcing/microgrid_api_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
ComponentMetricId.ACTIVE_POWER_INCLUSION_UPPER_BOUND: lambda msg: (
msg.active_power_inclusion_upper_bound
),
ComponentMetricId.CURRENT_PHASE_1: lambda msg: msg.current_per_phase[0],
ComponentMetricId.CURRENT_PHASE_2: lambda msg: msg.current_per_phase[1],
ComponentMetricId.CURRENT_PHASE_3: lambda msg: msg.current_per_phase[2],
ComponentMetricId.FREQUENCY: lambda msg: msg.frequency,
}

Expand Down Expand Up @@ -152,7 +155,9 @@ async def _check_battery_request(
"""
for metric in requests:
if metric not in _BatteryDataMethods:
raise ValueError(f"Unknown metric {metric} for Battery id {comp_id}")
err = f"Unknown metric {metric} for Battery id {comp_id}"
logging.error(err)
raise ValueError(err)
if comp_id not in self.comp_data_receivers:
self.comp_data_receivers[
comp_id
Expand All @@ -175,7 +180,9 @@ async def _check_ev_charger_request(
"""
for metric in requests:
if metric not in _EVChargerDataMethods:
raise ValueError(f"Unknown metric {metric} for EvCharger id {comp_id}")
err = f"Unknown metric {metric} for EvCharger id {comp_id}"
logging.error(err)
raise ValueError(err)
if comp_id not in self.comp_data_receivers:
self.comp_data_receivers[
comp_id
Expand All @@ -198,7 +205,9 @@ async def _check_inverter_request(
"""
for metric in requests:
if metric not in _InverterDataMethods:
raise ValueError(f"Unknown metric {metric} for Inverter id {comp_id}")
err = f"Unknown metric {metric} for Inverter id {comp_id}"
logging.error(err)
raise ValueError(err)
if comp_id not in self.comp_data_receivers:
self.comp_data_receivers[
comp_id
Expand All @@ -221,7 +230,9 @@ async def _check_meter_request(
"""
for metric in requests:
if metric not in _MeterDataMethods:
raise ValueError(f"Unknown metric {metric} for Meter id {comp_id}")
err = f"Unknown metric {metric} for Meter id {comp_id}"
logging.error(err)
raise ValueError(err)
if comp_id not in self.comp_data_receivers:
self.comp_data_receivers[
comp_id
Expand Down Expand Up @@ -257,7 +268,9 @@ async def _check_requested_component_and_metrics(
elif category == ComponentCategory.METER:
await self._check_meter_request(comp_id, requests)
else:
raise ValueError(f"Unknown component category {category}")
err = f"Unknown component category {category}"
logging.error(err)
raise ValueError(err)

def _get_data_extraction_method(
self, category: ComponentCategory, metric: ComponentMetricId
Expand All @@ -283,7 +296,9 @@ def _get_data_extraction_method(
return _MeterDataMethods[metric]
if category == ComponentCategory.EV_CHARGER:
return _EVChargerDataMethods[metric]
raise ValueError(f"Unknown component category {category}")
err = f"Unknown component category {category}"
logging.error(err)
raise ValueError(err)

def _get_metric_senders(
self,
Expand Down
11 changes: 11 additions & 0 deletions src/frequenz/sdk/microgrid/component/_component_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ class InverterData(ComponentData):
-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.
"""

# pylint: disable=line-too-long
active_power_inclusion_lower_bound: float
"""Lower inclusion bound for inverter power in watts.
Expand Down Expand Up @@ -301,6 +307,11 @@ def from_proto(cls, raw: microgrid_pb.ComponentData) -> InverterData:
component_id=raw.id,
timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
active_power=raw.inverter.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,
),
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,
Expand Down
6 changes: 6 additions & 0 deletions tests/utils/component_data_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def __init__( # pylint: disable=too-many-arguments
component_id: int,
timestamp: datetime,
active_power: float = math.nan,
current_per_phase: tuple[float, float, float] | None = None,
active_power_inclusion_lower_bound: float = math.nan,
active_power_exclusion_lower_bound: float = math.nan,
active_power_inclusion_upper_bound: float = math.nan,
Expand All @@ -120,6 +121,11 @@ def __init__( # pylint: disable=too-many-arguments
component_id=component_id,
timestamp=timestamp,
active_power=active_power,
current_per_phase=(
current_per_phase
if current_per_phase
else (math.nan, math.nan, math.nan)
),
active_power_inclusion_lower_bound=active_power_inclusion_lower_bound,
active_power_exclusion_lower_bound=active_power_exclusion_lower_bound,
active_power_inclusion_upper_bound=active_power_inclusion_upper_bound,
Expand Down