Skip to content

Commit

Permalink
Improve config handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Hale committed Jan 28, 2024
1 parent aa06004 commit 8e106ec
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/apps/powerwall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
import teslapy_wrapper as api_wrapper


def get_mpan(config_key, required):
v = pyscript.app_config.get(config_key)
if v is None and required:
raise KeyError(f"{config_key} missing")
if type(v) is int:
v = str(v)
return v


IMPORT_MPAN = get_mpan("import_mpan", True)
EXPORT_MPAN = get_mpan("export_mpan", False)

IMPORT_RATES = tariff.Rates()
EXPORT_RATES = tariff.Rates()

Expand All @@ -12,11 +24,9 @@ def debug(msg):


def get_rates(mpan):
import_mpan = pyscript.app_config["import_mpan"]
export_mpan = pyscript.app_config.get("export_mpan")
if mpan == import_mpan:
if mpan == IMPORT_MPAN:
return IMPORT_RATES
elif mpan == export_mpan:
elif mpan == EXPORT_MPAN:
return EXPORT_RATES
else:
return None
Expand Down

0 comments on commit 8e106ec

Please sign in to comment.