Skip to content

Commit e18a80b

Browse files
committed
implement copying charge templates
1 parent d8a4b3e commit e18a80b

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

packages/helpermodules/command.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
from control.chargepoint import chargepoint
1616
from control.chargepoint.chargepoint_template import get_autolock_plan_default, get_chargepoint_template_default
1717

18-
# ToDo: move to module commands if implemented
1918
from control.ev.charge_template import get_new_charge_template
2019
from control.ev.ev_template import EvTemplateData
2120
from helpermodules import pub
2221
from helpermodules.abstract_plans import ScheduledChargingPlan, TimeChargingPlan
2322
from helpermodules.utils.run_command import run_command
23+
# ToDo: move to module commands if implemented
2424
from modules.backup_clouds.onedrive.api import generateMSALAuthCode, retrieveMSALTokens
2525

2626
from helpermodules.broker import BrokerClient
@@ -428,14 +428,10 @@ def addChargeTemplate(self, connection_id: str, payload: dict) -> None:
428428
"""
429429
# check if "payload" contains "data.copy"
430430
if "data" in payload and "copy" in payload["data"]:
431-
pub_user_message(
432-
payload, connection_id,
433-
'Das Kopieren von Lade-Profilen ist noch nicht implementiert!',
434-
MessageType.ERROR)
435-
# new_charge_template = get_charge_template(payload["data"]["copy"])
436-
# copy schedule plans...
437-
# copy time charging plans...
438-
return
431+
new_charge_template = asdict(data.data.ev_charge_template_data[f'ct{payload["data"]["copy"]}'].data).copy()
432+
new_charge_template["chargemode"]["scheduled_charging"].pop("plans")
433+
new_charge_template["time_charging"].pop("plans")
434+
new_charge_template["name"] = f'Kopie von {new_charge_template["name"]}'
439435
else:
440436
new_charge_template = get_new_charge_template()
441437
new_id = self.max_id_charge_template + 1
@@ -444,6 +440,26 @@ def addChargeTemplate(self, connection_id: str, payload: dict) -> None:
444440
str(new_id), new_charge_template)
445441
self.max_id_charge_template = new_id
446442
Pub().pub("openWB/set/command/max_id/charge_template", new_id)
443+
# if copying a template, also copy schedule plans and time charging plans
444+
if "data" in payload and "copy" in payload["data"]:
445+
for _, plan in (data.data.ev_charge_template_data[f'ct{payload["data"]["copy"]}']
446+
.data.chargemode.scheduled_charging.plans.items()):
447+
new_plan = asdict(plan).copy()
448+
new_plan["id"] = self.max_id_charge_template_scheduled_plan + 1
449+
Pub().pub(f'openWB/set/vehicle/template/charge_template/{new_id}/'
450+
f'chargemode/scheduled_charging/plans/{new_plan["id"]}',
451+
new_plan)
452+
self.max_id_charge_template_scheduled_plan += 1
453+
Pub().pub("openWB/set/command/max_id/charge_template_scheduled_plan", new_id)
454+
for _, plan in (data.data.ev_charge_template_data[f'ct{payload["data"]["copy"]}']
455+
.data.time_charging.plans.items()):
456+
new_plan = asdict(plan).copy()
457+
new_plan["id"] = self.max_id_charge_template_time_charging_plan + 1
458+
Pub().pub(f'openWB/set/vehicle/template/charge_template/{new_id}/'
459+
f'time_charging/plans/{new_plan["id"]}',
460+
new_plan)
461+
self.max_id_charge_template_time_charging_plan += 1
462+
Pub().pub("openWB/set/command/max_id/charge_template_time_charging_plan", new_id)
447463
pub_user_message(payload, connection_id,
448464
f'Neues Lade-Profil mit ID \'{new_id}\' hinzugefügt.',
449465
MessageType.SUCCESS)

0 commit comments

Comments
 (0)