Configure a Fake Switch

The fake switch model is used for testing switch functionality without requiring physical hardware. It simulates a multi-position switch that can be controlled programmatically.

Navigate to the CONFIGURE tab of your machine’s page. Click the + icon next to your machine part in the left-hand menu and select Component or service. Select the switch type, then select the fake model. Enter a name or use the suggested name for your arm and click Create.

Fill in the attributes as applicable to your switch, according to the table below.

{
  "components": [
    {
      "name": "<your-switch-name>",
      "model": "fake",
      "type": "switch",
      "namespace": "rdk",
      "attributes": {
        "position_count": <number>,
        "labels": ["<label1>", "<label2>", "<label3>"]
      }
    }
  ]
}
{
  "components": [
    {
      "name": "my_switch",
      "model": "fake",
      "type": "switch",
      "namespace": "rdk",
      "attributes": {
        "position_count": 4,
        "labels": ["Off", "Low", "Medium", "High"]
      }
    }
  ]
}

Attributes

The following attributes are available for the fake switch model:

NameTypeRequired?Description
position_countintRequiredThe number of positions that the switch can be in. If omitted, the switch will have two positions. Default: 2
labelsarrayOptionalAn array of labels corresponding to the positions. If omitted, the switch will have labels of “Position 1”, “Position 2”, etc. The number of labels should match the position_count.

Test the switch

Once you have configured your switch, open the switch’s TEST panel on the CONFIGURE or CONTROL tab. You will be able to view the current position and change the switch’s position.

Troubleshooting

If your fake switch is not working as expected:

  1. Check your machine logs on the LOGS tab to check for errors.
  2. Make sure the position_count matches the number of labels if both are specified.
  3. Verify that position values used with SetPosition are within the valid range (0 to position_count - 1).
  4. Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the switch there.

Next steps