Skip to content

Commit 2d30c12

Browse files
author
Joel Collins
committed
Updated examples
1 parent a0ec226 commit 2d30c12

File tree

3 files changed

+25
-145
lines changed

3 files changed

+25
-145
lines changed

examples/nested_thing.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from labthings.server.quick import create_app
77
from labthings.server.decorators import ThingProperty, PropertySchema
8-
from labthings.server.view import View
8+
from labthings.server.view import PropertyView
99
from labthings.server.find import find_component
1010
from labthings.server.schema import Schema
1111
from labthings.server import fields
@@ -64,19 +64,15 @@ class MyComponentSchema(Schema):
6464
"""
6565

6666

67-
# Register this view as a Thing Property
68-
@ThingProperty
69-
# Define the data we're going to output (get), and what to expect in (post)
70-
@PropertySchema(
71-
fields.Integer(
67+
class DenoiseProperty(PropertyView):
68+
69+
schema = fields.Integer(
7270
required=True,
7371
example=200,
7472
minimum=100,
7573
maximum=500,
7674
description="Value of magic_denoise",
7775
)
78-
)
79-
class DenoiseProperty(View):
8076

8177
# Main function to handle GET requests (read)
8278
def get(self):
@@ -104,10 +100,11 @@ def post(self, new_property_value):
104100
"""
105101

106102

107-
@ThingProperty
108-
@PropertySchema(MyComponentSchema())
109-
class MyComponentProperty(View):
103+
class MyComponentProperty(PropertyView):
110104
# Main function to handle GET requests
105+
106+
schema = MyComponentSchema()
107+
111108
def get(self):
112109
"""Show the current data value"""
113110

examples/properties_dictionary.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

examples/simple_extensions.py

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33
import logging
44

55
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
157
from labthings.server.find import find_component
168
from labthings.server import fields
179
from labthings.core.utilities import path_relative_to
@@ -28,25 +20,16 @@
2820
"""
2921

3022

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+
}
4931

32+
def post(self, args):
5033
# Find our attached component
5134
my_component = find_component("org.labthings.example.mycomponent")
5235

@@ -114,17 +97,15 @@ def data(self):
11497
"""
11598

11699

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(
120103
required=True,
121104
example=200,
122105
minimum=100,
123106
maximum=500,
124107
description="Value of magic_denoise",
125108
)
126-
)
127-
class DenoiseProperty(View):
128109

129110
# Main function to handle GET requests (read)
130111
def get(self):
@@ -152,9 +133,10 @@ def post(self, new_property_value):
152133
"""
153134

154135

155-
@ThingProperty
156-
@PropertySchema(fields.List(fields.Float()))
157-
class QuickDataProperty(View):
136+
class QuickDataProperty(PropertyView):
137+
138+
schema = fields.List(fields.Float())
139+
158140
# Main function to handle GET requests
159141
def get(self):
160142
"""Show the current data value"""

0 commit comments

Comments
 (0)