spc-group / guarneri

Other
0 stars 0 forks source link

Make the config file be the authority #3

Closed canismarko closed 2 days ago

canismarko commented 1 week ago

Current Behavior

The main internal structure for Guarneri is like:

{
    "Motor": [  # device class
        {
            "name": "m1",
            "prefix": "25idc:m1",
        }
    ]
}

Right now, Guarneri iterates through it's mapping of device class names to device classes and checks if that name is present in the internal dictionary.

New Behavior

Based on discussion with @MDecarabas and @prjemian, we should flip this. Instead, let's create an internal structure from the TOML file that looks something like:

{
    "m1": [
        {
            "device_class": "Motor",
            "kwargs": {
                ...
            }
        }
    ]
}

then we can iterate through this structure and construct the devices accordingly.

Benefits

1) Mistyped classes can be identified when parsing, and raise exceptions. 2) Device class aliases can be optional. If a device class is not in the initial mapping, but is still importable by Guarneri, it can still be added. No coding necessary.