astra.device_manager#

Classes

DeviceManager(observatory_config, logger, ...)

Manages loading, connecting, polling, pausing/resuming, and monitoring all Alpaca devices for an observatory.

class astra.device_manager.DeviceManager(observatory_config: ObservatoryConfig, logger: ObservatoryLogger, queue_manager: QueueManager, thread_manager: ThreadManager)[source]#

Bases: object

Manages loading, connecting, polling, pausing/resuming, and monitoring all Alpaca devices for an observatory.

This class handles the lifecycle of devices including: - Loading device configurations - Establishing connections - Starting/stopping polling for FITS header data - Pausing/resuming polls during critical operations - Checking device responsiveness for watchdog monitoring - Forcing immediate polls for specific device types It interacts with the ObservatoryConfig for device settings, uses the ObservatoryLogger for logging, and relies on QueueManager and ThreadManager for asynchronous operations.

observatory_config#

Configuration for the observatory.

Type:

ObservatoryConfig

logger#

Logger for logging messages and errors.

Type:

ObservatoryLogger

queue_manager#

Manages the queue for inter-thread communication.

Type:

QueueManager

thread_manager#

Manages threads for concurrent operations.

Type:

ThreadManager

devices#

Dictionary of loaded devices organized by type and name.

Type:

dict

device_task_monitor_queue#

Tracks tasks for monitoring device status.

Type:

dict

property observatory_config: ObservatoryConfig#

Get the observatory configuration, reloading if the file has been modified.

This property provides access to the observatory configuration and automatically reloads it if the underlying configuration file has been modified since the last access.

Returns:

ObservatoryConfig – The current observatory configuration object.

Note

If the configuration is reloaded, devices may need to be restarted (TODO: implement automatic device restart).

load_devices()[source]#

Load and initialize Alpaca devices based on the observatory configuration.

connect_all(fits_config)[source]#

Connect to all loaded devices and start polling for FITS header data.

Establishes connections to all initialized devices and begins regular polling of device properties needed for FITS headers. Different polling intervals are used based on device criticality: - Most devices: 5-second intervals - SafetyMonitor: 1-second intervals for safety-critical data

The method: 1. Connects to all devices in the devices dictionary 2. Starts polling threads for non-fixed FITS header properties 3. Sets up special high-frequency polling for safety monitors 4. Starts the watchdog process after all connections are established

Raises:

Exception – Device connection errors are logged and added to error_source, but do not prevent other devices from being connected.

Note

  • SPECULOOS observatories skip focuser connection due to compatibility issues

  • A 1-second delay is added after connections before starting the watchdog to ensure devices are ready

pause_polls(device_types=None)[source]#

Pause polling for specified device types or all devices.

Temporarily stops the regular polling of device properties. This is useful during critical operations where device communication needs to be minimized or when devices need to be accessed exclusively by other processes.

Parameters:

device_types (list, optional) – A list of device type strings to pause polling for (e.g., [‘Telescope’, ‘Camera’]). If None, pauses polling for all device types. Defaults to None.

Note

  • Only device types that exist in the devices dictionary will be affected

  • Polling can be resumed using the resume_polls() method

  • This is commonly used in SPECULOOS operations before critical commands

resume_polls(device_types=None)[source]#

Resume polling for specified device types or all devices.

Restarts the regular polling of device properties that was previously paused using pause_polls(). This restores normal device monitoring and data collection for FITS headers.

Parameters:

device_types (list, optional) – A list of device type strings to resume polling for (e.g., [‘Telescope’, ‘Camera’]). If None, resumes polling for all device types. Defaults to None.

Note

  • Only device types that exist in the devices dictionary will be affected

  • This should be called after pause_polls() to restore normal operation

  • Errors during resume are logged but don’t prevent other devices from resuming

stop_all_devices()[source]#

Stop all devices and their associated processes.

check_devices_alive()[source]#

Check if all connected devices are responsive and alive.

Iterates through all loaded devices and tests their responsiveness by calling the is_alive() method. This helps detect communication failures, device crashes, or network issues that could affect observatory operations.

Returns:

bool

True if all devices are responsive, False if any device fails

to respond or encounters an error.

Side Effects:
  • Adds unresponsive devices to error_source list for monitoring

  • Logs error messages for each unresponsive device

  • Returns False immediately if any device fails

Note

  • Called regularly by the watchdog for continuous health monitoring

  • Critical for detecting device failures before they affect observations

  • Used to trigger error handling and recovery procedures

force_poll_observing_conditions(fits_config)[source]#

Force an immediate poll of all ObservingConditions devices.

list_device_names(device_type: str, paired_devices=None) list[source]#

List device names of a given type, optionally filtered by paired devices.

check_telescopes_in_domes()[source]#

Check telescope assignments in domes.

Warn if: - There are telescopes not assigned to any dome - There are domes assigned to telescopes that are not connected

Raise error if: - Dome configuration is invalid