Skip to content

Commit

Permalink
Fixing startup bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nexarian committed Jan 14, 2025
1 parent 0b88120 commit 900b652
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions proxy/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pypowerwall==0.12.3
bs4==0.0.2
beautifulsoup4==4.12.3
20 changes: 15 additions & 5 deletions proxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import sys
import threading
import time
import unicodedata
from enum import StrEnum, auto
from http import HTTPStatus
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
Expand All @@ -57,6 +58,13 @@
import pypowerwall
from pypowerwall import parse_version


def normalize_caseless(text: str) -> str:
return unicodedata.normalize("NFKD", text.casefold())

def caseless_equal(left: str, right: str) -> bool:
return normalize_caseless(left) == normalize_caseless(right)

BUILD: Final[str] = "t67"
UTF_8: Final[str] = "utf-8"

Expand Down Expand Up @@ -896,12 +904,14 @@ def check_for_environmental_pw_configs() -> List[str]:
"""
suffixes_to_check = {"", "1"}
actual_configs = []


environment = [normalize_caseless(key) for key in os.environ]
while suffixes_to_check:
current_suffix = suffixes_to_check.pop()
test_suffix = f"_{current_suffix}" if current_suffix.isnumeric() else current_suffix
if any(f"{config.value}{test_suffix}" in os.environ for config in CONFIG_TYPE):
actual_configs.append(test_suffix)
#if any( in (normalize_caseless(key) ) ):
if any(f"{config.value}{test_suffix}" in environment for config in CONFIG_TYPE):
actual_configs.append(test_suffix)
elif current_suffix.isnumeric() and int(current_suffix) > 1:
break
if current_suffix.isnumeric():
Expand Down Expand Up @@ -1006,9 +1016,9 @@ def main() -> None:
password=config[CONFIG_TYPE.PW_PASSWORD],
email=config[CONFIG_TYPE.PW_EMAIL],
timezone=config[CONFIG_TYPE.PW_TIMEZONE],
cache_expire=config[CONFIG_TYPE.PW_CACHE_EXPIRE],
pwcacheexpire=config[CONFIG_TYPE.PW_CACHE_EXPIRE],
timeout=config[CONFIG_TYPE.PW_TIMEOUT],
pool_maxsize=config[CONFIG_TYPE.PW_POOL_MAXSIZE],
poolmaxsize=config[CONFIG_TYPE.PW_POOL_MAXSIZE],
siteid=config[CONFIG_TYPE.PW_SITEID],
authpath=config[CONFIG_TYPE.PW_AUTH_PATH],
authmode=config[CONFIG_TYPE.PW_AUTH_MODE],
Expand Down

0 comments on commit 900b652

Please sign in to comment.