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
9 changes: 5 additions & 4 deletions packages/control/algorithm/additional_current.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from control.algorithm import common
from control.algorithm.chargemodes import CONSIDERED_CHARGE_MODES_ADDITIONAL_CURRENT
from control.loadmanagement import LimitingValue, Loadmanagement
from control.limiting_value import LoadmanagementLimit
from control.loadmanagement import Loadmanagement
from control.chargepoint.chargepoint import Chargepoint
from control.algorithm.filter_chargepoints import (get_chargepoints_by_mode_and_counter,
get_preferenced_chargepoint_charging)
Expand All @@ -28,7 +29,7 @@ def set_additional_current(self) -> None:
missing_currents, counts = common.get_missing_currents_left(preferenced_chargepoints)
available_currents, limit = Loadmanagement().get_available_currents(missing_currents, counter, cp)
log.debug(f"cp {cp.num} available currents {available_currents} missing currents "
f"{missing_currents} limit {limit}")
f"{missing_currents} limit {limit.message}")
cp.data.control_parameter.limit = limit
available_for_cp = common.available_current_for_cp(cp, counts, available_currents, missing_currents)
current = common.get_current_to_set(
Expand All @@ -46,7 +47,7 @@ def set_additional_current(self) -> None:
# tested
def _set_loadmangement_message(self,
current: float,
limit: LimitingValue,
limit: LoadmanagementLimit,
chargepoint: Chargepoint) -> None:
# Strom muss an diesem Zähler geändert werden
log.debug(
Expand All @@ -57,4 +58,4 @@ def _set_loadmangement_message(self,
round(current, 2) != round(max(
chargepoint.data.control_parameter.required_currents), 2)):
chargepoint.set_state_and_log(f"Es kann nicht mit der vorgegebenen Stromstärke geladen werden"
f"{limit}")
f"{limit.message}")
9 changes: 5 additions & 4 deletions packages/control/algorithm/additional_current_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
from control.chargepoint.control_parameter import ControlParameter
from control.ev.charge_template import ChargeTemplate
from control.ev.ev import Ev
from control.limiting_value import LoadmanagementLimit
from control.loadmanagement import LimitingValue


@pytest.mark.parametrize(
"set_current, limit, expected_msg",
[pytest.param(7, None, None, id="unverändert"),
[pytest.param(7, LoadmanagementLimit(None, None), None, id="unverändert"),
pytest.param(
6, LimitingValue.CURRENT.value.format('Garage'),
6, LoadmanagementLimit(LimitingValue.CURRENT.value.format('Garage'), LimitingValue.CURRENT),
f"Es kann nicht mit der vorgegebenen Stromstärke geladen werden{LimitingValue.CURRENT.value.format('Garage')}",
id="begrenzt durch Strom"),
pytest.param(
6, LimitingValue.POWER.value.format('Garage'),
6, LoadmanagementLimit(LimitingValue.POWER.value.format('Garage'), LimitingValue.POWER),
f"Es kann nicht mit der vorgegebenen Stromstärke geladen werden{LimitingValue.POWER.value.format('Garage')}",
id="begrenzt durch Leistung"),
pytest.param(
6, LimitingValue.UNBALANCED_LOAD.value.format('Garage'),
6, LoadmanagementLimit(LimitingValue.UNBALANCED_LOAD.value.format('Garage'), LimitingValue.UNBALANCED_LOAD),
f"Es kann nicht mit der vorgegebenen Stromstärke geladen werden"
f"{LimitingValue.UNBALANCED_LOAD.value.format('Garage')}",
id="begrenzt durch Schieflast"),
Expand Down
2 changes: 1 addition & 1 deletion packages/control/algorithm/min_current.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def set_min_current(self) -> None:
common.set_current_counterdiff(-(cp.data.set.current or 0), 0, cp)
if limit:
cp.set_state_and_log(
f"Ladung kann nicht gestartet werden{limit}")
f"Ladung kann nicht gestartet werden{limit.message}")
else:
common.set_current_counterdiff(
cp.data.set.target_current,
Expand Down
7 changes: 4 additions & 3 deletions packages/control/algorithm/surplus_controlled.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from control.chargepoint.chargepoint import Chargepoint
from control.chargepoint.chargepoint_state import ChargepointState, CHARGING_STATES
from control.counter import ControlRangeState, Counter
from control.limiting_value import LoadmanagementLimit
from control.loadmanagement import LimitingValue, Loadmanagement


Expand Down Expand Up @@ -82,16 +83,16 @@ def _set(self,

def _set_loadmangement_message(self,
current: float,
limit: LimitingValue,
limit: LoadmanagementLimit,
chargepoint: Chargepoint) -> None:
# Strom muss an diesem Zähler geändert werden
if (current != chargepoint.data.set.current and
# Strom erreicht nicht die vorgegebene Stromstärke
current != max(chargepoint.data.control_parameter.required_currents) and
# im PV-Laden wird der Strom immer durch die Leistung begrenzt
limit != LimitingValue.POWER):
limit.limiting_value != LimitingValue.POWER):
chargepoint.set_state_and_log(f"Es kann nicht mit der vorgegebenen Stromstärke geladen werden"
f"{limit}")
f"{limit.message}")

# tested
def filter_by_feed_in_limit(self, chargepoints: List[Chargepoint]) -> Tuple[List[Chargepoint], List[Chargepoint]]:
Expand Down
3 changes: 2 additions & 1 deletion packages/control/auto_phase_switch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from control.chargepoint.control_parameter import ControlParameter
from control.counter import Counter, CounterData, Set

from control.limiting_value import LoadmanagementLimit
from control.pv_all import PvAll
from control.bat_all import BatAll
from control.general import General
Expand Down Expand Up @@ -137,7 +138,7 @@ def test_auto_phase_switch(monkeypatch, vehicle: Ev, params: Params):
params.get_power,
32,
3,
None)
LoadmanagementLimit(None, None))

# evaluation
assert phases_to_use == params.expected_phases_to_use
Expand Down
5 changes: 3 additions & 2 deletions packages/control/chargepoint/control_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from control.chargepoint.chargepoint_state import ChargepointState
from control.chargemode import Chargemode as Chargemode_enum
from control.limiting_value import LimitingValue
from control.limiting_value import LoadmanagementLimit, loadmanagement_limit_factory
from dataclass_utils.factories import currents_list_factory


Expand All @@ -17,7 +17,8 @@ class ControlParameter:
default=None, metadata={"topic": "control_parameter/imported_at_plan_start"})
imported_instant_charging: Optional[float] = field(
default=None, metadata={"topic": "control_parameter/imported_instant_charging"})
limit: Optional[LimitingValue] = field(default=None, metadata={"topic": "control_parameter/limit"})
limit: Optional[LoadmanagementLimit] = field(default_factory=loadmanagement_limit_factory, metadata={
"topic": "control_parameter/limit"})
min_current: int = field(default=6, metadata={"topic": "control_parameter/min_current"})
phases: int = field(default=0, metadata={"topic": "control_parameter/phases"})
prio: bool = field(default=False, metadata={"topic": "control_parameter/prio"})
Expand Down
11 changes: 4 additions & 7 deletions packages/control/ev/ev.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""
from dataclasses import dataclass, field
import logging
import re
from typing import List, Optional, Tuple

from control import data
Expand All @@ -17,7 +16,7 @@
from control.chargepoint.control_parameter import ControlParameter
from control.ev.charge_template import ChargeTemplate
from control.ev.ev_template import EvTemplate
from control.limiting_value import LimitingValue
from control.limiting_value import LimitingValue, LoadmanagementLimit
from dataclass_utils.factories import empty_list_factory
from helpermodules import timecheck
from helpermodules.constants import NO_ERROR
Expand Down Expand Up @@ -294,7 +293,7 @@ def _check_phase_switch_conditions(self,
get_currents: List[float],
get_power: float,
max_current_cp: int,
limit: LimitingValue) -> Tuple[bool, Optional[str]]:
limit: LoadmanagementLimit) -> Tuple[bool, Optional[str]]:
# Manche EV laden mit 6.1A bei 6A Soll-Strom
min_current = (max(control_parameter.min_current, control_parameter.required_current) +
self.ev_template.data.nominal_difference)
Expand All @@ -309,9 +308,7 @@ def _check_phase_switch_conditions(self,
feed_in_yield = 0
all_surplus = data.data.counter_all_data.get_evu_counter().get_usable_surplus(feed_in_yield)
required_surplus = control_parameter.min_current * max_phases_ev * 230 - get_power
unblanced_load_limit_reached = (
limit is not None and
re.search(re.escape(LimitingValue.UNBALANCED_LOAD.value).replace(r'\{\}', r'.+'), limit))
unblanced_load_limit_reached = limit.limiting_value == LimitingValue.UNBALANCED_LOAD
condition_1_to_3 = (((max(get_currents) > max_current and
all_surplus > required_surplus) or unblanced_load_limit_reached) and
phases_in_use == 1)
Expand All @@ -335,7 +332,7 @@ def auto_phase_switch(self,
get_power: float,
max_current_cp: int,
max_phases: int,
limit: LimitingValue) -> Tuple[int, float, Optional[str]]:
limit: LoadmanagementLimit) -> Tuple[int, float, Optional[str]]:
message = None
timestamp_last_phase_switch = control_parameter.timestamp_last_phase_switch
current = control_parameter.required_current
Expand Down
12 changes: 12 additions & 0 deletions packages/control/limiting_value.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from dataclasses import dataclass
from enum import Enum
from typing import Optional


class LimitingValue(Enum):
Expand All @@ -11,3 +13,13 @@ class LimitingValue(Enum):
"reduziert wird.")
CONTROLLABLE_CONSUMERS_ERROR = (", da aufgrund eines Fehlers im IO-Gerät {} die steuerbaren Verbraucher nicht "
"gesteuert werden können. Bitte prüfe die Status-Seite.")


@dataclass
class LoadmanagementLimit:
message: Optional[str]
limiting_value: Optional[LimitingValue]


def loadmanagement_limit_factory() -> LoadmanagementLimit:
return LoadmanagementLimit(None, None)
Loading