Add options

This commit is contained in:
Fabian Affolter 2016-08-15 18:42:45 +02:00
parent 46a2506278
commit 722c4a6b14
No known key found for this signature in database
GPG Key ID: DDF3D6F44AAB1336

View File

@ -33,6 +33,8 @@ This section contains a couple of snippets for the validation we use.
### {% linkable_title Default name %} ### {% linkable_title Default name %}
It's common to set a default for a sensor if the user is not providing a name to use.
```python ```python
DEFAULT_NAME = 'Sensor name' DEFAULT_NAME = 'Sensor name'
@ -41,6 +43,18 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
``` ```
### {% linkable_title Limit the values %}
In certain cases you want to limit the user's input to a couple of options.
```python
DEFAULT_METHOD = 'GET'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
...
vol.Optional(CONF_METHOD, default=DEFAULT_METHOD): vol.In(['POST', 'GET']),
```
### {% linkable_title Port %} ### {% linkable_title Port %}
As all port numbers are coming out of the range 1 till 65535 a range check should be performed. As all port numbers are coming out of the range 1 till 65535 a range check should be performed.