Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix(inventory): keep a mesh device's origin when a node draws it

Pouzord49de5da57a1
diff --git a/backend/app/services/inventory_sync.py b/backend/app/services/inventory_sync.py
index 3f9dcc1..650f43f 100644
--- a/backend/app/services/inventory_sync.py
+++ b/backend/app/services/inventory_sync.py
@@ -840,7 +840,13 @@ async def link_facts(
overwrite_scalars=overwrite_scalars,
replace_lists=replace_lists,
)
- device.discovery_sources = add_source(device.discovery_sources, CANVAS_SOURCE)
+ # Seed the list with the row's origin first: the Zigbee and Z-Wave imports
+ # leave `discovery_sources` empty, and the UI reads the list over
+ # `discovery_source` once it has anything in it — `["canvas"]` alone
+ # would file a mesh device under Canvas and drop it from the Zigbee view.
+ device.discovery_sources = add_source(
+ add_source(device.discovery_sources, device.discovery_source), CANVAS_SOURCE
+ )
# A row a node draws is past the pending queue — the mirror of the
# "approved but no longer drawn -> pending" revival the imports do. A hidden
diff --git a/backend/tests/test_inventory_sync.py b/backend/tests/test_inventory_sync.py
index 28ce740..2792375 100644
--- a/backend/tests/test_inventory_sync.py
+++ b/backend/tests/test_inventory_sync.py
@@ -462,6 +462,46 @@ class TestStatusOnLink:
assert device is not None and device.status == "hidden"
+
+class TestSourcesOnLink:
+ """Drawing a discovered device adds ``canvas`` to its sources, never replaces them."""
+
+ @pytest.mark.asyncio
+ async def test_a_mesh_row_keeps_its_origin_when_a_node_draws_it(self, db_session):
+ """Regression for #532: the Zigbee import leaves `discovery_sources` empty,
+ and linking a node turned it into `["canvas"]` alone — the device then
+ dropped out of the Zigbee filter and showed a CANVAS chip."""
+ design = await _design(db_session)
+ db_session.add(InventoryDevice(
+ id="d-zb", ieee_address="0xAAAA", status="approved",
+ discovery_source="zigbee", discovery_sources=[],
+ ))
+ node = _node(design, device_id="d-zb")
+ db_session.add(node)
+ await db_session.commit()
+
+ device = await link_facts(db_session, node, {"label": "Lidl PC"})
+ await db_session.commit()
+
+ assert device is not None and device.discovery_sources == ["zigbee", "canvas"]
+
+ @pytest.mark.asyncio
+ async def test_a_row_already_filed_under_canvas_gets_its_origin_back(self, db_session):
+ """Rows the bug already rewrote to `["canvas"]` heal on their next save."""
+ design = await _design(db_session)
+ db_session.add(InventoryDevice(
+ id="d-zb", ieee_address="0xAAAA", status="approved",
+ discovery_source="zigbee", discovery_sources=["canvas"],
+ ))
+ node = _node(design, device_id="d-zb")
+ db_session.add(node)
+ await db_session.commit()
+
+ device = await link_facts(db_session, node, {"label": "Lidl PC"})
+ await db_session.commit()
+
+ assert device is not None and set(device.discovery_sources) == {"zigbee", "canvas"}
+
# --- the backfill -----------------------------------------------------------