devctrl.devices.device_manager.DeviceManager#
- class DeviceManager(config_file: ConfigFile | None = None, config_template: str = 'last_dev_<device>_<type/name>', prompt_choice_func: Callable[[DeviceInfo], tuple[str, str]] | None = None)[source]#
Bases:
objectClass that handles multiple devices. It can: - connect to devices by prompting the user, via command line or a GUI widget (prompt function must be supplied, see device_select.py) - save the device name and id for each device to a config file - auto-reconnect to the devices from the config file - check if devices are still connected - make the devices available as global variables for interactive use
Methods
Add or update a device.
Add or update a device from a DeviceInfo object.
check_connectedConnect the dummy implementation of the device.
Connect the device by reading the typename and name from the configuration file.
Connect a device the config file.
Connect a device from a prompt to the user.
Connect the device using the provided device typename and name
Return the device instance of a connected device.
Return the device instance of a connected device.
Get a dictionary of globals.
Return the device info instance of the device.
Return all device keys, sorted by descending connect_priority
Check if the device was connected.
Remove a device.
Attributes
Event is emitted when a new device is added
Event is emitted when a device is removed
Event is emitted when a device info is updated
- add_device(key: str, name: str, device_type: Type[Device], global_varname: str | None, connect_priority: int = 0)[source]#
Add or update a device.
- add_device_info(device_info: DeviceInfo)[source]#
Add or update a device from a DeviceInfo object.
- connect_from_config(key: str, override_config_file: ConfigFile | None = None) Device[source]#
Connect the device by reading the typename and name from the configuration file.
- Parameters:
key – The device key
override_config_file – ConfigFile to read the device type and name from
- Returns:
device
- connect_from_config_then_prompt(key: str, override_prompt_choice_func: Callable | None = None, override_config_file: ConfigFile | None = None, n_prompt_tries=3) Device[source]#
Connect a device the config file. If that fails, prompt the user. The promt is given by the prompt_choice_func and can be via the command line or a GUI.
- Parameters:
key – The device key
override_prompt_choice_func – The function that lets the user select a device
override_config_file – ConfigFile to store the typename and name in
- Returns:
device
- connect_from_prompt(key: str, override_prompt_choice_func: Callable | None = None, override_config_file: ConfigFile | None = None) Device[source]#
Connect a device from a prompt to the user. The promt is given by the prompt_choice_func and can be via the command line or a GUI.
- Parameters:
key – The device key
override_prompt_choice_func – The function that lets the user select a device
override_config_file – ConfigFile to store the typename and name in
- Returns:
device
- connect_manually(key: str, device_typename: str, device_name: str, override_config_file: ConfigFile | None = None) Device[source]#
Connect the device using the provided device typename and name
- Parameters:
key – The device key
device_typename – device type name to use in the config file key
device_typename_prompt – String describing device type to use in the interactive prompt
override_config_file – ConfigFile to store the typename and name in
- Returns:
device
- e_device_added#
Event is emitted when a new device is added
- e_device_removed#
Event is emitted when a device is removed
- e_device_updated#
Event is emitted when a device info is updated
- get_connection_info(key: str) tuple[str, str][source]#
- Returns:
device typename and device name that were passed to the to device’s connect method
- Raises:
KeyError – if no connection info is available for the device
- get_device(key: str, assert_type: Type[_T] = <class 'devctrl.devices.device.Device'>) _T[source]#
Return the device instance of a connected device.
- Parameters:
key – Device key
assert_type – Type of the device instance to return.
- Returns:
The device instance
- Raises:
RuntimeError – If the device was added but is not connected or if the connected type fails the type check
KeyError – If the device was not added
- get_device_or(key: str, default=None) Device | None[source]#
Return the device instance of a connected device.
- Parameters:
key – Device key
- Returns:
The device instance, or default if device is not connected or was not added
- get_globals() dict[str, Device][source]#
Get a dictionary of globals. Can be added to global variables in your context using globals().update(device_manager.get_globals()) :return: dictionary containing the global variable names and the associated device
- get_info(key: str) DeviceInfo[source]#
Return the device info instance of the device.
- Parameters:
key – Device name
- Returns:
DeviceInfo instance
- Raises:
KeyError – If the device was not added
- get_keys() list[str][source]#
Return all device keys, sorted by descending connect_priority
- Returns:
Sorted list of keys