Skip to content

Commit 722c4a6

Browse files
committed
Add options
1 parent 46a2506 commit 722c4a6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

source/developers/development_validation.markdown

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ This section contains a couple of snippets for the validation we use.
3333

3434
### {% linkable_title Default name %}
3535

36+
It's common to set a default for a sensor if the user is not providing a name to use.
37+
3638
```python
3739
DEFAULT_NAME = 'Sensor name'
3840

@@ -41,6 +43,18 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
4143
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
4244
```
4345

46+
### {% linkable_title Limit the values %}
47+
48+
In certain cases you want to limit the user's input to a couple of options.
49+
50+
```python
51+
DEFAULT_METHOD = 'GET'
52+
53+
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
54+
...
55+
vol.Optional(CONF_METHOD, default=DEFAULT_METHOD): vol.In(['POST', 'GET']),
56+
```
57+
4458
### {% linkable_title Port %}
4559

4660
As all port numbers are coming out of the range 1 till 65535 a range check should be performed.

0 commit comments

Comments
 (0)