From 2b0c6f2a18857c8153fd1dc30fcfc6990fd6ab20 Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Mon, 25 Sep 2023 09:19:44 +0200 Subject: [PATCH 1/4] fix parent_cp --- packages/helpermodules/command.py | 9 ++++++++- packages/helpermodules/setdata.py | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/helpermodules/command.py b/packages/helpermodules/command.py index 505adc4adf..2f715bc7d4 100644 --- a/packages/helpermodules/command.py +++ b/packages/helpermodules/command.py @@ -18,7 +18,7 @@ from helpermodules.measurement_logging.process_log import get_daily_log, get_monthly_log, get_yearly_log from helpermodules.messaging import MessageType, pub_user_message, pub_error_global from helpermodules.parse_send_debug import parse_send_debug_data -from helpermodules.pub import Pub +from helpermodules.pub import Pub, pub_single from helpermodules.subdata import SubData from helpermodules.utils.topic_parser import decode_payload from control import bat, bridge, chargelog, data, ev, counter, counter_all, pv @@ -794,6 +794,13 @@ def __on_message_rm(self, client, userdata, msg): topic = type_to_topic_mapping(payload["type"]) data.data.counter_all_data.hierarchy_remove_item(payload["id"]) client.subscribe(f'openWB/{topic}/{payload["id"]}/#', 2) + elif "openWB/chargepoint/" in msg.topic and "/config" in msg.topic: + payload = decode_payload(msg.payload) + if payload["type"] == "external_openwb": + pub_single( + f'openWB/set/internal_chargepoint/{payload["configuration"]["duo_num"]}/data/parent_cp', + None, + hostname=payload["configuration"]["ip_address"]) 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 3e656ccee5..4f10008330 100644 --- a/packages/helpermodules/setdata.py +++ b/packages/helpermodules/setdata.py @@ -1022,7 +1022,10 @@ def process_internal_chargepoint_topic(self, msg): if "data/cp_interruption_duration" in msg.topic: self._validate_value(msg, int, [(0, float("inf"))]) elif "data/parent_cp" in msg.topic: - self._validate_value(msg, str) + for cp in subdata.SubData.cp_data.values(): + if cp.chargepoint.data.config.type == "internal_openwb": + if get_index(msg.topic) == cp.chargepoint.data.config.configuration.duo_num: + self._validate_value(msg, str) elif "data/set_current" in msg.topic: self._validate_value(msg, float, [(0, 0), (6, 32)]) elif "data/phases_to_use" in msg.topic: From 0097a1d074dde0727df757da1e568f8961c37f0d Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Mon, 25 Sep 2023 09:31:10 +0200 Subject: [PATCH 2/4] fix --- packages/helpermodules/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/helpermodules/command.py b/packages/helpermodules/command.py index 2f715bc7d4..e39ac1dbbc 100644 --- a/packages/helpermodules/command.py +++ b/packages/helpermodules/command.py @@ -794,7 +794,7 @@ def __on_message_rm(self, client, userdata, msg): topic = type_to_topic_mapping(payload["type"]) data.data.counter_all_data.hierarchy_remove_item(payload["id"]) client.subscribe(f'openWB/{topic}/{payload["id"]}/#', 2) - elif "openWB/chargepoint/" in msg.topic and "/config" in msg.topic: + elif re.search("openWB/chargepoint/[0-9]+/config$", msg.topic) is not None: payload = decode_payload(msg.payload) if payload["type"] == "external_openwb": pub_single( From 3e7eb7934044f1b89354a3fc48a99b1bc255d501 Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Mon, 25 Sep 2023 10:23:30 +0200 Subject: [PATCH 3/4] fix --- packages/helpermodules/setdata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/helpermodules/setdata.py b/packages/helpermodules/setdata.py index 4f10008330..49764fcb45 100644 --- a/packages/helpermodules/setdata.py +++ b/packages/helpermodules/setdata.py @@ -1024,7 +1024,7 @@ def process_internal_chargepoint_topic(self, msg): elif "data/parent_cp" in msg.topic: for cp in subdata.SubData.cp_data.values(): if cp.chargepoint.data.config.type == "internal_openwb": - if get_index(msg.topic) == cp.chargepoint.data.config.configuration.duo_num: + if int(get_index(msg.topic)) == cp.chargepoint.data.config.configuration["duo_num"]: self._validate_value(msg, str) elif "data/set_current" in msg.topic: self._validate_value(msg, float, [(0, 0), (6, 32)]) From d55d13bcb59f910f5b55c84d3206f71fd9c75525 Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Mon, 25 Sep 2023 12:34:37 +0200 Subject: [PATCH 4/4] fix obsolet parent_cp --- packages/helpermodules/setdata.py | 14 ++++++++++---- packages/helpermodules/update_config.py | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/helpermodules/setdata.py b/packages/helpermodules/setdata.py index 49764fcb45..d24c97e63b 100644 --- a/packages/helpermodules/setdata.py +++ b/packages/helpermodules/setdata.py @@ -1022,10 +1022,16 @@ def process_internal_chargepoint_topic(self, msg): if "data/cp_interruption_duration" in msg.topic: self._validate_value(msg, int, [(0, float("inf"))]) elif "data/parent_cp" in msg.topic: - for cp in subdata.SubData.cp_data.values(): - if cp.chargepoint.data.config.type == "internal_openwb": - if int(get_index(msg.topic)) == cp.chargepoint.data.config.configuration["duo_num"]: - self._validate_value(msg, str) + if decode_payload(msg.payload) is None: + self._validate_value(msg, str) + else: + for cp in subdata.SubData.cp_data.values(): + if cp.chargepoint.data.config.type == "internal_openwb": + if int(get_index(msg.topic)) == cp.chargepoint.data.config.configuration["duo_num"]: + self._validate_value(msg, str) + break + else: + log.error("Kein interner Ladepunkt konfiguriert, dem ein parent_cp zugeordnet werden kann.") elif "data/set_current" in msg.topic: self._validate_value(msg, float, [(0, 0), (6, 32)]) elif "data/phases_to_use" in msg.topic: diff --git a/packages/helpermodules/update_config.py b/packages/helpermodules/update_config.py index 9964461a72..ea60bfd4fd 100644 --- a/packages/helpermodules/update_config.py +++ b/packages/helpermodules/update_config.py @@ -26,7 +26,7 @@ class UpdateConfig: - DATASTORE_VERSION = 19 + DATASTORE_VERSION = 20 valid_topic = [ "^openWB/bat/config/configured$", "^openWB/bat/set/charging_power_left$", @@ -404,6 +404,8 @@ class UpdateConfig: ("openWB/general/range_unit", "km"), ("openWB/general/ripple_control_receiver/configured", False), ("openWB/graph/config/duration", 120), + ("openWB/internal_chargepoint/0/data/parent_cp", None), + ("openWB/internal_chargepoint/1/data/parent_cp", None), ("openWB/optional/et/active", False), ("openWB/optional/et/config/max_price", 0), ("openWB/optional/et/config/provider", {}), @@ -496,7 +498,7 @@ def __pub_missing_defaults(self): # zwingend erforderliche Standardwerte setzen for topic, default_payload in self.default_topic: if topic not in self.all_received_topics.keys(): - log.debug(f"Setzte Topic '{topic}' auf Standardwert '{str(default_payload)}'") + log.debug(f"Setze Topic '{topic}' auf Standardwert '{str(default_payload)}'") Pub().pub(topic.replace("openWB/", "openWB/set/"), default_payload) def __update_version(self): @@ -840,3 +842,17 @@ def convert_file(file): convert_file(f"/var/www/html/openWB/data/daily_log/{timecheck.create_timestamp_YYYYMMDD()}.json") convert_file(f"/var/www/html/openWB/data/monthly_log/{timecheck.create_timestamp_YYYYMM()}.json") Pub().pub("openWB/system/datastore_version", 19) + + def upgrade_datastore_19(self) -> None: + for topic, payload in self.all_received_topics.items(): + if re.search("openWB/internal_chargepoint/[0-1]/data/parent_cp", topic) is not None: + payload = decode_payload(payload) + for topic_cp, payload_cp in self.all_received_topics.items(): + payload_cp = decode_payload(payload_cp) + if f"openWB/chargepoint/{payload}/config" == topic_cp: + if payload_cp["type"] == "internal_openwb": + if int(get_index(topic)) == payload_cp["configuration"]["duo_num"]: + break + else: + Pub().pub(topic, None) + Pub().pub("openWB/system/datastore_version", 20)