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
13 changes: 13 additions & 0 deletions packages/helpermodules/measurement_logging/process_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,19 @@ def calc_energy_imported_by_source(energy_imported, energy_source):
pv = entry["pv"]["all"]["energy_exported"] if "all" in entry["pv"].keys() else 0
grid_imported, grid_exported = get_grid_from(entry)
consumption = grid_imported - grid_exported + pv + bat_exported - bat_imported + cp_exported
for type in ("bat", "cp"):
if entry[type]["all"]["energy_imported"] > consumption:
consumption += entry[type]["all"]["energy_imported"] - consumption
grid_imported += entry[type]["all"]["energy_imported"] - grid_imported
log.debug(f"Angepasste Verbrauchswerte für {type} um "
f"{entry[type]['all']['energy_imported'] - consumption} kWh")
for counter in entry["counter"].values():
if counter["grid"] is False:
if counter["energy_imported"] > consumption:
consumption += counter["energy_imported"] - consumption
grid_imported += counter["energy_imported"] - grid_imported
log.debug(f"Angepasste Verbrauchswerte für {type} um "
f"{entry[type]['all']['energy_imported'] - consumption} kWh")
try:
if grid_exported > pv:
# Ins Netz eingespeiste Leistung kam nicht von der PV-Anlage sondern aus dem Speicher
Expand Down
25 changes: 25 additions & 0 deletions packages/helpermodules/measurement_logging/process_log_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
from copy import deepcopy
from unittest.mock import Mock
import pytest

from helpermodules.measurement_logging import process_log
from helpermodules.measurement_logging.process_log import (
analyse_percentage,
_calculate_average_power,
process_entry,
get_totals,
CalculationType)

from helpermodules.measurement_logging.process_log_testdata import (counter_jumps_forward,
counter_jumps_forward_processed,
regular_daily_log_entry,
regular_daily_log_entry_processed)


def test_get_totals(daily_log_sample, daily_log_totals):
# setup and execution
Expand Down Expand Up @@ -52,3 +61,19 @@ def test_convert(daily_log_entry_kw, daily_log_sample):

# evaluation
assert entry == daily_log_entry_kw


@pytest.mark.parametrize("data, expected", [
pytest.param(counter_jumps_forward, counter_jumps_forward_processed, id="counter jumps forward"),
pytest.param(regular_daily_log_entry, regular_daily_log_entry_processed, id="regular daily log entry")
])
def test_get_daily_log(data, expected, monkeypatch):
# setup
collect_daily_log_data_mock = Mock(return_value=data)
monkeypatch.setattr(process_log, "_collect_daily_log_data", collect_daily_log_data_mock)

# execution
daily_log_processed = process_log.get_daily_log("20250616")

# evaluation
assert daily_log_processed == expected
Loading