cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.1289: full source
This commit is contained in:
1 parent
165dda4479
commit
05802d6f87
57 files changed
+5928
-232
No files matched your search
@@ -373,6 +373,91 @@ def test_support_session_banner_end_and_owners_choices(tmp_path):
|
||||
assert "Ended." in s.req("POST", "p=devices", {"do": "end-support"}, sup, ingress)
|
||||
|
||||
|
||||
def test_hot_water_tank_ratings_and_idle_loss(tmp_path):
|
||||
"""Backlog 329 (docs/design/storage-losses.md): any HA water heater
|
||||
used as a hot-water tank (control dhw_tank, consent off); its heater the
|
||||
owner's choice; its ratings entered here as on the Hub (each above 0);
|
||||
what it is not planned without as a warning; the loss's and a battery's
|
||||
idle loss's source from the agent's latest plan; support may not change
|
||||
them."""
|
||||
s = Site(tmp_path)
|
||||
s.ha.reg["devices"].append({"id": "dev-tank", "name": "Tank", "manufacturer": "Stiebel Eltron", "model": "WWK 300",
|
||||
"config_entries": ["e4"]})
|
||||
s.ha.reg["entities"].append(ent("water_heater.tank", "dev-tank", "wh1", "stiebel"))
|
||||
s.ha.states.append(st("water_heater.tank", "eco", current_temperature=51.5, temperature=55, min_temp=35, max_temp=65))
|
||||
out = s.req()
|
||||
assert "It could control: hot-water tank." in out
|
||||
out = s.post(do="use", ha_device="dev-tank", profile="ha-water-heater", name="Tank")
|
||||
dev_id = next(i for i, d in s.devices().items() if d["profile"] == "ha-water-heater")
|
||||
tank = s.frag(dev_id)["controls"][0]
|
||||
assert (tank["kind"], tank["consent"], tank["entities"]) == ("dhw_tank", False, {"water_heater": "water_heater.tank"})
|
||||
page = s.req(query=f"p=devices&d={dev_id}")
|
||||
assert "Hot-water tank" in page and 'name="heater"' in page and "Choose its heater" in page
|
||||
assert "Needed: the tank is not planned without it." in page
|
||||
assert "the tank's volume (Ratings), its heater (above)" in page
|
||||
assert 'name="f_rated_tank_volume_l"' in page and 'value="ratings"' in page and "tank 51.5 °C" in page
|
||||
# the heater and the ratings: the owner's
|
||||
assert "Saved." in s.post(do="tank", id=dev_id, heater="heat_pump")
|
||||
assert s.frag(dev_id)["controls"][0]["params"]["heater"] == "heat_pump"
|
||||
assert "the heater is one of" in s.post(do="tank", id=dev_id, heater="gas")
|
||||
s.post(do="ratings", id=dev_id, f_rated_tank_volume_l="300", f_rated_tank_heater_kw="0.6", f_rated_tank_cop="")
|
||||
assert s.devices()[dev_id]["ratings"] == {"tank_volume_l": 300.0, "tank_heater_kw": 0.6}
|
||||
specs = json.loads((s.state / "devices-specs.json").read_text())["devices"][dev_id]
|
||||
assert specs["ratings"]["tank_volume_l"] == 300.0 and specs["controls"] == [tank["id"]]
|
||||
assert "0.01 to 1000" in s.post(do="ratings", id=dev_id, f_rated_tank_heater_kw="0", f_rated_tank_volume_l="300")
|
||||
assert s.devices()[dev_id]["ratings"]["tank_heater_kw"] == 0.6 # refused: kept as it was
|
||||
page = s.req(query=f"p=devices&d={dev_id}")
|
||||
assert "the heat pump's COP (Ratings)" in page and "300 L · heater 0.6 kW" in page
|
||||
assert 'value="300"' in page
|
||||
# the agent's plan: the loss assumed at class D's limit (quiet, no alarm)
|
||||
(s.state / "preferences-view.json").write_text(json.dumps({"v": 1, "planning": {"refused": {}, "storage": {
|
||||
tank["id"]: {"kind": "dhw_tank", "heater": "heat_pump", "volume_l": 300, "standby_w": 122.0, "loss_src": "assumed",
|
||||
"erp_class": "D", "temp_c": 51.5, "usable_kwh": 2.2}}}}))
|
||||
page = s.req(query=f"p=devices&d={dev_id}")
|
||||
assert "Needed:" not in page and "now 51.5 °C · 2.2 kWh usable" in page
|
||||
assert "Standing loss 122 W assumed: class D's limit (Parameters). Enter the label's value below." in page
|
||||
# support may not change what is the owner's
|
||||
sup = {"x-remote-user-name": "cantabile-support"}
|
||||
for form, why in (({"do": "tank", "id": dev_id, "heater": "element"}, "The tank's heater is the owner"),
|
||||
({"do": "ratings", "id": dev_id, "f_rated_tank_volume_l": "200"}, "The ratings are the owner")):
|
||||
out = s.req("POST", f"p=devices&d={dev_id}", form, sup)
|
||||
assert why in out, form
|
||||
assert s.devices()[dev_id]["ratings"]["tank_volume_l"] == 300.0
|
||||
assert s.frag(dev_id)["controls"][0]["params"]["heater"] == "heat_pump"
|
||||
|
||||
def german():
|
||||
i18n.use("de")
|
||||
return s.req(query=f"p=devices&d={dev_id}")
|
||||
import contextvars
|
||||
out = contextvars.copy_context().run(german)
|
||||
assert "Warmwasserspeicher" in out and "Warmhalteverlust 122 W angenommen" in out and "Nenndaten" in out
|
||||
|
||||
|
||||
def test_battery_idle_loss_line():
|
||||
"""A battery's idle loss with its source (design 2.3): learnt, the
|
||||
owner's, assumed (a quiet line with what to do, never an alarm)."""
|
||||
from cantabile_edge.devpage import battery_store_lines, ratings_html
|
||||
assert battery_store_lines({"standby_w": 49.2, "standby_src": "learnt", "idle_loss_kwh_24h": 1.18,
|
||||
"self_discharge_pct_month": 2, "self_discharge_src": "parameter"}) == [
|
||||
"Idle loss 49 W (learnt by the box) · about 1.18 kWh a day", "Self-discharge 2 %/month assumed (Parameters)"]
|
||||
assert battery_store_lines({"standby_w": 13, "standby_src": "parameter"}) == [
|
||||
"Idle loss 13 W assumed (Parameters): enter the datasheet's value below."]
|
||||
assert battery_store_lines({"standby_w": 30, "standby_src": "owner"}) == ["Idle loss 30 W (your rating)"]
|
||||
assert battery_store_lines({"planned": False}) == []
|
||||
d = {"id": "hm8042-hybrid-1", "rating_fields": [
|
||||
{"name": "rated_battery_standby_w", "label": "x", "rating": "battery_standby_w", "value": None}],
|
||||
"storage": [{"id": "battery", "kind": "battery", "standby_w": 13, "standby_src": "assumed"}]}
|
||||
out = ratings_html(d)
|
||||
assert out.index("Idle loss 13 W assumed") < out.index('name="f_rated_battery_standby_w"')
|
||||
assert "box warn" not in out and "leave empty and the box learns it" in out
|
||||
# a hot-water meter's ratings too (the add-on had no form for them)
|
||||
out = ratings_html({"id": "ha-water-meter-1", "rating_fields": [
|
||||
{"name": "rated_dhw_kwh_per_m3", "label": "x", "rating": "dhw_kwh_per_m3", "value": 58.2}]})
|
||||
assert "From the meter and the installation" in out and 'value="58.2"' in out
|
||||
assert "Hot water: kWh of heat per m³ drawn" in out
|
||||
assert ratings_html({"id": "x", "rating_fields": []}) == ""
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def english():
|
||||
i18n.use("en")
|
||||
Reference in new issue
Block a user