File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change 6
6
from labthings .server .decorators import (
7
7
ThingAction ,
8
8
ThingProperty ,
9
+ PropertySchema ,
9
10
use_args ,
10
11
use_body ,
11
12
marshal_task ,
@@ -67,28 +68,27 @@ def average_data(self, n: int):
67
68
"""
68
69
69
70
70
- @ThingProperty
71
+ @ThingProperty # Register this view as a Thing Property
72
+ @PropertySchema ( # Define the data we're going to output (get), and what to expect in (post)
73
+ fields .Integer (
74
+ required = True ,
75
+ example = 200 ,
76
+ minimum = 100 ,
77
+ maximum = 500 ,
78
+ description = "Value of magic_denoise" ,
79
+ )
80
+ )
71
81
class DenoiseProperty (View ):
72
82
73
- # Output will be a single integer
74
- @marshal_with (fields .Integer (example = 200 ))
75
- # Main function to handle GET requests
83
+ # Main function to handle GET requests (read)
76
84
def get (self ):
77
85
"""Show the current magic_denoise value"""
78
86
79
87
# When a GET request is made, we'll find our attached component
80
88
my_component = find_component ("org.labthings.example.mycomponent" )
81
89
return my_component .magic_denoise
82
90
83
- # Expect a single integer in the request body. Pass to post function as argument.
84
- @use_body (
85
- fields .Integer (
86
- required = True , example = 200 , description = "New value for magic_denoise"
87
- )
88
- )
89
- # Output will be a single integer
90
- @marshal_with (fields .Integer (example = 200 ))
91
- # Main function to handle POST requests
91
+ # Main function to handle POST requests (write)
92
92
def post (self , body ):
93
93
"""Change the current magic_denoise value"""
94
94
You can’t perform that action at this time.
0 commit comments