From 7c9427854a05f04ac1f9adc835d320905b20356b Mon Sep 17 00:00:00 2001 From: jtc42 Date: Sat, 18 Jan 2020 15:24:54 +0000 Subject: [PATCH] Moved simple property to class-level PropertySchema --- examples/simple_thing.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/simple_thing.py b/examples/simple_thing.py index 18b662bb..40e47023 100644 --- a/examples/simple_thing.py +++ b/examples/simple_thing.py @@ -6,6 +6,7 @@ from labthings.server.decorators import ( ThingAction, ThingProperty, + PropertySchema, use_args, use_body, marshal_task, @@ -67,12 +68,19 @@ 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""" @@ -80,15 +88,7 @@ def get(self): 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"""