summaryrefslogtreecommitdiff
path: root/core/reference_registry.py
diff options
context:
space:
mode:
authorChristian Kolset <christian.kolset@gmail.com>2026-09-20 11:31:07 -0600
committerChristian Kolset <christian.kolset@gmail.com>2026-09-20 11:31:07 -0600
commitbb8be051ffffa56a01093c9f3aaa80e84748568f (patch)
treedb5c0e3e5f8a453984aea9c70afa007319c610c3 /core/reference_registry.py
parentf3327d56d48d63b21ffc03a55fa5e7db753d1707 (diff)
Fix Signal name reset and orphaned references on device reconfigure
Apply & Reconnect rebuilt a device's whole Signal list from hardware defaults on every call, silently discarding user/profile-set names, units, and colors even when pins hadn't changed. Add merge_signal_metadata() and call it from ArduinoDevice.remap_pins() and SerialDevice.reconfigure() to reapply the same fields ProfileManager already treats as user overrides, keyed by signal_id. Also close a related gap: removing a pin that a Channel/Plot/Control still referenced left it silently dangling, and SignalProcessor never pruned its latest-value cache, so a derived Channel kept computing off a permanently frozen stale reading. Add SignalProcessor. on_device_reconfigured() to purge that cache, reference_registry. find_references() for a console breadcrumb, and live "missing source" indicators on Plot traces and Channel blocks reusing ControlWidget's existing stale/QSS pattern. Also fixes ControlWidget._write() still enqueuing writes to a channel that no longer exists. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'core/reference_registry.py')
-rw-r--r--core/reference_registry.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/core/reference_registry.py b/core/reference_registry.py
index b6fcd0f..7ab9649 100644
--- a/core/reference_registry.py
+++ b/core/reference_registry.py
@@ -20,7 +20,7 @@ hold such a reference and rewrites it. It expects a MainWindow instance
reachable from.
"""
-from typing import Tuple
+from typing import List, Tuple
Ref = Tuple[str, str]
@@ -72,3 +72,33 @@ def propagate_rename(app, old_ref: Ref, new_ref: Ref) -> None:
win.refresh_derived()
if hasattr(win, "refresh_devices"):
win.refresh_devices()
+
+
+def find_references(app, ref: Ref) -> List[str]:
+ """Reverse lookup: human-readable names of everything currently holding
+ a (device_id, channel_id) reference — same 5 subsystems propagate_rename()
+ walks, but collecting instead of rewriting. Used to flag a signal_id an
+ Apply & Reconnect just dropped (still referenced elsewhere = orphaned),
+ without blocking the reconnect itself — see devices_window/channels_window/
+ control_panel "missing source" indicators, which do the live per-widget
+ check; this is only for a one-line summary breadcrumb."""
+ found: List[str] = []
+
+ for dc in app.processor.get_derived():
+ if ref in dc.sources:
+ found.append(f"Channel '{dc.name}'")
+
+ chart = getattr(app, "_chart", None)
+ if chart is not None and chart._cfg is not None:
+ for pane in chart._cfg.panes:
+ for tr in pane.traces:
+ if (tr.device_id, tr.channel_id) == ref:
+ found.append(f"Plot '{pane.title}' trace '{tr.label or tr.channel_id}'")
+
+ ctrl = getattr(app, "_ctrl", None)
+ if ctrl is not None:
+ for spec in ctrl.get_specs():
+ if (spec.device_id, spec.channel_id) == ref:
+ found.append(f"Control '{spec.title}'")
+
+ return found