Skip to content

Commit

Permalink
fix hardware configuration file (#1896)
Browse files Browse the repository at this point in the history
* fix hardware configuration file

* update default file

* msg

* improve

* don't fix all breaking changes after reset
  • Loading branch information
LKuemmel authored Oct 1, 2024
1 parent 9bdb434 commit cc81b49
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion data/config/configuration.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"openwb-version": 1, "ripple_control_receiver_configured": false, "max_c_socket": 32}
{"openwb-version": 1, "max_c_socket": 32, "dc_charging": false}
20 changes: 18 additions & 2 deletions packages/helpermodules/hardware_configuration.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import logging
import json
import sys
from typing import Dict, Optional

from helpermodules.utils.json_file_handler import write_and_check

log = logging.getLogger(__name__)

HARDWARE_CONFIGURATION_FILE = "/home/openwb/configuration.json"


def _read_configuration() -> Dict:
with open(HARDWARE_CONFIGURATION_FILE, "r") as f:
return json.loads(f.read())
for i in range(2):
try:
with open(HARDWARE_CONFIGURATION_FILE, "r") as f:
config = json.loads(f.read())
if isinstance(config, dict):
return config
except Exception:
# wird im else-Zweig abgefangen
pass
else:
log.error("Invalid configuration.json file. Creating new one with default values.")
with open("./data/config/configuration.json", "r") as f:
config_file = json.loads(f.read())
write_and_check(HARDWARE_CONFIGURATION_FILE, config_file)
return config_file


def update_hardware_configuration(new_setting: Dict) -> None:
Expand Down
3 changes: 2 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ def __update_version(self):
def __solve_breaking_changes(self) -> None:
""" solve breaking changes in the datastore
"""
datastore_version = decode_payload(self.all_received_topics.get("openWB/system/datastore_version")) or 0
datastore_version = (decode_payload(self.all_received_topics.get("openWB/system/datastore_version")) or
self.DATASTORE_VERSION)
log.debug(f"current datastore version: {datastore_version}")
log.debug(f"target datastore version: {self.DATASTORE_VERSION}")
for version in range(datastore_version, self.DATASTORE_VERSION):
Expand Down

0 comments on commit cc81b49

Please sign in to comment.