Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benderl committed Feb 15, 2024
1 parent 30dea6b commit 2e62214
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/helpermodules/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def __init__(self, name: str, on_connect: Callable, on_message: Callable) -> Non
def start_infinite_loop(self) -> None:
self.client.loop_forever()

def start_finite_loop(self, timeout: int = 1) -> None:
def start_finite_loop(self) -> None:
self.client.loop_start()
time.sleep(timeout)
time.sleep(1)
self.client.loop_stop()

def disconnect(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion packages/helpermodules/measurement_logging/process_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def process_entry(entry: dict, next_entry: dict, calculation: CalculationType):
try:
for module in next_entry[type].keys():
if module not in entry[type].keys():
log.warning(f"adding module {module} from next entry")
log.debug(f"adding module {module} from next entry")
entry[type].update({module: {"energy_imported": 0.0, "energy_exported": 0.0}})
except KeyError:
# catch missing "type"
Expand Down
30 changes: 14 additions & 16 deletions packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,11 @@ def on_connect(self, client: MqttClient, userdata, flags: dict, rc: int):
client.subscribe("openWB/#", 2)

def on_message(self, client: MqttClient, userdata, msg: MQTTMessage):
if msg.topic == "openWB/system/datastore_version":
log.debug(f"received datastore version: {msg.payload}")
self.all_received_topics.update({msg.topic: msg.payload})

def __update_topic(self, topic: str, payload):
""" publish topic to broker and update all_received_topics
set- and sub-data are not yet initialized, so we have to use pub() directly!
set- and sub-data are not yet initialized, so we have to publish directly into the topic without adding "set/"
"""
Pub().pub(topic, payload)
if payload == "":
Expand All @@ -541,7 +539,7 @@ def __remove_outdated_topics(self):
if re.search(valid_topic, topic) is not None:
break
else:
log.debug("Ungültiges Topic zum Startzeitpunkt: "+str(topic))
log.debug(f"Ungültiges Topic zum Startzeitpunkt: {topic}")
removed_topics += [topic]
# delete topics to allow setting new defaults afterwards
for topic in removed_topics:
Expand Down Expand Up @@ -588,10 +586,10 @@ def __solve_breaking_changes(self) -> None:
log.debug(f"target datastore version: {self.DATASTORE_VERSION}")
for version in range(datastore_version, self.DATASTORE_VERSION):
try:
log.debug(f"upgrading datastore from version {version} to {version + 1}")
log.debug(f"upgrading datastore from version '{version}' to '{version + 1}'")
getattr(self, f"upgrade_datastore_{version}")()
except AttributeError:
log.error(f"missing upgrade function! {version}")
log.error(f"missing upgrade function! '{version}'")

def _loop_all_received_topics(self, callback) -> None:
modified_topics = {}
Expand Down Expand Up @@ -676,12 +674,12 @@ def upgrade_logs() -> None:
jsonFile.seek(0)
json.dump(new_content, jsonFile)
jsonFile.truncate()
log.debug(f"Format der Logdatei {file} aktualisiert.")
log.debug(f"Format der Logdatei '{file}' aktualisiert.")
except Exception:
log.exception(f"Logfile {file} entspricht nicht dem Dateiformat von Alpha 3.")
log.exception(f"Logfile '{file}' entspricht nicht dem Dateiformat von Alpha 3.")
except json.decoder.JSONDecodeError:
log.exception(
f"Logfile {file} konnte nicht konvertiert werden, da es keine gültigen json-Daten enthält.")
log.exception(f"Logfile '{file}' konnte nicht konvertiert werden, "
"da es keine gültigen json-Daten enthält.")
with open(file, "r+") as jsonFile:
try:
content = json.load(jsonFile)
Expand All @@ -698,7 +696,7 @@ def upgrade_logs() -> None:
json.dump(content, jsonFile)
jsonFile.truncate()
except Exception:
log.exception(f"Logfile {file} konnte nicht konvertiert werden.")
log.exception(f"Logfile '{file}' konnte nicht konvertiert werden.")

self._loop_all_received_topics(upgrade)
upgrade_logs()
Expand Down Expand Up @@ -1062,7 +1060,7 @@ def upgrade(topic: str, payload) -> None:
pub_system_message(payload, result.stdout, MessageType.SUCCESS)
else:
log.error("update of configuration for bridge "
f"'{bridge_configuration['name']}' {index} failed! {result.stdout}")
f"'{bridge_configuration['name']}' ({index}) failed! {result.stdout}")
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 24)

Expand Down Expand Up @@ -1230,11 +1228,11 @@ def convert_file(file):
jsonFile.seek(0)
json.dump(content, jsonFile)
jsonFile.truncate()
log.debug(f"Format der Logdatei {file} aktualisiert.")
log.debug(f"Format der Logdatei '{file}' aktualisiert.")
except FileNotFoundError:
pass
except Exception:
log.exception(f"Logfile {file} konnte nicht konvertiert werden.")
log.exception(f"Logfile '{file}' konnte nicht konvertiert werden.")

files = glob.glob(str(self.base_path / "data" / "daily_log") + "/*")
files.sort()
Expand All @@ -1259,11 +1257,11 @@ def convert_file(file):
jsonFile.seek(0)
json.dump(content, jsonFile)
jsonFile.truncate()
log.debug(f"Format der Logdatei {file} aktualisiert.")
log.debug(f"Format der Logdatei '{file}' aktualisiert.")
except FileNotFoundError:
pass
except Exception:
log.exception(f"Logfile {file} konnte nicht konvertiert werden.")
log.exception(f"Logfile '{file}' konnte nicht konvertiert werden.")
files = glob.glob(str(self.base_path / "data" / "daily_log") + "/*")
files.sort()
for file in files:
Expand Down

0 comments on commit 2e62214

Please sign in to comment.