Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plan ids in connected vehicle #1958

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 14 additions & 14 deletions packages/control/ev/charge_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class SelectedPlan:
max_current: int = 16
missing_amount: float = 0
phases: int = 1
num: int = 0
id: int = 0


@dataclass
Expand Down Expand Up @@ -150,22 +150,22 @@ def time_charging(self,
current = plan.current if charging_type == ChargingType.AC.value else plan.dc_current
if self.data.et.active and data.data.optional_data.et_provider_available():
if not data.data.optional_data.et_price_lower_than_limit(self.data.et.max_price):
return 0, "stop", self.CHARGING_PRICE_EXCEEDED, plan.name
return 0, "stop", self.CHARGING_PRICE_EXCEEDED, plan.id
if plan.limit.selected == "none": # kein Limit konfiguriert, mit konfigurierter Stromstärke laden
return current, "time_charging", message, plan.name
return current, "time_charging", message, plan.id
elif plan.limit.selected == "soc": # SoC Limit konfiguriert
if soc:
if soc < plan.limit.soc:
return current, "time_charging", message, plan.name # Limit nicht erreicht
return current, "time_charging", message, plan.id # Limit nicht erreicht
else:
return 0, "stop", self.TIME_CHARGING_SOC_REACHED, plan.name # Limit erreicht
return 0, "stop", self.TIME_CHARGING_SOC_REACHED, plan.id # Limit erreicht
else:
return plan.current, "time_charging", message, plan.name
return plan.current, "time_charging", message, plan.id
elif plan.limit.selected == "amount": # Energiemengenlimit konfiguriert
if used_amount_time_charging < plan.limit.amount:
return current, "time_charging", message, plan.name # Limit nicht erreicht
return current, "time_charging", message, plan.id # Limit nicht erreicht
else:
return 0, "stop", self.TIME_CHARGING_AMOUNT_REACHED, plan.name # Limit erreicht
return 0, "stop", self.TIME_CHARGING_AMOUNT_REACHED, plan.id # Limit erreicht
else:
raise TypeError(f'{plan.limit.selected} unbekanntes Zeitladen-Limit.')
else:
Expand Down Expand Up @@ -260,7 +260,7 @@ def scheduled_charging_recent_plan(self,
used_amount: float,
max_phases: int,
phase_switch_supported: bool,
charging_type: str) -> Tuple[Optional[SelectedPlan], float]:
charging_type: str) -> Optional[SelectedPlan]:
""" prüft, ob der Ziel-SoC oder die Ziel-Energiemenge erreicht wurde und stellt den zur Erreichung nötigen
Ladestrom ein. Um etwas mehr Puffer zu haben, wird bis 20 Min nach dem Zieltermin noch geladen, wenn dieser
nicht eingehalten werden konnte.
Expand Down Expand Up @@ -310,7 +310,7 @@ def _search_plan(self,
missed_date_today_of_plan_with_smallest_remaining_time = False
plan_data: Optional[SelectedPlan] = None
battery_capacity = ev_template.data.battery_capacity
for num, plan in self.data.chargemode.scheduled_charging.plans.items():
for plan in self.data.chargemode.scheduled_charging.plans.values():
if plan.active:
if plan.limit.selected == "soc" and soc is None:
raise ValueError("Um Zielladen mit SoC-Ziel nutzen zu können, bitte ein SoC-Modul konfigurieren "
Expand Down Expand Up @@ -341,10 +341,10 @@ def _search_plan(self,
available_current=available_current,
max_current=max_current,
phases=phases,
num=num,
id=plan.id,
missing_amount=missing_amount,
duration=duration)
log.debug(f"Plan-Nr. {num}: Differenz zum Start {remaining_time}s, Dauer {duration/3600}h, "
log.debug(f"Plan-Nr. {plan.id}: Differenz zum Start {remaining_time}s, Dauer {duration/3600}h, "
f"Termin heute verpasst: {missed_date_today}")
except Exception:
log.exception("Fehler im ev-Modul "+str(self.ct_num))
Expand Down Expand Up @@ -380,7 +380,7 @@ def _calculate_duration(self,
SCHEDULED_CHARGING_REACHED_SCHEDULED_SOC = ("Falls vorhanden wird mit EVU-Überschuss geladen, da der Ziel-Soc "
"für Zielladen bereits erreicht wurde.")
SCHEDULED_CHARGING_NO_PLANS_CONFIGURED = "Keine Ladung, da keine Ziel-Termine konfiguriert sind."
SCHEDULED_CHARGING_NO_DATE_PENDING = "Kein Zielladen, da kein Ziel-Termin in den nächsten 24 Stunden ansteht."
SCHEDULED_CHARGING_NO_DATE_PENDING = "Kein Zielladen, da kein Ziel-Termin ansteht."
SCHEDULED_CHARGING_USE_PV = ("Kein Zielladen, da noch Zeit bis zum Zieltermin ist. Falls vorhanden, "
"wird mit Überschuss geladen.")
SCHEDULED_CHARGING_MAX_CURRENT = ("Zielladen mit {}A. Der Ladestrom wurde erhöht, um den Zieltermin zu erreichen. "
Expand All @@ -407,7 +407,7 @@ def scheduled_charging_calc_current(self,
return current, submode, self.SCHEDULED_CHARGING_NO_PLANS_CONFIGURED, control_parameter_phases
else:
return current, submode, self.SCHEDULED_CHARGING_NO_DATE_PENDING, control_parameter_phases
current_plan = self.data.chargemode.scheduled_charging.plans[plan_data.num]
current_plan = self.data.chargemode.scheduled_charging.plans[str(plan_data.id)]
limit = current_plan.limit
phases = plan_data.phases
log.debug("Verwendeter Plan: "+str(current_plan.name))
Expand Down
2 changes: 1 addition & 1 deletion packages/control/ev/charge_template_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_search_plan(check_duration_return1: Tuple[Optional[float], bool],
if expected_plan_num is None:
assert plan_data is None
else:
assert plan_data.num == expected_plan_num
assert plan_data.id == expected_plan_num
assert plan_data.duration == 100


Expand Down
15 changes: 7 additions & 8 deletions packages/control/ev/ev.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,18 @@ def get_required_current(self,
charging_type)
soc_request_interval_offset = 0
if plan_data:
name = self.charge_template.data.chargemode.scheduled_charging.plans[plan_data.num].name
# Wenn mit einem neuen Plan geladen wird, muss auch die Energiemenge von neuem gezählt werden.
if (self.charge_template.data.chargemode.scheduled_charging.plans[plan_data.num].limit.
if (self.charge_template.data.chargemode.scheduled_charging.plans[str(plan_data.id)].limit.
selected == "amount" and
name != control_parameter.current_plan):
plan_data.id != control_parameter.current_plan):
control_parameter.imported_at_plan_start = imported
# Wenn der SoC ein paar Minuten alt ist, kann der Termin trotzdem gehalten werden.
# Zielladen kann nicht genauer arbeiten, als das Abfrageintervall vom SoC.
if (self.soc_module and
self.charge_template.data.chargemode.
scheduled_charging.plans[plan_data.num].limit.selected == "soc"):
scheduled_charging.plans[str(plan_data.id)].limit.selected == "soc"):
soc_request_interval_offset = self.soc_module.general_config.request_interval_charging
control_parameter.current_plan = name
control_parameter.current_plan = plan_data.id
else:
control_parameter.current_plan = None
required_current, submode, message, phases = self.charge_template.scheduled_charging_calc_current(
Expand All @@ -185,18 +184,18 @@ def get_required_current(self,
if control_parameter.imported_at_plan_start is None:
control_parameter.imported_at_plan_start = imported
used_amount = imported - control_parameter.imported_at_plan_start
tmp_current, tmp_submode, tmp_message, name = self.charge_template.time_charging(
tmp_current, tmp_submode, tmp_message, plan_id = self.charge_template.time_charging(
self.data.get.soc,
used_amount,
charging_type
)
# Info vom Zielladen erhalten
message = f"{message or ''} {tmp_message or ''}".strip()
if tmp_current > 0:
control_parameter.current_plan = name
# Wenn mit einem neuen Plan geladen wird, muss auch die Energiemenge von neuem gezählt werden.
if name != control_parameter.current_plan:
if plan_id != control_parameter.current_plan:
control_parameter.imported_at_plan_start = imported
control_parameter.current_plan = plan_id
required_current = tmp_current
submode = tmp_submode
if (required_current == 0) or (required_current is None):
Expand Down
4 changes: 3 additions & 1 deletion packages/helpermodules/abstract_plans.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import List
from typing import List, Optional


def once_factory() -> List:
Expand Down Expand Up @@ -63,6 +63,7 @@ class TimeframePlan(PlanBase):
class ScheduledChargingPlan(PlanBase):
current: int = 14
dc_current: float = 145
id: Optional[int] = None
name: str = "neuer Zielladen-Plan"
limit: ScheduledLimit = field(default_factory=scheduled_limit_factory)
time: str = "07:00" # ToDo: aktuelle Zeit verwenden
Expand All @@ -73,6 +74,7 @@ class TimeChargingPlan(TimeframePlan):
name: str = "neuer Zeitladen-Plan"
current: int = 16
dc_current: float = 145
id: Optional[int] = None
limit: Limit = field(default_factory=limit_factory)


Expand Down
10 changes: 6 additions & 4 deletions packages/helpermodules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,12 @@ def addChargeTemplateSchedulePlan(self, connection_id: str, payload: dict) -> No
""" sendet das Topic, zu dem ein neuer Zielladen-Plan erstellt werden soll.
"""
new_id = self.max_id_charge_template_scheduled_plan + 1
charge_template_default = dataclass_utils.asdict(ev.ScheduledChargingPlan())
charge_template_default = ev.ScheduledChargingPlan()
charge_template_default.id = new_id
Pub().pub(
f'openWB/set/vehicle/template/charge_template/{payload["data"]["template"]}'
f'/chargemode/scheduled_charging/plans/{new_id}',
charge_template_default)
dataclass_utils.asdict(charge_template_default))
self.max_id_charge_template_scheduled_plan = new_id
Pub().pub(
"openWB/set/command/max_id/charge_template_scheduled_plan", new_id)
Expand Down Expand Up @@ -399,11 +400,12 @@ def addChargeTemplateTimeChargingPlan(self, connection_id: str, payload: dict) -
""" sendet das Topic, zu dem ein neuer Zeitladen-Plan erstellt werden soll.
"""
new_id = self.max_id_charge_template_time_charging_plan + 1
time_charging_plan_default = dataclass_utils.asdict(ev.TimeChargingPlan())
time_charging_plan_default = ev.TimeChargingPlan()
time_charging_plan_default.id = new_id
Pub().pub(
f'openWB/set/vehicle/template/charge_template/{payload["data"]["template"]}'
f'/time_charging/plans/{new_id}',
time_charging_plan_default)
dataclass_utils.asdict(time_charging_plan_default))
self.max_id_charge_template_time_charging_plan = new_id
Pub().pub(
"openWB/set/command/max_id/charge_template_time_charging_plan", new_id)
Expand Down
12 changes: 11 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@


class UpdateConfig:
DATASTORE_VERSION = 68
DATASTORE_VERSION = 69
valid_topic = [
"^openWB/bat/config/configured$",
"^openWB/bat/config/power_limit_mode$",
Expand Down Expand Up @@ -1874,3 +1874,13 @@
return {"openWB/general/chargemode_config/phase_switch_delay": 5}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 68)

def upgrade_datastore_68(self) -> None:
def upgrade(topic: str, payload) -> Optional[dict]:
if (re.search("openWB/vehicle/template/charge_template/[0-9]+/chargemode/scheduled_charging/plans/[0-9]+", topic) is not None or

Check failure on line 1880 in packages/helpermodules/update_config.py

View workflow job for this annotation

GitHub Actions / build

line too long (140 > 120 characters)
re.search("openWB/vehicle/template/charge_template/[0-9]+/time_charging/plans/[0-9]+", topic) is not None):

Check failure on line 1881 in packages/helpermodules/update_config.py

View workflow job for this annotation

GitHub Actions / build

line too long (127 > 120 characters)
payload = decode_payload(payload)
payload["id"] = int(get_second_index(topic))
return {topic: payload}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 69)
Loading