mirror of
https://github.com/Matysh/houseplan-card
synced 2026-09-29 03:09:36 +00:00
v1.59.0-rc.1: optimize plans and polish editor feedback
This commit is contained in:
@@ -67,6 +67,59 @@ async def test_config_rev_conflict(hass: HomeAssistant, hass_ws_client: WebSocke
|
||||
assert resp["result"]["rev"] == 1
|
||||
|
||||
|
||||
async def test_plan_optimize_pair_and_one_deep_undo(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||
) -> None:
|
||||
"""Config and layout move together; the snapshot restores both revisions."""
|
||||
await _setup(hass)
|
||||
client = await hass_ws_client(hass)
|
||||
original = {"spaces": [], "markers": [], "settings": {}}
|
||||
original_layout = {"dev": {"s": "f1", "x": 0.1, "y": 0.2}}
|
||||
|
||||
await client.send_json_auto_id({
|
||||
"type": "houseplan/config/set", "config": original, "expected_rev": 0,
|
||||
})
|
||||
assert (await client.receive_json())["success"]
|
||||
await client.send_json_auto_id({
|
||||
"type": "houseplan/layout/set", "layout": original_layout, "expected_rev": 0,
|
||||
})
|
||||
assert (await client.receive_json())["success"]
|
||||
|
||||
optimized = {**original, "model_version": 1}
|
||||
optimized_layout = {"dev": {"s": "f1", "x": 0.125, "y": 0.25}}
|
||||
await client.send_json_auto_id({
|
||||
"type": "houseplan/plan/optimize",
|
||||
"config": optimized,
|
||||
"layout": optimized_layout,
|
||||
"expected_config_rev": 1,
|
||||
"expected_layout_rev": 1,
|
||||
})
|
||||
resp = await client.receive_json()
|
||||
assert resp["success"]
|
||||
assert resp["result"]["config_rev"] == 2
|
||||
assert resp["result"]["layout_rev"] == 2
|
||||
assert resp["result"]["can_undo"] is True
|
||||
|
||||
await client.send_json_auto_id({"type": "houseplan/config/get"})
|
||||
assert (await client.receive_json())["result"]["can_optimize_undo"] is True
|
||||
|
||||
await client.send_json_auto_id({
|
||||
"type": "houseplan/plan/optimize_undo",
|
||||
"expected_config_rev": 2,
|
||||
"expected_layout_rev": 2,
|
||||
})
|
||||
resp = await client.receive_json()
|
||||
assert resp["success"] and resp["result"]["can_undo"] is False
|
||||
|
||||
await client.send_json_auto_id({"type": "houseplan/config/get"})
|
||||
cfg = (await client.receive_json())["result"]
|
||||
assert cfg["config"] == original
|
||||
assert cfg["can_optimize_undo"] is False
|
||||
await client.send_json_auto_id({"type": "houseplan/layout/get"})
|
||||
layout = (await client.receive_json())["result"]
|
||||
assert layout["layout"] == original_layout
|
||||
|
||||
|
||||
async def test_not_ready_without_entry(hass: HomeAssistant, hass_ws_client: WebSocketGenerator) -> None:
|
||||
"""WS commands answer not_ready when the integration has no loaded entry."""
|
||||
# register only the WS commands, without an entry
|
||||
|
||||
@@ -1319,8 +1319,8 @@ def test_decor_furniture_does_not_disturb_the_other_kinds():
|
||||
{"id": "z", "kind": "hologram", "x": 0, "y": 0, "w": 1, "h": 1}]}]})
|
||||
|
||||
def test_space_walls_thickness():
|
||||
"""docs/WALL-THICKNESS.md: optional walls[{key,cm}]; absent = today's plan;
|
||||
cm bounded 1..100; key a bounded string; list capped like openings."""
|
||||
"""docs/WALL-THICKNESS.md: exact endpoints are optional/backward compatible;
|
||||
cm, keys, points and the list itself remain bounded."""
|
||||
base = {"id": "s1", "title": "S", "view_box": [0, 0, 1, 1], "rooms": []}
|
||||
# no walls -- byte-compatible
|
||||
assert "walls" not in v.CONFIG_SCHEMA({"spaces": [base]})["spaces"][0]
|
||||
@@ -1329,6 +1329,15 @@ def test_space_walls_thickness():
|
||||
out = v.CONFIG_SCHEMA({"spaces": [{**base, "walls": [ok]}]})
|
||||
assert out["spaces"][0]["walls"] == [ok]
|
||||
|
||||
exact = {**ok, "a": [0.2, 0.1], "b": [0.2, 0.4]}
|
||||
out = v.CONFIG_SCHEMA({"spaces": [{**base, "walls": [exact]}]})
|
||||
assert out["spaces"][0]["walls"] == [exact]
|
||||
with pytest.raises(vol.Invalid):
|
||||
v.CONFIG_SCHEMA({"spaces": [{**base, "walls": [{**ok, "a": [0.2, 0.1]}]}]})
|
||||
for bad in ([0.2], [0.2, 0.4, 0.6], [float("inf"), 0.4], [5001, 0.4]):
|
||||
with pytest.raises(vol.Invalid):
|
||||
v.CONFIG_SCHEMA({"spaces": [{**base, "walls": [{**ok, "a": bad}]}]})
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
v.CONFIG_SCHEMA({"spaces": [{**base, "walls": [{"key": ok["key"], "cm": 0}]}]})
|
||||
with pytest.raises(vol.Invalid):
|
||||
|
||||
Reference in New Issue
Block a user