choice

The “choice” type alows to pick a value from a list and to match it with a corresponding value in a dict.

Device Profile

Example of a choice value type in a device profile:

profile = {

    # ...

    "settings": {

        "light_effect": {
            "label": "Light effect",
            "description": "Set the light effect",
            "cli": ["-e", "--light-effect"],
            "report_type": usbhid.HID_REPORT_TYPE_OUTPUT,
            "command": [0x07, 0x00],
            "value_type": "choice",
            "choices": {
                "steady": 0x01,
                "breath": 0x03,
                1: 0x01,
                2: 0x02,
                3: 0x03,
                4: 0x04,
            },
            "default": "steady",
        },

    },

    # ...

}

CLI

Example of CLI option generated with this handler:

-e LIGHT_EFFECT, --light-effect=LIGHT_EFFECT
                    Set the light effect (values: steady, breath, 1, 2, 3,
                    4, default: steady)

Example of CLI usage:

rivalcfg --light-effet=steady

Functions

rivalcfg.handlers.choice.add_cli_option(cli_parser, setting_name, setting_info)

Add the given “choice” type setting to the given CLI arguments parser.

Parameters:
  • cli_parser (ArgumentParser) – An ArgumentParser instance.

  • setting_name (str) – The name of the setting.

  • setting_info (dict) – The information dict of the setting from the device profile.

rivalcfg.handlers.choice.choices_to_list(choices)

Helper function that transforms choices dict to an ordered string list. Numeric values are sorted and placed after string values.

Parameters:

choices (dict) – The dict containing available choices.

Return type:

list[str]

>>> choices_to_list({0: 0, 1: 1, 2: 2, "foo": 2})
['foo', '0', '1', '2']
rivalcfg.handlers.choice.choices_to_string(choices)

Helper function that transforms choices dict to a printable string.

Parameters:

choices (dict) – The dict containing available choices.

Return type:

str

>>> choices_to_string({0: 0, 1: 1, 2: 2, "foo": 2})
'foo, 0, 1, 2'
rivalcfg.handlers.choice.process_value(setting_info, choice)

Called by the rivalcfg.mouse.Mouse class when processing a “choice” type setting.

Parameters:
  • setting_info (dict) – The information dict of the setting from the device profile.

  • choice – The selected choice.

Return type:

list[int]