Skip to content
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
3 changes: 3 additions & 0 deletions packages/control/counter_all/counter_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def _calc_home_consumption_from_counter(

if comp.data.get.fault_state < 2:
if child["type"] == ComponentType.COUNTER.value:
# Die Funktion muss in jedem Rekursionsschritt ausgeführt werden, da die Funktion nur
# Hybrid-Batterien berücksichtigt, wenn diese direkt unter dem aktuellen Zähler hängen
child["children"] = self.get_elements_for_downstream_calculation(child["id"])
add_home_consumption, add_not_home_consumption = self._calc_home_consumption_from_counter(
child, child_home_consumption)
home_consumption += add_home_consumption
Expand Down
25 changes: 25 additions & 0 deletions packages/control/counter_all/counter_home_consumption_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ def test_calc_home_consumption(counter_all: Callable[[], CounterAll], data_):
assert home_consumption == 500


@pytest.mark.parametrize(
"battery_power",
[pytest.param(-500, id="discharging"), pytest.param(500, id="charging")],
)
def test_calc_home_consumption_with_hybrid_battery_below_nested_counter(battery_power: int, data_):
c = hierarchy_nested()
root = c.data.get.hierarchy[0]
nested_counter = root["children"][1]
inverter = root["children"].pop(2)
inverter["children"].append(root["children"].pop(2))
nested_counter["children"].append(inverter)

data.data.bat_data["bat2"].data.get.power = battery_power
data.data.pv_data["pv1"].data.get.power = -1000
for chargepoint in data.data.cp_data.values():
chargepoint.data.get.power = 100
data.data.counter_data["counter6"].data.get.power = battery_power - 700
data.data.counter_data["counter0"].data.get.power = battery_power - 400

home_consumption, not_in_home_consumption, _ = c._calc_home_consumption()

assert home_consumption == 200
assert not_in_home_consumption == 100


@pytest.mark.parametrize(
["counter_all", "expected_home_consumption"],
[
Expand Down
Loading