1313import atexit
1414
1515from labthings .server .quick import create_app
16- from labthings .server .decorators import PropertySchema , use_args , marshal_with , Doc
1716from labthings .server import semantics
1817from labthings .server .view import ActionView , PropertyView
1918from labthings .server .find import find_component
@@ -73,23 +72,17 @@ def average_data(self, n: int):
7372"""
7473
7574
76- # Define the data we're going to output (get), and what to expect in (post)
75+ # Wrap in a semantic annotation to autmatically set schema and args
7776@semantics .moz .LevelProperty (100 , 500 , example = 200 )
78- @Doc (description = "Value of magic_denoise" ,)
7977class DenoiseProperty (PropertyView ):
78+ """Value of magic_denoise"""
8079
81- # Main function to handle GET requests (read)
8280 def get (self ):
83- """Show the current magic_denoise value"""
84-
8581 # When a GET request is made, we'll find our attached component
8682 my_component = find_component ("org.labthings.example.mycomponent" )
8783 return my_component .magic_denoise
8884
89- # Main function to handle POST requests (write)
90- def post (self , new_property_value ):
91- """Change the current magic_denoise value"""
92-
85+ def put (self , new_property_value ):
9386 # Find our attached component
9487 my_component = find_component ("org.labthings.example.mycomponent" )
9588
@@ -104,12 +97,13 @@ def post(self, new_property_value):
10497"""
10598
10699
107- @PropertySchema (fields .List (fields .Float ()))
108100class QuickDataProperty (PropertyView ):
109- # Main function to handle GET requests
110- def get (self ):
111- """Show the current data value"""
101+ """Show the current data value"""
102+
103+ # Marshal the response as a list of floats
104+ schema = fields .List (fields .Float ())
112105
106+ def get (self ):
113107 # Find our attached component
114108 my_component = find_component ("org.labthings.example.mycomponent" )
115109 return my_component .data
@@ -123,17 +117,14 @@ def get(self):
123117class MeasurementAction (ActionView ):
124118 # Expect JSON parameters in the request body.
125119 # Pass to post function as dictionary argument.
126- @use_args (
127- {
128- "averages" : fields .Integer (
129- missing = 20 ,
130- example = 20 ,
131- description = "Number of data sets to average over" ,
132- )
133- }
134- )
135- # Output schema
136- @marshal_with (fields .List (fields .Number ))
120+ args = {
121+ "averages" : fields .Integer (
122+ missing = 20 , example = 20 , description = "Number of data sets to average over" ,
123+ )
124+ }
125+ # Marshal the response as a list of numbers
126+ schema = fields .List (fields .Number )
127+
137128 # Main function to handle POST requests
138129 def post (self , args ):
139130 """Start an averaged measurement"""
0 commit comments