Skip to content
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
23 changes: 9 additions & 14 deletions packages/helpermodules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,15 @@ def _get_max_ids(self) -> None:
max_id = default
for topic, payload in received_topics.items():
if re.search(topic_str, topic) is not None:
try:
if id_topic == "autolock_plan":
for plan in payload["autolock"]["plans"]:
max_id = max(plan["id"], max_id)
elif id_topic == "charge_template_scheduled_plan":
for plan in payload["chargemode"]["scheduled_charging"]["plans"]:
max_id = max(plan["id"], max_id)
elif id_topic == "charge_template_time_charging_plan":
for plan in payload["time_charging"]["plans"]:
max_id = max(plan["id"], max_id)
except KeyError:
# überspringe Profile, die keinen Eintrag für Pläne haben.
# Da gab es einen Bug beim Kopieren.
pass
if id_topic == "autolock_plan":
for plan in payload["autolock"]["plans"]:
max_id = max(plan["id"], max_id)
elif id_topic == "charge_template_scheduled_plan":
for plan in payload["chargemode"]["scheduled_charging"]["plans"]:
max_id = max(plan["id"], max_id)
elif id_topic == "charge_template_time_charging_plan":
for plan in payload["time_charging"]["plans"]:
max_id = max(plan["id"], max_id)
setattr(self, f'max_id_{id_topic}', max_id)
Pub().pub("openWB/set/command/max_id/"+id_topic, max_id)
for id_topic, topic_str, default in self.MAX_IDS["topic"]:
Expand Down
92 changes: 91 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

class UpdateConfig:

DATASTORE_VERSION = 93
DATASTORE_VERSION = 94

valid_topic = [
"^openWB/bat/config/bat_control_permitted$",
Expand Down Expand Up @@ -2425,3 +2425,93 @@ def upgrade(topic: str, payload) -> Optional[dict]:
return {topic: payload}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 93)

def upgrade_datastore_93(self) -> None:
# Pläne die keinen plans Key haben, id=None
max_id = -1
none_id = False
for topic, payload in self.all_received_topics.items():
if re.search("openWB/vehicle/template/charge_template/[0-9]+$", topic) is not None:
payload = decode_payload(payload)
try:
for plan in payload["chargemode"]["scheduled_charging"]["plans"]:
try:
max_id = max(plan["id"], max_id)
except TypeError:
if plan["id"] is None:
none_id = True
else:
raise TypeError(f"Plan {plan} hat keinen Key 'id' und ist kein NoneType.")
except KeyError:
payload["chargemode"]["scheduled_charging"].update({"plans": []})
self.all_received_topics[topic] = json.dumps(payload, ensure_ascii=False).encode("utf-8")
Pub().pub(f"openWB/set/vehicle/template/charge_template/{get_index(topic)}", payload)
if none_id:
for topic, payload in self.all_received_topics.items():
if re.search("openWB/vehicle/template/charge_template/[0-9]+$", topic) is not None:
payload = decode_payload(payload)
for plan in payload["chargemode"]["scheduled_charging"]["plans"]:
if plan["id"] is None:
plan["id"] = max_id + 1
max_id += 1
self.all_received_topics[topic] = json.dumps(payload, ensure_ascii=False).encode("utf-8")
Pub().pub(f"openWB/set/vehicle/template/charge_template/{get_index(topic)}", payload)

max_id = -1
none_id = False
for topic, payload in self.all_received_topics.items():
if re.search("openWB/vehicle/template/charge_template/[0-9]+$", topic) is not None:
payload = decode_payload(payload)
try:
for plan in payload["time_charging"]["plans"]:
try:
max_id = max(plan["id"], max_id)
except TypeError:
if plan["id"] is None:
none_id = True
else:
raise TypeError(f"Plan {plan} hat keinen Key 'id' und ist kein NoneType.")
except KeyError:
payload["time_charging"].update({"plans": []})
self.all_received_topics[topic] = json.dumps(payload, ensure_ascii=False).encode("utf-8")
Pub().pub(f"openWB/set/vehicle/template/charge_template/{get_index(topic)}", payload)
if none_id:
for topic, payload in self.all_received_topics.items():
if re.search("openWB/vehicle/template/charge_template/[0-9]+$", topic) is not None:
payload = decode_payload(payload)
for plan in payload["time_charging"]["plans"]:
if plan["id"] is None:
plan["id"] = max_id + 1
max_id += 1
self.all_received_topics[topic] = json.dumps(payload, ensure_ascii=False).encode("utf-8")
Pub().pub(f"openWB/set/vehicle/template/charge_template/{get_index(topic)}", payload)

max_id = -1
none_id = False
for topic, payload in self.all_received_topics.items():
if re.search("openWB/chargepoint/template/[0-9]+$", topic) is not None:
payload = decode_payload(payload)
try:
for plan in payload["autolock"]["plans"]:
try:
max_id = max(plan["id"], max_id)
except TypeError:
if plan["id"] is None:
none_id = True
else:
raise TypeError(f"Plan {plan} hat keinen Key 'id' und ist kein NoneType.")
except KeyError:
payload["autolock"].update({"plans": []})
self.all_received_topics[topic] = json.dumps(payload, ensure_ascii=False).encode("utf-8")
Pub().pub(f"openWB/set/chargepoint/template/{get_index(topic)}", payload)
if none_id:
for topic, payload in self.all_received_topics.items():
if re.search("openWB/chargepoint/template/[0-9]+$", topic) is not None:
payload = decode_payload(payload)
for plan in payload["autolock"]["plans"]:
if plan["id"] is None:
plan["id"] = max_id + 1
max_id += 1
self.all_received_topics[topic] = json.dumps(payload, ensure_ascii=False).encode("utf-8")
Pub().pub(f"openWB/set/chargepoint/template/{get_index(topic)}", payload)
self.__update_topic("openWB/system/datastore_version", 94)