diff --git a/packages/helpermodules/command.py b/packages/helpermodules/command.py index 505adc4adf..e39ac1dbbc 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 re.search("openWB/chargepoint/[0-9]+/config$", msg.topic) is not None: + 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..d24c97e63b 100644 --- a/packages/helpermodules/setdata.py +++ b/packages/helpermodules/setdata.py @@ -1022,7 +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: - 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)