From a5788afe4ef8aebe84830fb76b1a726b660c0acb Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Mon, 3 Jun 2024 10:00:31 +0200 Subject: [PATCH] fix template deletion --- packages/helpermodules/command.py | 16 ++++++++++++++-- packages/helpermodules/setdata.py | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/helpermodules/command.py b/packages/helpermodules/command.py index c296478a15..6b84ff1e17 100644 --- a/packages/helpermodules/command.py +++ b/packages/helpermodules/command.py @@ -344,7 +344,7 @@ def removeChargeTemplate(self, connection_id: str, payload: dict) -> None: pub_user_message(payload, connection_id, "Die ID ist größer als die maximal vergebene ID.", MessageType.ERROR) if payload["data"]["id"] > 0: - Pub().pub(f'openWB/vehicle/template/charge_template/{payload["data"]["id"]}', "") + ProcessBrokerBranch(f'vehicle/template/charge_template/{payload["data"]["id"]}/').remove_topics() pub_user_message( payload, connection_id, f'Lade-Profil mit ID \'{payload["data"]["id"]}\' gelöscht.', @@ -503,7 +503,7 @@ def removeEvTemplate(self, connection_id: str, payload: dict) -> None: pub_user_message(payload, connection_id, "Die ID ist größer als die maximal vergebene ID.", MessageType.ERROR) if payload["data"]["id"] > 0: - Pub().pub(f'openWB/vehicle/template/ev_template/{payload["data"]["id"]}', "") + ProcessBrokerBranch(f'vehicle/template/ev_template/{payload["data"]["id"]}/').remove_topics() pub_user_message( payload, connection_id, f'Fahrzeug-Profil mit ID \'{payload["data"]["id"]}\' gelöscht.', MessageType.SUCCESS) @@ -850,6 +850,18 @@ def __on_message_rm(self, client, userdata, msg): f'openWB/set/internal_chargepoint/{payload["configuration"]["duo_num"]}/data/parent_cp', None, hostname=payload["configuration"]["ip_address"]) + elif re.search("openWB/chargepoint/template/[0-9]+$", msg.topic) is not None: + for cp in SubData.cp_data.values(): + if cp.chargepoint.data.config.template == int(msg.topic.split("/")[-1]): + pub_single(f'openWB/set/chargepoint/{cp.chargepoint.num}/config/template', 0) + elif re.search("openWB/vehicle/template/charge_template/[0-9]+$", msg.topic) is not None: + for vehicle in SubData.ev_data.values(): + if vehicle.data.charge_template == int(msg.topic.split("/")[-1]): + pub_single(f'openWB/set/vehicle/{vehicle.num}/charge_template', 0) + elif re.search("openWB/vehicle/template/ev_template/[0-9]+$", msg.topic) is not None: + for vehicle in SubData.ev_data.values(): + if vehicle.data.ev_template == int(msg.topic.split("/")[-1]): + pub_single(f'openWB/set/vehicle/{vehicle.num}/ev_template', 0) def __on_message_max_id(self, client, userdata, msg): self.received_topics.append(msg.topic) diff --git a/packages/helpermodules/setdata.py b/packages/helpermodules/setdata.py index c21c4b3ee1..6498904af0 100644 --- a/packages/helpermodules/setdata.py +++ b/packages/helpermodules/setdata.py @@ -511,6 +511,8 @@ def process_chargepoint_topic(self, msg: mqtt.MQTTMessage): "openWB/set/chargepoint/get/daily_imported" in msg.topic or "openWB/set/chargepoint/get/daily_exported" in msg.topic): self._validate_value(msg, float, [(0, float("inf"))]) + elif re.search("chargepoint/[0-9]+/config/template$", msg.topic) is not None: + self._validate_value(msg, int, pub_json=True) elif "template" in msg.topic: self._validate_value(msg, "json") elif re.search("chargepoint/[0-9]+/config$", msg.topic) is not None: