ConfigurableCsc#
- class lsst.ts.salobj.ConfigurableCsc(name, index, config_schema, config_dir=None, check_if_duplicate=False, initial_state=None, override='', simulation_mode=0, extra_commands={})#
-
Base class for a configurable Commandable SAL Component (CSC)
- Parameters:
name (
str) – Name of SAL component.index (
intorNone) – SAL component index, or 0 or None if the component is not indexed.config_schema (
dict) – Configuration schema, as a dict in jsonschema format.config_dir (
str, optional) – Directory of configuration files, or None for the standard configuration directory (obtained from_get_default_config_dir). This is provided for unit testing.check_if_duplicate (
bool, optional) – Check for heartbeat events from the same SAL name and index at startup (before starting the heartbeat loop)? Defaults to False in order to speed up unit tests, butamainsets it true.initial_state (
State,intorNone, optional) – Initial state for this CSC. If None use the class attributedefault_initial_state. TypicallyState.STANDBY(orState.OFFLINEfor an externally commandable CSC) but can also beState.DISABLED, orState.ENABLED, in which case you may also want to specifyoverridefor a configurable CSC.override (
str, optional) – Configuration override file to apply ifinitial_stateisState.DISABLEDorState.ENABLED.simulation_mode (
int, optional) – Simulation mode. The default is 0: do not simulate.extra_commands (
set`[`str]) – List of commands that can be defined in the CSC but be missing from the interface.
- Raises:
ValueError – If
config_diris not a directory orinitial_stateis invalid.salobj.ExpectedError – If
simulation_modeis invalid. Note: you will only see this error if you awaitstart_task.RuntimeError – If the environment variable
LSST_SITEis not set.
- config_dir#
Directory containing configuration files.
- Type:
- config_validator#
Validator for configuration files.
- Type:
StandardValidator
- schema_version#
Configuration schema version, as specified in the schema as the final word of the
title. Used to find theconfig_dir.- Type:
- site#
The value of the
LSST_SITEenvironment variable, e.g. “summit”. Used to select the correct configuration files.- Type:
Notes
Configuration
Configuration is handled by the
startcommand, as follows:The
overridefield specifies a path to a configuration file found in the package specified byconfig_pkgin a subdirectory with the name of this SAL component (e.g. Test or ATDomeTrajectory).The configuration file is validated against the schema specified by specified
config_schema. This includes setting default values from the schema and validating the result again (in case the default values are invalid).The validated configuration is converted to a struct-like object using
types.SimpleNamespace.The configuration is passed to the
configuremethod, which subclasses must override. Note thatconfigureis called just before summary state changes fromState.STANDBYtoState.DISABLED.
Constructor
The constructor does the following, beyond the parent class constructor:
Set summary state, then run the
ConfigurableCsc.startasynchronously, which does the following:If
initial_summary_stateisState.DISABLEDorState.ENABLEDthen callConfigurableCsc.configure.Call
BaseCsc.report_summary_stateSet
start_taskdone
Attributes Summary
Get or set the configuration directory.
Methods Summary
add_arguments(parser)Add arguments to the parser created by
make_from_cmd_line.add_kwargs_from_args(args, kwargs)Add constructor keyword arguments based on parsed arguments.
begin_start(data)Begin do_start; configure the CSC before changing state.
Shut down pending tasks.
configure(config)Configure the CSC.
Get the name of the configuration package, e.g. "ts_config_ocs".
Read the config dir and put configurationsAvailable if changed.
read_config_files(config_validator, ...[, ...])Read a set of configuration files and return the validated config.
Attributes Documentation
- config_dir#
Get or set the configuration directory.
- Parameters:
config_dir (
str,pathlib.Path) – New configuration directory.- Returns:
config_dir – Absolute path to the configuration directory.
- Return type:
- Raises:
ValueError – If the new configuration dir is not a directory.
Methods Documentation
- classmethod add_arguments(parser)#
Add arguments to the parser created by
make_from_cmd_line.- Parameters:
parser (
argparse.ArgumentParser) – The argument parser.- Return type:
Notes
If you override this method then you should almost certainly override
add_kwargs_from_argsas well.
- classmethod add_kwargs_from_args(args, kwargs)#
Add constructor keyword arguments based on parsed arguments.
- Parameters:
args (
argparse.Namespace) – Parsed command.kwargs (
dict) – Keyword argument dict for the constructor. Update this based onargs. The index argument will already be present if relevant.
- Return type:
Notes
If you override this method then you should almost certainly override
add_argumentsas well.
- async begin_start(data)#
Begin do_start; configure the CSC before changing state.
- Parameters:
data (
cmd_start.DataType) – Command data- Return type:
Notes
The
overridefield must be one of:The name of a config label or config file
The name and version of a config file, formatted as
<file_name>:<version>, where the version is a git reference, such as a git tag or commit hash. This form does not support labels.
- abstract async configure(config)#
Configure the CSC.
- Parameters:
config (
object) – The configuration, as described by the config schema, as a struct-like object.- Return type:
Notes
Called when running the
startcommand, just before changing summary state fromState.STANDBYtoState.DISABLED.
- abstract static get_config_pkg()#
Get the name of the configuration package, e.g. “ts_config_ocs”.
- Return type:
- async read_config_dir()#
Read the config dir and put configurationsAvailable if changed.
Output the
configurationsAvailableevent (if changed), after updating theoverridesandversionfields. Also update theversionfield ofevt_configurationApplied, in preparation for the next time the event is output.- Return type:
- classmethod read_config_files(config_validator, config_dir, files_to_read, git_hash='')#
Read a set of configuration files and return the validated config.
- Parameters:
config_validator (jsonschema validator) – Schema validator for configuration.
config_dir (pathlib.Path) – Path to config files.
files_to_read (List [str]) – Names of files to read, with .yaml suffix. Empty names are ignored (a useful feature for BaseConfigTestCase). The files are read in order, with each later file overriding values that have been accumulated so far.
git_hash (str, optional) – Git hash to use for the files. “” if current.
- Returns:
The validated config as a simple namespace.
- Return type:
- Raises:
ExpectedError – If the specified configuration files cannot be found, cannot be parsed as yaml dicts, or produce an invalid configuration (one that does not match the schema).