diff --git a/packages/helpermodules/measurement_logging/write_log.py b/packages/helpermodules/measurement_logging/write_log.py index deb5c3a6a1..d51ce0d865 100644 --- a/packages/helpermodules/measurement_logging/write_log.py +++ b/packages/helpermodules/measurement_logging/write_log.py @@ -95,7 +95,7 @@ def save_log(folder): date = timecheck.create_timestamp_HH_MM() else: date = timecheck.create_timestamp_YYYYMMDD() - current_timestamp = timecheck.create_timestamp() + current_timestamp = int(timecheck.create_timestamp()) cp_dict = {} for cp in data.data.cp_data: try: diff --git a/packages/helpermodules/update_config.py b/packages/helpermodules/update_config.py index 8b7a6e1da8..c84694136f 100644 --- a/packages/helpermodules/update_config.py +++ b/packages/helpermodules/update_config.py @@ -33,7 +33,7 @@ class UpdateConfig: - DATASTORE_VERSION = 33 + DATASTORE_VERSION = 34 valid_topic = [ "^openWB/bat/config/configured$", "^openWB/bat/set/charging_power_left$", @@ -1114,3 +1114,27 @@ def upgrade_prices(topic: str, payload) -> None: self._loop_all_received_topics(upgrade_et_entry) self._loop_all_received_topics(upgrade_prices) Pub().pub("openWB/system/datastore_version", 33) + + def upgrade_datastore_33(self) -> None: + def convert_file(file): + try: + with open(file, "r+") as jsonFile: + content = json.load(jsonFile) + for e in content["entries"]: + if type(e.date) is not str: + old_date = datetime.datetime.fromtimestamp(e.date) + e.date = old_date.strftime('%H:$M') + if type(e.timestamp) is float: + e.timestamp = int(e.timestamp) + jsonFile.seek(0) + json.dump(content, jsonFile) + jsonFile.truncate() + log.debug(f"Format der Logdatei {file} aktualisiert.") + except FileNotFoundError: + pass + except Exception: + log.exception(f"Logfile {file} konnte nicht konvertiert werden.") + files = glob.glob(str(self.base_path / "data" / "daily_log") + "/*") + for file in files: + convert_file(file) + Pub().pub("openWB/system/datastore_version", 34)