|
3 | 3 | import logging
|
4 | 4 |
|
5 | 5 | from labthings.server.quick import create_app
|
6 |
| -from labthings.server.decorators import ( |
7 |
| - ThingProperty, |
8 |
| - PropertySchema, |
9 |
| - ThingAction, |
10 |
| - use_args, |
11 |
| - marshal_task, |
12 |
| - doc, |
13 |
| -) |
14 |
| -from labthings.server.view import View |
| 6 | +from labthings.server.view import ActionView, PropertyView |
15 | 7 | from labthings.server.find import find_component
|
16 | 8 | from labthings.server import fields
|
17 | 9 | from labthings.core.utilities import path_relative_to
|
|
28 | 20 | """
|
29 | 21 |
|
30 | 22 |
|
31 |
| -@ThingAction |
32 |
| -class ExtensionMeasurementAction(View): |
33 |
| - # Expect JSON parameters in the request body. |
34 |
| - # Pass to post function as dictionary argument. |
35 |
| - @use_args( |
36 |
| - { |
37 |
| - "averages": fields.Integer( |
38 |
| - missing=10, |
39 |
| - example=10, |
40 |
| - description="Number of data sets to average over", |
41 |
| - ) |
42 |
| - } |
43 |
| - ) |
44 |
| - # Shorthand to say we're always going to return a Task object |
45 |
| - @marshal_task |
46 |
| - # Main function to handle POST requests |
47 |
| - def post(self, args): |
48 |
| - """Start an averaged measurement""" |
| 23 | +class ExtensionMeasurementAction(ActionView): |
| 24 | + """Start an averaged measurement""" |
| 25 | + |
| 26 | + args = { |
| 27 | + "averages": fields.Integer( |
| 28 | + missing=10, example=10, description="Number of data sets to average over", |
| 29 | + ) |
| 30 | + } |
49 | 31 |
|
| 32 | + def post(self, args): |
50 | 33 | # Find our attached component
|
51 | 34 | my_component = find_component("org.labthings.example.mycomponent")
|
52 | 35 |
|
@@ -114,17 +97,15 @@ def data(self):
|
114 | 97 | """
|
115 | 98 |
|
116 | 99 |
|
117 |
| -@ThingProperty # Register this view as a Thing Property |
118 |
| -@PropertySchema( # Define the data we're going to output (get), and what to expect in (post) |
119 |
| - fields.Integer( |
| 100 | +class DenoiseProperty(PropertyView): |
| 101 | + |
| 102 | + schema = fields.Integer( |
120 | 103 | required=True,
|
121 | 104 | example=200,
|
122 | 105 | minimum=100,
|
123 | 106 | maximum=500,
|
124 | 107 | description="Value of magic_denoise",
|
125 | 108 | )
|
126 |
| -) |
127 |
| -class DenoiseProperty(View): |
128 | 109 |
|
129 | 110 | # Main function to handle GET requests (read)
|
130 | 111 | def get(self):
|
@@ -152,9 +133,10 @@ def post(self, new_property_value):
|
152 | 133 | """
|
153 | 134 |
|
154 | 135 |
|
155 |
| -@ThingProperty |
156 |
| -@PropertySchema(fields.List(fields.Float())) |
157 |
| -class QuickDataProperty(View): |
| 136 | +class QuickDataProperty(PropertyView): |
| 137 | + |
| 138 | + schema = fields.List(fields.Float()) |
| 139 | + |
158 | 140 | # Main function to handle GET requests
|
159 | 141 | def get(self):
|
160 | 142 | """Show the current data value"""
|
|
0 commit comments