summaryrefslogtreecommitdiff
path: root/core/profile.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/profile.py')
-rw-r--r--core/profile.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/core/profile.py b/core/profile.py
index b2d25b4..2a70370 100644
--- a/core/profile.py
+++ b/core/profile.py
@@ -69,6 +69,7 @@ class ProfileDerived:
class Profile:
name: str = "Untitled Profile"
version: str = "1.0"
+ devices: List[Dict] = field(default_factory=list)
controls: List[Dict] = field(default_factory=list)
channels: List[Dict] = field(default_factory=list)
pipelines: List[Dict] = field(default_factory=list)
@@ -85,6 +86,7 @@ class Profile:
return Profile(
name = d.get("name", ""),
version = d.get("version", "1.0"),
+ devices = d.get("devices", []),
controls = d.get("controls", []),
channels = d.get("channels", []),
pipelines = d.get("pipelines", []),
@@ -136,6 +138,11 @@ class ProfileManager:
) -> Profile:
p = Profile(name=profile_name)
+ # Devices
+ for dev in registry.all_instances():
+ if hasattr(dev, "get_save_config"):
+ p.devices.append(dev.get_save_config())
+
# Controls
p.controls = [spec.to_dict() for spec in control_specs]
@@ -197,6 +204,7 @@ class ProfileManager:
processor,
control_panel,
settings_ref: dict,
+ engine=None,
):
"""Apply a loaded profile to the live application state."""
from ui.control_editor import ControlSpec
@@ -205,6 +213,54 @@ class ProfileManager:
filter_from_dict,
)
+ # ── Devices ──────────────────────────────────────────────────────
+ _DEVICE_FACTORIES = {}
+ try:
+ from devices.analog_input import AnalogInputDevice
+ _DEVICE_FACTORIES["analog_input"] = AnalogInputDevice
+ except Exception:
+ pass
+ try:
+ from devices.digital_io import DigitalIODevice
+ _DEVICE_FACTORIES["digital_io"] = DigitalIODevice
+ except Exception:
+ pass
+ try:
+ from devices.serial_device import SerialDevice
+ _DEVICE_FACTORIES["serial"] = SerialDevice
+ except Exception:
+ pass
+
+ for dev_cfg in profile.devices:
+ dev_type = dev_cfg.get("device_type")
+ dev_id = dev_cfg.get("device_id")
+ if not dev_id:
+ continue
+ factory = _DEVICE_FACTORIES.get(dev_type)
+ if not factory:
+ print(f"[Profile] Unknown device type: {dev_type}")
+ continue
+ try:
+ # Replace existing device so saved config takes effect
+ existing = registry.get_instance(dev_id)
+ if existing is not None:
+ try:
+ existing.disconnect()
+ except Exception:
+ pass
+ registry.remove_instance(dev_id)
+ if engine is not None:
+ engine.remove_device(dev_id)
+
+ kwargs = {k: v for k, v in dev_cfg.items() if k != "device_type"}
+ dev = factory(**kwargs)
+ registry.add_instance(dev)
+ dev.connect()
+ if engine is not None:
+ engine.add_device(dev)
+ except Exception as e:
+ print(f"[Profile] Could not restore device {dev_id}: {e}")
+
# ── Channel overrides ────────────────────────────────────────────
for ch_data in profile.channels:
dev = registry.get_instance(ch_data["device_id"])