Skip to content

Commit 860c4a9

Browse files
committed
Add some more details and use extend
1 parent e6b65dd commit 860c4a9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

source/developers/development_validation.markdown

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Beside the [voluptuous](https://pypi.python.org/pypi/voluptuous) default types a
2121

2222
To validate plaforms using [MQTT](/components/mqtt/) there are `valid_subscribe_topic` and `valid_publish_topic` present.
2323

24+
Some things to keep in mind:
25+
26+
- Use the constants which are definded in `const.py`.
27+
- Import `PLATFORM_SCHEMA` from parent component and extend it.
28+
- Preferred order is `required` first, then `optional`.
29+
2430
### {% linkable_title Snippets %}
2531

2632
This section contains a couple of snippets for the validation we use.
@@ -30,7 +36,7 @@ This section contains a couple of snippets for the validation we use.
3036
```python
3137
DEFAULT_NAME = 'Sensor name'
3238

33-
PLATFORM_SCHEMA = vol.Schema({
39+
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
3440
...
3541
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
3642
```
@@ -42,8 +48,8 @@ As all port numbers are coming out of the range 1 till 65535 a range check shoul
4248
```python
4349
DEFAULT_PORT = 993
4450

45-
PLATFORM_SCHEMA = vol.Schema({
46-
[...]
51+
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
52+
...
4753
vol.Optional(CONF_PORT, default=DEFAULT_PORT):
4854
vol.All(vol.Coerce(int), vol.Range(min=1, max=65535)),
4955
```
@@ -58,8 +64,8 @@ SENSOR_TYPES = {
5864
'average_download_rate': ('Average Speed', 'MB/s'),
5965
}
6066

61-
PLATFORM_SCHEMA = vol.Schema({
62-
....
67+
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
68+
...
6369
vol.Optional(CONF_MONITORED_VARIABLES, default=[]):
6470
[vol.In(SENSOR_TYPES)],
6571
```

0 commit comments

Comments
 (0)