Skip to content

Commit

Permalink
Merge pull request #1421 from openWB/bugfix
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
benderl authored Feb 20, 2024
2 parents 51fc091 + 2e62214 commit 75bfb33
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 221 deletions.
22 changes: 13 additions & 9 deletions packages/helpermodules/hardware_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@
import sys
from typing import Dict

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


def update_hardware_configuration(new_setting: Dict) -> None:
with open("/home/openwb/configuration.json", "r") as f:
with open(HARDWARE_CONFIGURATION_FILE, "r") as f:
data = json.loads(f.read())
with open("/home/openwb/configuration.json", "w") as f:
with open(HARDWARE_CONFIGURATION_FILE, "w") as f:
data.update(new_setting)
f.write(json.dumps(data))


def remove_setting_hardware_configuration(obsolet_setting: str) -> None:
with open("/home/openwb/configuration.json", "r") as f:
with open(HARDWARE_CONFIGURATION_FILE, "r") as f:
data = json.loads(f.read())
with open("/home/openwb/configuration.json", "w") as f:
data.pop(obsolet_setting)
f.write(json.dumps(data))
if obsolet_setting in data:
with open(HARDWARE_CONFIGURATION_FILE, "w") as f:
data.pop(obsolet_setting)
f.write(json.dumps(data))


def get_hardware_configuration_setting(name: str):
with open("/home/openwb/configuration.json", "r") as f:
return json.loads(f.read())[name]
def get_hardware_configuration_setting(name: str, default=None):
with open(HARDWARE_CONFIGURATION_FILE, "r") as f:
configuration = json.loads(f.read())
return configuration.get(name, default)


def get_serial_number() -> str:
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 @@ -427,7 +427,7 @@ def get_single_value(source: dict, default: int = 0) -> float:
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
Loading

0 comments on commit 75bfb33

Please sign in to comment.