Skip to content

Commit bfed520

Browse files
authored
Merge pull request #20 from EnergieID/feat/allow-multiple-forcast
Support multiple different forecasts
2 parents 02203f1 + 1ecb89c commit bfed520

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ ENERGY_ID_COFY_API_TOKEN=foo
44
# --- Database --------------------------------------------------------------
55
DB_URL=postgresql+asyncpg://cofy:cofy@localhost:5432/epv
66

7+
# --- Forecasts -------------------------------------------------------------
8+
FORECASTS={"ACC_1": 42923}
9+
710
# dev only, not needed for production, but useful for local development with Docker
811
POSTGRES_DB=epv
912
POSTGRES_USER=cofy

main.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
3. `poe dev` to start the dev server (auto-reloads, reads .env)
1111
"""
1212

13+
import json
1314
from os import environ
1415

1516
from cofy import CofyAPI
@@ -32,14 +33,18 @@
3233
# Each module exposes its own set of API routes under the name you choose.
3334
# Browse the available modules: https://github.com/EnergieID/cofy-api
3435

35-
cofy.register_module(
36-
DirectiveModule(
37-
source=DirectiveSource(
38-
source=DBSource(
39-
db_url=environ.get("DB_URL", "postgresql+asyncpg://cofy:cofy@localhost:5432/epv"),
40-
itemid=42923,
36+
forecasts = json.loads(environ.get("FORECASTS", "{}"))
37+
for name, id in forecasts.items():
38+
cofy.register_module(
39+
DirectiveModule(
40+
source=DirectiveSource(
41+
source=DBSource(
42+
db_url=environ.get("DB_URL", "postgresql+asyncpg://cofy:cofy@localhost:5432/epv"),
43+
itemid=id,
44+
),
45+
boundaries=(-100000, 0, 100000, 500000),
4146
),
42-
boundaries=(-100000, 0, 100000, 500000),
43-
),
47+
name=name,
48+
description=f"Directive for community {name}",
49+
)
4450
)
45-
)

0 commit comments

Comments
 (0)