diff options
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 |
