|
| 1 | +--- |
| 2 | +title: "Configure a Fake Switch" |
| 3 | +linkTitle: "fake" |
| 4 | +weight: 10 |
| 5 | +type: "docs" |
| 6 | +description: "Configure a fake switch for testing." |
| 7 | +images: ["/icons/components/switch.svg"] |
| 8 | +tags: ["switch", "components"] |
| 9 | +aliases: |
| 10 | + - "/components/switch/fake/" |
| 11 | +component_description: "A model used for testing, with no physical hardware." |
| 12 | +toc_hide: true |
| 13 | +--- |
| 14 | + |
| 15 | +The `fake` switch model is a model for testing switch functionality without physical hardware. |
| 16 | +It simulates a multi-position switch which you can control programmatically. |
| 17 | + |
| 18 | +{{< tabs >}} |
| 19 | +{{% tab name="Config Builder" %}} |
| 20 | + |
| 21 | +Navigate to the **CONFIGURE** tab of your machine's page. |
| 22 | +Click the **+** icon next to your machine part in the left-hand menu and select **Component or service**. |
| 23 | +Select the `switch` type, then select the `fake` model. |
| 24 | +Enter a name or use the suggested name for your arm and click **Create**. |
| 25 | + |
| 26 | +Fill in the attributes as applicable to your switch, according to the table below. |
| 27 | + |
| 28 | +{{% /tab %}} |
| 29 | +{{% tab name="JSON Template" %}} |
| 30 | + |
| 31 | +```json {class="line-numbers linkable-line-numbers"} |
| 32 | +{ |
| 33 | + "components": [ |
| 34 | + { |
| 35 | + "name": "<your-switch-name>", |
| 36 | + "model": "fake", |
| 37 | + "type": "switch", |
| 38 | + "namespace": "rdk", |
| 39 | + "attributes": { |
| 40 | + "position_count": <number>, |
| 41 | + "labels": ["<label1>", "<label2>", "<label3>"] |
| 42 | + } |
| 43 | + } |
| 44 | + ] |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +{{% /tab %}} |
| 49 | +{{% tab name="JSON Example" %}} |
| 50 | + |
| 51 | +```json {class="line-numbers linkable-line-numbers"} |
| 52 | +{ |
| 53 | + "components": [ |
| 54 | + { |
| 55 | + "name": "my_switch", |
| 56 | + "model": "fake", |
| 57 | + "type": "switch", |
| 58 | + "namespace": "rdk", |
| 59 | + "attributes": { |
| 60 | + "position_count": 4, |
| 61 | + "labels": ["Off", "Low", "Medium", "High"] |
| 62 | + } |
| 63 | + } |
| 64 | + ] |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +{{% /tab %}} |
| 69 | +{{< /tabs >}} |
| 70 | + |
| 71 | +## Attributes |
| 72 | + |
| 73 | +The following attributes are available for the `fake` switch model: |
| 74 | + |
| 75 | +<!-- prettier-ignore --> |
| 76 | +| Name | Type | Required? | Description | |
| 77 | +| ---- | ---- | --------- | ----------- | |
| 78 | +| `position_count` | int | **Required** | The number of positions that the switch can be in. Default: `2` | |
| 79 | +| `labels` | array | Optional | An array of labels corresponding to the positions. Default: numeric values for the number of positions, starting with 0. | |
| 80 | + |
| 81 | +## Test the switch |
| 82 | + |
| 83 | +{{< readfile "/static/include/components/test-control/switch-control.md" >}} |
| 84 | + |
| 85 | +## Troubleshooting |
| 86 | + |
| 87 | +If your fake switch is not working as expected: |
| 88 | + |
| 89 | +1. Check your machine logs on the **LOGS** tab to check for errors. |
| 90 | +2. Make sure the `position_count` matches the number of `labels` if both are specified. |
| 91 | +3. Verify that position values used with `SetPosition` are within the valid range (0 to `position_count - 1`). |
| 92 | +4. Click on the **TEST** panel on the **CONFIGURE** or **CONTROL** tab and test if you can use the switch there. |
| 93 | + |
| 94 | +## Next steps |
| 95 | + |
| 96 | +Check out the [switch API](/dev/reference/apis/components/switch/) or check out one of these guides: |
| 97 | + |
| 98 | +{{< cards >}} |
| 99 | +{{% card link="/dev/reference/apis/components/switch/" customTitle="Switch API" noimage="true" %}} |
| 100 | +{{% card link="/operate/modules/configure-modules/" noimage="true" %}} |
| 101 | +{{< /cards >}} |
0 commit comments