Skip to content
Merged
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
64 changes: 28 additions & 36 deletions packages/helpermodules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,20 @@ def _get_max_ids(self) -> None:
max_id = default
for topic, payload in received_topics.items():
if re.search(topic_str, topic) is not None:
if id_topic == "autolock_plan":
for plan in payload["autolock"]["plans"]:
max_id = max(plan["id"], max_id)
elif id_topic == "charge_template_scheduled_plan":
for plan in payload["chargemode"]["scheduled_charging"]["plans"]:
max_id = max(plan["id"], max_id)
elif id_topic == "charge_template_time_charging_plan":
for plan in payload["time_charging"]["plans"]:
max_id = max(plan["id"], max_id)
try:
if id_topic == "autolock_plan":
for plan in payload["autolock"]["plans"]:
max_id = max(plan["id"], max_id)
elif id_topic == "charge_template_scheduled_plan":
for plan in payload["chargemode"]["scheduled_charging"]["plans"]:
max_id = max(plan["id"], max_id)
elif id_topic == "charge_template_time_charging_plan":
for plan in payload["time_charging"]["plans"]:
max_id = max(plan["id"], max_id)
except KeyError:
# überspringe Profile, die keinen Eintrag für Pläne haben.
# Da gab es einen Bug beim Kopieren.
pass
setattr(self, f'max_id_{id_topic}', max_id)
Pub().pub("openWB/set/command/max_id/"+id_topic, max_id)
for id_topic, topic_str, default in self.MAX_IDS["topic"]:
Expand Down Expand Up @@ -452,40 +457,27 @@ def removeAutolockPlan(self, connection_id: str, payload: dict) -> None:
def addChargeTemplate(self, connection_id: str, payload: dict) -> None:
""" sendet das Topic, zu dem ein neues Lade-Profil erstellt werden soll.
"""
# check if "payload" contains "data.copy"
if "data" in payload and "copy" in payload["data"]:
new_charge_template = asdict(data.data.ev_charge_template_data[f'ct{payload["data"]["copy"]}'].data).copy()
new_charge_template["chargemode"]["scheduled_charging"].pop("plans")
new_charge_template["time_charging"].pop("plans")
new_charge_template["name"] = f'Kopie von {new_charge_template["name"]}'
else:
new_charge_template = get_new_charge_template()
new_id = self.max_id_charge_template + 1
new_charge_template["id"] = new_id
Pub().pub("openWB/set/vehicle/template/charge_template/" +
str(new_id), new_charge_template)
self.max_id_charge_template = new_id
Pub().pub("openWB/set/command/max_id/charge_template", new_id)
# if copying a template, also copy schedule plans and time charging plans
# check if "payload" contains "data.copy"
if "data" in payload and "copy" in payload["data"]:
for _, plan in (data.data.ev_charge_template_data[f'ct{payload["data"]["copy"]}']
.data.chargemode.scheduled_charging.plans.items()):
new_plan = asdict(plan).copy()
new_plan["id"] = self.max_id_charge_template_scheduled_plan + 1
Pub().pub(f'openWB/set/vehicle/template/charge_template/{new_id}/'
f'chargemode/scheduled_charging/plans/{new_plan["id"]}',
new_plan)
new_charge_template = copy.deepcopy(data.data.ev_charge_template_data[f'ct{payload["data"]["copy"]}'].data)
new_charge_template.name = f'Kopie von {new_charge_template.name}'
for plan in new_charge_template.chargemode.scheduled_charging.plans:
plan.id = self.max_id_charge_template_scheduled_plan + 1
self.max_id_charge_template_scheduled_plan += 1
Pub().pub("openWB/set/command/max_id/charge_template_scheduled_plan", new_id)
for _, plan in (data.data.ev_charge_template_data[f'ct{payload["data"]["copy"]}']
.data.time_charging.plans.items()):
new_plan = asdict(plan).copy()
new_plan["id"] = self.max_id_charge_template_time_charging_plan + 1
Pub().pub(f'openWB/set/vehicle/template/charge_template/{new_id}/'
f'time_charging/plans/{new_plan["id"]}',
new_plan)
for plan in new_charge_template.time_charging.plans:
plan.id = self.max_id_charge_template_time_charging_plan + 1
self.max_id_charge_template_time_charging_plan += 1
Pub().pub("openWB/set/command/max_id/charge_template_time_charging_plan", new_id)
new_charge_template = asdict(new_charge_template)
else:
new_charge_template = get_new_charge_template()
new_charge_template["id"] = new_id

Pub().pub("openWB/set/command/max_id/charge_template", new_id)
Pub().pub(f"openWB/set/vehicle/template/charge_template/{new_id}", new_charge_template)
pub_user_message(payload, connection_id,
f'Neues Lade-Profil mit ID \'{new_id}\' hinzugefügt.',
MessageType.SUCCESS)
Expand Down