fix: backfill inventory row for on-canvas mesh devices missing one
A device already on a canvas (Node exists) but with no pending_devices row never showed in the discovery inventory — the inventory lists pending_devices, not nodes. This stranded legacy auto-placed coordinators: on a canvas yet invisible in the inventory list. Both mesh imports now, in the already-approved-node branch, ensure an inventory row exists: create one as status="approved" when missing, or refresh its metadata (preserving status) when present. New/unplaced devices still land as status="pending"; hidden rows stay hidden. Tests updated: approved-node path now backfills an approved inventory row (zigbee + zwave), plus a regression that a hidden inventory row is not revived. ha-relevant: yes
This commit is contained in:
@@ -374,7 +374,9 @@ async def test_persist_sets_coordinator_pending_fields(db_session) -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_persist_skips_pending_for_approved_node(db_session) -> None:
|
||||
async def test_persist_backfills_inventory_for_approved_node(db_session) -> None:
|
||||
"""On-canvas device missing its inventory row gets one backfilled
|
||||
(status="approved"); Node props still refresh."""
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.api.routes.zwave import _persist_pending_import
|
||||
@@ -394,12 +396,13 @@ async def test_persist_skips_pending_for_approved_node(db_session) -> None:
|
||||
|
||||
await _persist_pending_import(db_session, _PENDING_NODES, _PENDING_EDGES)
|
||||
|
||||
pendings = (
|
||||
inv = (
|
||||
await db_session.execute(
|
||||
select(PendingDevice).where(PendingDevice.ieee_address == "zwave-0xh-2")
|
||||
)
|
||||
).scalars().all()
|
||||
assert pendings == []
|
||||
).scalar_one()
|
||||
assert inv.status == "approved"
|
||||
assert inv.suggested_type == "zwave_router"
|
||||
refreshed = (
|
||||
await db_session.execute(select(Node).where(Node.ieee_address == "zwave-0xh-2"))
|
||||
).scalar_one()
|
||||
|
||||
Reference in New Issue
Block a user