Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parent cp #1134

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/helpermodules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion packages/helpermodules/setdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 18 additions & 2 deletions packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


class UpdateConfig:
DATASTORE_VERSION = 19
DATASTORE_VERSION = 20
valid_topic = [
"^openWB/bat/config/configured$",
"^openWB/bat/set/charging_power_left$",
Expand Down Expand Up @@ -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", {}),
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)