Docker PoC for batteries
This commit is contained in:
@@ -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),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user