plestylib.device.params#

Classes#

AutoResponseParser

A response parser that attempts to autocast the raw response to the expected data type defined in the config parameter.

Command

Represents a command that can be sent to the device.

ConfigParameter

Represents a single configuration parameter for a device.

ConfigGroup

Represents a group of configuration parameters for a device.

ConfigSystem

Manage configuration parameters, groups, and validation rules.

Module Contents#

class plestylib.device.params.AutoResponseParser#

Bases: plestylib.device.device_utils.ResponseParser

A response parser that attempts to autocast the raw response to the expected data type defined in the config parameter.

__call__(response, param=None, separator=',', **kwargs)#

Attempt to autocast a value to the specified data type.

Supported types include basic types (int, float, str, bool) and iterable types like List[int], Tuple[float], etc. For iterable types, if the input is a string, it will be split by the specified separator and each element will be cast to the appropriate type.

Parameters:
  • value – The value to be cast, which can be of any type.

  • dtype – The target data type to cast the value to. This can be a basic type or an iterable type.

  • separator – The separator to use when splitting string inputs for iterable types (default is “,”).

class plestylib.device.params.Command#

Represents a command that can be sent to the device.

name: str#
command: str#
required_params: List[str] | None = None#
optional_params: List[str] | None = None#
mode: str = 'write'#
description: str | None = None#
class plestylib.device.params.ConfigParameter#

Represents a single configuration parameter for a device.

name: str#
default: Any = None#
value: Any = None#
dtype: type | None = None#
unit: str | None = None#
read_only: bool = False#
write_only: bool = False#
min_value: float | int | None = None#
max_value: float | int | None = None#
options: list[Any] | None = None#
command: str | None = None#
parser: plestylib.device.device_utils.ResponseParser | None = None#
description: str | None = None#
class plestylib.device.params.ConfigGroup#

Represents a group of configuration parameters for a device.

name: str#
parameters: Dict[str, ConfigParameter]#
command_prefix: str = ''#
allowed_commands: List[Command] = []#
description: str | None = None#
class plestylib.device.params.ConfigSystem(param_schema=None, solver=None)#

Manage configuration parameters, groups, and validation rules.

_config#
auto_parser#
solver = None#
static _parse_command(command: Any) str | Command | None#

Parse command field from schema.

Parameters:

command (Any)

Return type:

str | Command | None

_register_param_dict(params: dict[str, Any], group_name: str) None#

Register all parameters in a schema dictionary into the target group.

Parameters:
  • params (dict[str, Any])

  • group_name (str)

Return type:

None

register_params_from_schema(schema: str | dict[str, Any]) list[str]#

Register parameters and groups from a schema path or dictionary.

Supported schema shapes:

  1. Flat parameters (registered to default group):

{
    "param_a": {
        "type": "float",
        "default": 1.0
    }
}
  1. Group map:

{
    "group_a": {
        "description": "Example group",
        "command_prefix": "CFG",
        "allowed_commands": [
            {
                "name": "set_mode",
                "command": "MODE",
                "mode": "write"
            }
        ],
        "parameters": {
            "param_a": {
                "type": "float",
                "default": 1.0
            }
        }
    }
}
  1. Wrapped group map under “groups”:

{
    "groups": {
        "group_a": {
            "parameters": {
                "param_a": {
                    "type": "float"
                }
            }
        }
    }
}
Returns:

Registered parameter keys.

Return type:

list[str]

Parameters:

schema (str | dict[str, Any])

register_config(key: str, group: str = 'default', default: Any = None, dtype: type | None = None, unit: str | None = None, read_only: bool = False, write_only: bool = False, min_value: float | int | None = None, max_value: float | int | None = None, options: list[Any] | None = None, command: str | Command | None = None, parser: Any = None, description: str | None = None) ConfigParameter#

Register one configuration parameter after validating constraints.

Returns the registered ConfigParameter and raises if the key already exists in the group or the provided metadata is invalid.

Parameters:
  • key (str)

  • group (str)

  • default (Any)

  • dtype (type | None)

  • unit (str | None)

  • read_only (bool)

  • write_only (bool)

  • min_value (float | int | None)

  • max_value (float | int | None)

  • options (list[Any] | None)

  • command (str | Command | None)

  • parser (Any)

  • description (str | None)

Return type:

ConfigParameter

_validate_config_param(param: ConfigParameter) None#

Check the validity of the parameter.

Parameters:

param (ConfigParameter)

Return type:

None

register_config_group(group_name: str, command_prefix: str = '', allowed_commands: List[Command] | None = None, parameters: Dict[str, ConfigParameter] | None = None, description: str | None = None) ConfigGroup#

Register a named group of related configuration parameters.

Returns the registered ConfigGroup and raises if the group already exists or if any provided parameter metadata is invalid.

Parameters:
  • group_name (str)

  • command_prefix (str)

  • allowed_commands (List[Command] | None)

  • parameters (Dict[str, ConfigParameter] | None)

  • description (str | None)

Return type:

ConfigGroup

_check_register_min_max(min_value: float | int | None, max_value: float | int | None) None#

Check the validity of min and max values for a numeric parameter.

Parameters:
  • min_value (float | int | None)

  • max_value (float | int | None)

Return type:

None

_check_type(param: ConfigParameter, value: Any) None#

Check if a value matches the expected data type for a parameter.

Parameters:
Return type:

None

_check_in_range(param: ConfigParameter, value: float | int) None#

Check if a numeric value is within the allowed range for a parameter.

Parameters:
Return type:

None

_check_in_options(param: ConfigParameter, value: Any) None#

Check if a categorical value is within the allowed options for a parameter.

Parameters:
Return type:

None

get_config_list(group: str = 'default') list[str]#

Return a list of registered configuration parameter keys for a specific group.

Parameters:

group (str)

Return type:

list[str]

get_group_list() list[str]#

Return a list of registered configuration group names.

Return type:

list[str]

get_group(group: str) ConfigGroup#

Retrieve a registered configuration group by name.

Parameters:

group (str)

Return type:

ConfigGroup

get_config(key: str, group: str = 'default') ConfigParameter#

Retrieve a registered configuration parameter by key.

Parameters:
  • key (str)

  • group (str)

Return type:

ConfigParameter

set_config_value(key: str, value: Any, group: str = 'default') None#

Set the value of a registered configuration parameter.

Parameters:
  • key (str)

  • value (Any)

  • group (str)

Return type:

None

set_config_min_max(key: str, min_value: float | int | None, max_value: float | int | None, group: str = 'default') None#

Set the minimum and maximum allowed values for a numeric configuration parameter.

Parameters:
  • key (str)

  • min_value (float | int | None)

  • max_value (float | int | None)

  • group (str)

Return type:

None

get_config_value(key: str, group: str = 'default') Any#

Get the current value of a registered configuration parameter.

Parameters:
  • key (str)

  • group (str)

Return type:

Any

check_write_config(key: str, value: Any, group: str = 'default') None#

Check if a value can be written to a configuration parameter without actually writing it.

Parameters:
  • key (str)

  • value (Any)

  • group (str)

Return type:

None

check_query_config(key: str, group: str = 'default') None#

Check if a configuration parameter can be queried.

Parameters:
  • key (str)

  • group (str)

Return type:

None

param_summary(constraints: bool = True, description: bool = False) str#

Return a summary string of the device’s current configuration.

Parameters:
  • constraints (bool)

  • description (bool)

Return type:

str