1515from control .chargepoint import chargepoint
1616from control .chargepoint .chargepoint_template import get_autolock_plan_default , get_chargepoint_template_default
1717
18- # ToDo: move to module commands if implemented
1918from control .ev .charge_template import get_new_charge_template
2019from control .ev .ev_template import EvTemplateData
2120from helpermodules import pub
2221from helpermodules .abstract_plans import ScheduledChargingPlan , TimeChargingPlan
2322from helpermodules .utils .run_command import run_command
23+ # ToDo: move to module commands if implemented
2424from modules .backup_clouds .onedrive .api import generateMSALAuthCode , retrieveMSALTokens
2525
2626from 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