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
8 changes: 7 additions & 1 deletion packages/control/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,12 @@ def switch_off_check_timer(self, load: Load) -> None:
except Exception:
log.exception("Fehler im allgemeinen PV-Modul")

def _get_switch_off_threshold_by_load(self, load: Load) -> int:
if isinstance(load, Chargepoint):
return data.data.general_data.data.chargemode_config.surplus.vehicle.switch_off_threshold
else:
return data.data.general_data.data.chargemode_config.surplus.consumer.switch_off_threshold

def calc_switch_off_threshold(self, load: Load) -> float:
surplus_config = data.data.general_data.data.chargemode_config.surplus
control_parameter = load.data.control_parameter
Expand All @@ -510,7 +516,7 @@ def calc_switch_off_threshold(self, load: Load) -> float:
threshold = (-surplus_config.feed_in_yield
+ surplus_config.vehicle.switch_on_threshold*control_parameter.phases)
else:
threshold = surplus_config.consumer.switch_off_threshold
threshold = self._get_switch_off_threshold_by_load(load)
return threshold

def calc_switch_off(self, load: Load) -> Tuple[float, float]:
Expand Down
18 changes: 18 additions & 0 deletions packages/control/counter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ def test_control_range(control_range, evu_power, expected_range_offset, general_
assert range_offset == expected_range_offset


@pytest.mark.parametrize("load_factory, expected",
[pytest.param(lambda: Chargepoint(0, None), -200, id="Ladepunkt"),
pytest.param(lambda: Consumer(0), -50, id="Verbraucher")])
def test_calc_switch_off_threshold_by_load(load_factory, expected: float, general_data_fixture):
# setup
surplus_config = data.data.general_data.data.chargemode_config.surplus
surplus_config.feed_in_limit = False
surplus_config.vehicle.switch_off_threshold = -200
surplus_config.consumer.switch_off_threshold = -50
c = Counter(0)

# execution
threshold = c.calc_switch_off_threshold(load_factory())

# evaluation
assert threshold == expected


def test_reset_switch_on_off_ignores_stale_timestamp_without_delay_state(general_data_fixture, monkeypatch):
# setup
evu_counter = Counter(0)
Expand Down
Loading