@@ -21,6 +21,12 @@ Beside the [voluptuous](https://pypi.python.org/pypi/voluptuous) default types a
21
21
22
22
To validate plaforms using [ MQTT] ( /components/mqtt/ ) there are ` valid_subscribe_topic ` and ` valid_publish_topic ` present.
23
23
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
+
24
30
### {% linkable_title Snippets %}
25
31
26
32
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.
30
36
``` python
31
37
DEFAULT_NAME = ' Sensor name'
32
38
33
- PLATFORM_SCHEMA = vol.Schema ({
39
+ PLATFORM_SCHEMA = PLATFORM_SCHEMA .extend ({
34
40
...
35
41
vol.Optional(CONF_NAME , default = DEFAULT_NAME ): cv.string,
36
42
```
@@ -42,8 +48,8 @@ As all port numbers are coming out of the range 1 till 65535 a range check shoul
42
48
```python
43
49
DEFAULT_PORT = 993
44
50
45
- PLATFORM_SCHEMA = vol.Schema ({
46
- [ ... ]
51
+ PLATFORM_SCHEMA = PLATFORM_SCHEMA .extend ({
52
+ ...
47
53
vol.Optional(CONF_PORT , default = DEFAULT_PORT ):
48
54
vol.All(vol.Coerce(int ), vol.Range(min = 1 , max = 65535 )),
49
55
```
@@ -58,8 +64,8 @@ SENSOR_TYPES = {
58
64
' average_download_rate' : (' Average Speed' , ' MB/s' ),
59
65
}
60
66
61
- PLATFORM_SCHEMA = vol.Schema ({
62
- ... .
67
+ PLATFORM_SCHEMA = PLATFORM_SCHEMA .extend ({
68
+ ...
63
69
vol.Optional(CONF_MONITORED_VARIABLES , default = []):
64
70
[vol.In(SENSOR_TYPES )],
65
71
```
0 commit comments