cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.901: full source

This commit is contained in:
Setti Solutions S.R.L committed 2026-11-05 13:14:49 +02:00
1 parent d48b9aff87
commit e2c7085d2c
76 files changed
+5380 -330

No files matched your search

+24 -18
View File
@@ -112,45 +112,51 @@ def test_mapping_v3_refuses(tmp_path, bad, why):
# -- bundles ------------------------------------------------------------------
def test_tariff_and_fallbacks(tmp_path):
b = Bundles(str(tmp_path), SITE, default_price_ct=33)
def test_tariff_as_it_is_and_none_without(tmp_path):
"""docs/parameters.md U1: no default price, no last price held: without
a tariff (never, expired, another site's) status none and no prices;
a step the tariff has no price for has none (the plan covers the priced
steps); an export without a price is unpriced (None), not 0 ct."""
b = Bundles(str(tmp_path), SITE)
start = 1_800_000_000 // 900 * 900
p = b.prices(start, 900, 4, start)
assert p.import_ct == [33] * 4 and "default" in p.note
assert (p.status, p.reason) == ("none", "never") and p.import_ct == [None] * 4 and p.export_ct == [None] * 4
assert p.note.startswith("no tariff: price optimisation off (no tariff received yet")
t = {"v": 1, "kind": "tariff", "id": "t1", "site": SITE, "issued": start, "start": start, "step_s": 900,
"steps": 2, "expires": start + 7200, "currency": "EUR", "unit": "ct/kWh",
"import": [10, None], "export": [5, 5]}
(tmp_path / "tariff.json").write_text(json.dumps(t))
p = b.prices(start, 900, 4, start)
assert p.import_ct == [10, 10, 10, 10] and p.export_ct == [5, 5, 0, 0] and "3 of 4" in p.note
p = b.prices(start, 900, 2, start + 7200) # expired: the flat price, said
assert p.import_ct == [10, 10] and "expired" in p.note
os.remove(tmp_path / "tariff.json")
assert "last known flat" in b.prices(start, 900, 1, start).note
assert p.import_ct == [10, None, None, None] and p.export_ct == [5, 5, None, None]
assert p.status == "tariff" and p.priced_steps == 1 and "the plan covers those" in p.note
p = b.prices(start, 900, 2, start + 7200) # expired: no price at all, said with the time
assert (p.status, p.reason, p.tariff_id) == ("none", "expired", "t1") and p.import_ct == [None, None]
assert "the tariff t1 expired at" in p.note
os.remove(tmp_path / "tariff.json") # gone: never a last price held
assert b.prices(start, 900, 1, start).reason == "never"
t["site"] = "cd" * 16 # another site's file: not taken
(tmp_path / "tariff.json").write_text(json.dumps(t))
assert b.prices(start, 900, 1, start).note.startswith("no tariff")
assert b.prices(start, 900, 1, start).reason == "other_site"
t.update(site=SITE, start=start + 900, id="t10") # no price for now: none
(tmp_path / "tariff.json").write_text(json.dumps(t))
assert b.prices(start, 900, 2, start).reason == "no_price_now"
def test_feed_in_at_zero_is_said(tmp_path):
"""Finding A1-a: where no export price is known the feed-in is 0 ct, and
the plan's note says so (no tariff, expired, no or a short export series)."""
b = Bundles(str(tmp_path), SITE, default_price_ct=33)
def test_export_unpriced_is_said(tmp_path):
b = Bundles(str(tmp_path), SITE)
start = 1_800_000_000 // 900 * 900
p = b.prices(start, 900, 4, start)
assert p.export_ct == [0.0] * 4 and "feed-in at 0 ct/kWh" in p.note
t = {"v": 1, "kind": "tariff", "id": "t1", "site": SITE, "issued": start, "start": start, "step_s": 900,
"steps": 4, "expires": start + 7200, "currency": "EUR", "unit": "ct/kWh",
"import": [10, 10, 10, 10], "export": [5, 5, 5, 5]}
(tmp_path / "tariff.json").write_text(json.dumps(t))
assert b.prices(start, 900, 4, start).note == "tariff t1" # all priced: nothing to say
assert "feed-in at 0 ct/kWh" in b.prices(start, 900, 2, start + 7200).note # expired
t["export"] = [5, None, None, None]
(tmp_path / "tariff.json").write_text(json.dumps(t))
assert "feed-in at 0 ct/kWh in 3 of 4 steps" in b.prices(start, 900, 4, start).note
p = b.prices(start, 900, 4, start)
assert p.export_ct == [5, None, None, None] and "no export price in 3 of 4 steps: export unpriced" in p.note
del t["export"]
(tmp_path / "tariff.json").write_text(json.dumps(t))
assert b.prices(start, 900, 4, start).note == "tariff t1; feed-in at 0 ct/kWh"
assert b.prices(start, 900, 4, start).note == "tariff t1; no export price: export unpriced (no value)"
def test_model_bundle(tmp_path):