Skip to content

Commit

Permalink
fix mac_c_socket migration
Browse files Browse the repository at this point in the history
  • Loading branch information
benderl committed Oct 10, 2023
1 parent 567ec43 commit f293eee
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions packages/helpermodules/data_migration/data_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,17 @@ def _monthly_log_entry(self, file: str):
log.exception(f"Fehler beim Konvertieren des Monats-Logs vom {file}, Reihe {row}")
return entries

def _get_openwb_conf_value(self, key: str) -> Optional[str]:
value = None
def _get_openwb_conf_value(self, key: str, default: Optional[str] = None) -> Optional[str]:
value = default
found = False
for line in self.openwb_conf:
if key in line:
raw_value = line.replace(f"{key}=", "")
value = raw_value.rstrip("\n")
found = True
break
if not found:
log.debug(f"Keine Konfiguration für '{key}' gefunden. Verwende Standardwert '{default}'.")
return value

def _migrate_settings_from_openwb_conf(self):
Expand All @@ -542,42 +546,30 @@ def _migrate_settings_from_openwb_conf(self):

def _move_serial_number(self) -> None:
serial_number = self._get_openwb_conf_value("snnumber")
if serial_number:
if serial_number is not None:
with open("/home/openwb/snnumber", "w") as file:
file.write(f"snnumber={serial_number}")
else:
log.debug("Keine Seriennummer gefunden.")

def _move_cloud_data(self) -> None:
cloud_user = self._get_openwb_conf_value("clouduser")
cloud_pw = self._get_openwb_conf_value("cloudpw")
if cloud_user is not None and cloud_pw is not None:
Pub().pub("openWB/set/command/data_migration/todo",
{"command": "connectCloud", "data": {"username": cloud_user, "password": cloud_pw, "partner": 0}})
else:
log.debug("Keine Cloud-Zugangsdaten gefunden.")

def _move_rse(self) -> None:
rse = bool(self._get_openwb_conf_value("rseenabled"))
if rse is None:
log.debug("Keine Rundsteuerempfänger-Konfiguration gefunden. Setze auf False.")
rse = False
rse = bool(self._get_openwb_conf_value("rseenabled", "0"))
update_hardware_configuration({"ripple_control_receiver_configured": rse})

def _move_max_c_socket(self):
max_c_socket = int(self._get_openwb_conf_value("ppbuchse"))
if max_c_socket is None:
log.debug("Keine max_c_socket-Konfiguration gefunden. Setze auf False.")
max_c_socket = 32
max_c_socket = int(self._get_openwb_conf_value("ppbuchse", "32"))
update_hardware_configuration({"max_c_socket": max_c_socket})

def _move_pddate(self) -> None:
pddate = self._get_openwb_conf_value("pddate")
if pddate is not None:
with open("/home/openwb/pddate", "w") as file:
file.write(f"pddate={pddate}")
else:
log.debug("Kein Produktionsdatum gefunden.")

NOT_CONFIGURED = " wurde in openWB software2 nicht konfiguriert."

Expand Down

0 comments on commit f293eee

Please sign in to comment.