diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2026-09-20 11:31:07 -0600 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2026-09-20 11:31:07 -0600 |
| commit | bb8be051ffffa56a01093c9f3aaa80e84748568f (patch) | |
| tree | db5c0e3e5f8a453984aea9c70afa007319c610c3 /devices/base_device.py | |
| parent | f3327d56d48d63b21ffc03a55fa5e7db753d1707 (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 'devices/base_device.py')
| -rw-r--r-- | devices/base_device.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/devices/base_device.py b/devices/base_device.py index e3eed65..ae7f438 100644 --- a/devices/base_device.py +++ b/devices/base_device.py @@ -104,3 +104,20 @@ class BaseDevice(ABC): def __repr__(self): return f"<{self.__class__.__name__} id={self.info.device_id} status={self.status.value}>" + + +def merge_signal_metadata(old_signals: List[SignalConfig], new_signals: List[SignalConfig]) -> List[SignalConfig]: + """Reapply user-customized Signal metadata (name/unit/enabled/color) onto a + freshly rebuilt signal list, keyed by signal_id. Mirrors exactly the fields + ProfileManager treats as user overrides (core/profile.py capture/apply) so + identity set at profile-load time survives a later device reconfigure too — + otherwise a device's own reconfigure()/remap_pins() rebuilding info.signals + from scratch silently resets names back to hardware defaults. Signal ids + not present in old_signals (new pins) keep their fresh defaults; ids no + longer in new_signals (removed pins) are simply dropped.""" + old_by_id = {s.signal_id: s for s in old_signals} + for sig in new_signals: + old = old_by_id.get(sig.signal_id) + if old is not None: + sig.name, sig.unit, sig.enabled, sig.color = old.name, old.unit, old.enabled, old.color + return new_signals |
