|
7 | 7 | import logging |
8 | 8 |
|
9 | 9 | from labthings.server.quick import create_app |
| 10 | +from labthings.server import fields |
10 | 11 |
|
11 | 12 | from components.pdf_component import PdfComponent |
12 | 13 |
|
|
33 | 34 | "magic_denoise", # Objects attribute name |
34 | 35 | "/denoise", # URL to bind the property to |
35 | 36 | description="A magic denoise property", |
| 37 | + schema=fields.Int(example=200), # Property should be integer formatted |
36 | 38 | ) |
37 | 39 |
|
38 | 40 | labthing.build_property( |
39 | 41 | my_component, # Python object |
40 | 42 | "magic_dictionary", # Objects attribute name |
41 | 43 | "/dictionary", # URL to bind the property to |
42 | 44 | description="A big dictionary of little properties", |
| 45 | + schema={ # Property is a dictionary, with these value types |
| 46 | + "voltage": fields.Int(), |
| 47 | + "volume": fields.List(fields.Int()), |
| 48 | + "mode": fields.String(), |
| 49 | + "light_on": fields.Bool(), |
| 50 | + "user": {"name": fields.String(), "id": fields.Int()}, |
| 51 | + "bytes": fields.Bytes(), |
| 52 | + }, |
43 | 53 | ) |
44 | 54 |
|
45 | 55 | labthing.build_action( |
46 | 56 | my_component.average_data, # Python function |
47 | 57 | "/average", # URL to bind the action to |
48 | 58 | description="Take an averaged measurement", |
49 | 59 | safe=True, # Is the state of the Thing unchanged by calling the action? |
50 | | - idempotent=True, # Can the action be called repeatedly with the same result? |
| 60 | + idempotent=True, # Can the action be called repeatedly with the same result?, |
| 61 | + args={ # How do we convert from the request input to function arguments? |
| 62 | + "n": fields.Int(description="Number of averages to take", example=5, default=5) |
| 63 | + }, |
51 | 64 | ) |
52 | 65 |
|
53 | 66 |
|
|
0 commit comments