Skip to content

Commit 29ca056

Browse files
author
Joel Collins
committed
Added op annotations to example
1 parent 89ce0e9 commit 29ca056

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

examples/simple_thing.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import logging
66
import atexit
77

8-
from labthings.server.quick import create_app, semantics, find_component, fields
9-
from labthings.views import ActionView, PropertyView
8+
from labthings import create_app, semantics, find_component, fields
9+
from labthings.views import ActionView, PropertyView, op
1010

1111

1212
"""
@@ -62,11 +62,13 @@ def average_data(self, n: int):
6262
class DenoiseProperty(PropertyView):
6363
"""Value of magic_denoise"""
6464

65+
@op.readproperty
6566
def get(self):
6667
# When a GET request is made, we'll find our attached component
6768
my_component = find_component("org.labthings.example.mycomponent")
6869
return my_component.magic_denoise
6970

71+
@op.writeproperty
7072
def put(self, new_property_value):
7173
# Find our attached component
7274
my_component = find_component("org.labthings.example.mycomponent")
@@ -88,6 +90,7 @@ class QuickDataProperty(PropertyView):
8890
# Marshal the response as a list of floats
8991
schema = fields.List(fields.Float())
9092

93+
@op.readproperty
9194
def get(self):
9295
# Find our attached component
9396
my_component = find_component("org.labthings.example.mycomponent")
@@ -111,6 +114,7 @@ class MeasurementAction(ActionView):
111114
schema = fields.List(fields.Number)
112115

113116
# Main function to handle POST requests
117+
@op.invokeaction
114118
def post(self, args):
115119
"""Start an averaged measurement"""
116120

@@ -134,7 +138,6 @@ def cleanup():
134138
# Create LabThings Flask app
135139
app, labthing = create_app(
136140
__name__,
137-
prefix="/api",
138141
title=f"My Lab Device API",
139142
description="Test LabThing-based API",
140143
version="0.1.0",

0 commit comments

Comments
 (0)