Skip to content

Commit

Permalink
Moved simple property to class-level PropertySchema
Browse files Browse the repository at this point in the history
  • Loading branch information
jtc42 committed Jan 18, 2020
1 parent 0adb401 commit 7c94278
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions examples/simple_thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from labthings.server.decorators import (
ThingAction,
ThingProperty,
PropertySchema,
use_args,
use_body,
marshal_task,
Expand Down Expand Up @@ -67,28 +68,27 @@ def average_data(self, n: int):
"""


@ThingProperty
@ThingProperty # Register this view as a Thing Property
@PropertySchema( # Define the data we're going to output (get), and what to expect in (post)
fields.Integer(
required=True,
example=200,
minimum=100,
maximum=500,
description="Value of magic_denoise",
)
)
class DenoiseProperty(View):

# Output will be a single integer
@marshal_with(fields.Integer(example=200))
# Main function to handle GET requests
# Main function to handle GET requests (read)
def get(self):
"""Show the current magic_denoise value"""

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

# Expect a single integer in the request body. Pass to post function as argument.
@use_body(
fields.Integer(
required=True, example=200, description="New value for magic_denoise"
)
)
# Output will be a single integer
@marshal_with(fields.Integer(example=200))
# Main function to handle POST requests
# Main function to handle POST requests (write)
def post(self, body):
"""Change the current magic_denoise value"""

Expand Down

0 comments on commit 7c94278

Please sign in to comment.