Docker PoC for batteries

This commit is contained in:
2026-04-26 07:47:20 -04:00
parent 396e810895
commit e893be8c35
4 changed files with 108 additions and 1 deletions

View File

@@ -100,9 +100,25 @@ class AppConfig:
def load_config(path: Path) -> AppConfig:
raw = yaml.safe_load(path.read_text())
# Allow env-var overrides for MQTT credentials. Useful for Docker
# deployments where secrets shouldn't live in the YAML, and for HA
# addons translating addon-options into env at runtime.
import os
mqtt_raw = dict(raw["mqtt"])
for key, env_var in (
("host", "MQTT_HOST"),
("port", "MQTT_PORT"),
("username", "MQTT_USERNAME"),
("password", "MQTT_PASSWORD"),
):
v = os.environ.get(env_var)
if v is not None:
mqtt_raw[key] = int(v) if key == "port" else v
return AppConfig(
bus=BusConfig(**raw["bus"]),
mqtt=MQTTConfig(**raw["mqtt"]),
mqtt=MQTTConfig(**mqtt_raw),
packs=[PackConfig(**p) for p in raw["packs"]],
cell_count=raw.get("cell_count", 16),
)