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
6 changes: 3 additions & 3 deletions packages/control/ev/charge_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def _calc_remaining_time(self,
control_parameter_phases: int,
soc_request_interval_offset: int,
bidi_state: BidiState) -> SelectedPlan:
bidi = BidiState.BIDI_CAPABLE and plan.bidi
bidi = BidiState.BIDI_CAPABLE and plan.bidi_charging_enabled
if bidi:
duration, missing_amount = self._calculate_duration(
plan, soc, ev_template.data.battery_capacity,
Expand Down Expand Up @@ -553,14 +553,14 @@ def scheduled_charging_calc_current(self,
if limit.selected == "soc" and soc >= limit.soc_limit and soc >= limit.soc_scheduled:
message = self.SCHEDULED_CHARGING_REACHED_LIMIT_SOC
elif limit.selected == "soc" and limit.soc_scheduled <= soc < limit.soc_limit:
if plan.bidi and bidi_state == BidiState.BIDI_CAPABLE:
if plan.bidi_charging_enabled and bidi_state == BidiState.BIDI_CAPABLE:
message = self.SCHEDULED_CHARGING_BIDI
current = min_current
submode = "bidi_charging"
phases = control_parameter_phases
else:
message = self.SCHEDULED_CHARGING_REACHED_SCHEDULED_SOC
if plan.bidi and bidi_state != BidiState.BIDI_CAPABLE:
if plan.bidi_charging_enabled and bidi_state != BidiState.BIDI_CAPABLE:
message += bidi_state.value
current = min_current
submode = "pv_charging"
Expand Down
14 changes: 7 additions & 7 deletions packages/control/ev/charge_template_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,24 @@ def test_calc_remaining_time(phases_to_use,


@pytest.mark.parametrize(
"selected, phases, bidi, expected_duration, expected_missing_amount",
"selected, phases, bidi_charging_enabled, expected_duration, expected_missing_amount",
[
pytest.param("soc", 1, False, 10062.111801242236, 9000, id="soc, one phase"),
pytest.param("amount", 2, False, 447.2049689440994, 800, id="amount, two phases"),
pytest.param("soc", 2, True, 3240.0, 9000, id="bidi"),
])
def test_calculate_duration(selected: str,
phases: int,
bidi: bool,
bidi_charging_enabled: bool,
expected_duration: float,
expected_missing_amount: float):
# setup
ct = ChargeTemplate()
plan = ScheduledChargingPlan(bidi=bidi)
plan = ScheduledChargingPlan(bidi_charging_enabled=bidi_charging_enabled)
plan.limit.selected = selected
# execution
duration, missing_amount = ct._calculate_duration(
plan, 60, 45000, 200, phases, ChargingType.AC.value, EvTemplate(), bidi)
plan, 60, 45000, 200, phases, ChargingType.AC.value, EvTemplate(), bidi_charging_enabled)

# evaluation
assert duration == expected_duration
Expand Down Expand Up @@ -226,7 +226,7 @@ def test_scheduled_charging_recent_plan(end_time_mock,


@pytest.mark.parametrize(
"plan_data, soc, used_amount, selected, bidi, expected",
"plan_data, soc, used_amount, selected, bidi_charging_enabled, expected",
[
pytest.param(None, 0, 0, "none", False, (0, "stop",
ChargeTemplate.SCHEDULED_CHARGING_NO_DATE_PENDING, 3), id="no date pending"),
Expand Down Expand Up @@ -262,13 +262,13 @@ def test_scheduled_charging_calc_current(plan_data: SelectedPlan,
soc: int,
used_amount: float,
selected: str,
bidi: bool,
bidi_charging_enabled: bool,
expected: Tuple[float, str, str, int]):
# setup
ct = ChargeTemplate()
plan = ScheduledChargingPlan(active=True, id=0)
plan.limit.selected = selected
plan.bidi = bidi
plan.bidi_charging_enabled = bidi_charging_enabled
# json verwandelt Keys in strings
ct.data.chargemode.scheduled_charging.plans = [plan]
if plan_data:
Expand Down
2 changes: 1 addition & 1 deletion packages/helpermodules/abstract_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TimeframePlan(PlanBase):

@dataclass
class ScheduledChargingPlan(PlanBase):
bidi: bool = False
bidi_charging_enabled: bool = False
bidi_power: int = 10000
current: int = 14
dc_current: float = 145
Expand Down
15 changes: 14 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

class UpdateConfig:

DATASTORE_VERSION = 92
DATASTORE_VERSION = 93

valid_topic = [
"^openWB/bat/config/bat_control_permitted$",
Expand Down Expand Up @@ -2412,3 +2412,16 @@ def upgrade(topic: str, payload) -> Optional[dict]:
return {topic: payload}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 92)

def upgrade_datastore_92(self) -> None:
def upgrade(topic: str, payload) -> Optional[dict]:
if re.search("openWB/vehicle/template/charge_template/[0-9]+$", topic) is not None:
payload = decode_payload(payload)
for plan in payload["chargemode"]["scheduled_charging"]["plans"]:
if "bidi" in plan:
bidi_charging_enabled = plan["bidi"]
plan.pop("bidi")
plan.update({"bidi_charging_enabled": bidi_charging_enabled})
return {topic: payload}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 93)