Skip to content

Commit 7c94278

Browse files
committed
Moved simple property to class-level PropertySchema
1 parent 0adb401 commit 7c94278

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

examples/simple_thing.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from labthings.server.decorators import (
77
ThingAction,
88
ThingProperty,
9+
PropertySchema,
910
use_args,
1011
use_body,
1112
marshal_task,
@@ -67,28 +68,27 @@ def average_data(self, n: int):
6768
"""
6869

6970

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+
)
7181
class DenoiseProperty(View):
7282

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)
7684
def get(self):
7785
"""Show the current magic_denoise value"""
7886

7987
# When a GET request is made, we'll find our attached component
8088
my_component = find_component("org.labthings.example.mycomponent")
8189
return my_component.magic_denoise
8290

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)
9292
def post(self, body):
9393
"""Change the current magic_denoise value"""
9494

0 commit comments

Comments
 (0)