diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/profile.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/core/profile.py b/core/profile.py index 1fa667a..c0ae5f1 100644 --- a/core/profile.py +++ b/core/profile.py @@ -325,9 +325,33 @@ class ProfileManager: # "name" is a display label, not a constructor arg — every device # factory builds its own default name internally, so apply it # after construction instead of passing it through. - custom_name = dev_cfg.get("name") + # "port_desc"/"port_serial" are identity metadata for port + # re-detection below, not constructor args either. + custom_name = dev_cfg.get("name") + port_desc = dev_cfg.get("port_desc", "") + port_serial = dev_cfg.get("port_serial", "") kwargs = {k: v for k, v in dev_cfg.items() - if k not in ("device_type", "name")} + if k not in ("device_type", "name", "port_desc", "port_serial")} + + # Re-map the saved port to whatever it enumerates as on *this* + # machine — COM/tty numbers aren't stable across machines (or + # even across replugs on some OSes). Only if the saved port + # isn't already present verbatim (same-machine reload — nothing + # to fix) and we have something to match against. + if not kwargs.get("simulate", True) and "port" in kwargs and (port_desc or port_serial): + from api_layers.arduino_layer import ArduinoLayer + current_ports = {dev for dev, _ in ArduinoLayer.list_ports()} + if kwargs["port"] not in current_ports: + found = ArduinoLayer.find_port_by_identity(port_desc, port_serial) + if found: + print(f"[Profile] '{dev_id}': port {kwargs['port']!r} not found, " + f"re-mapped to {found!r} by device identity") + kwargs["port"] = found + else: + print(f"[Profile] '{dev_id}': port {kwargs['port']!r} not found and " + f"no matching device on this machine — will show ERROR " + f"until reconfigured") + dev = factory(**kwargs) if custom_name: dev.info.name = custom_name |
