Skip to content

Commit

Permalink
Added op annotations to example
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Jul 29, 2020
1 parent 89ce0e9 commit 29ca056
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/simple_thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import logging
import atexit

from labthings.server.quick import create_app, semantics, find_component, fields
from labthings.views import ActionView, PropertyView
from labthings import create_app, semantics, find_component, fields
from labthings.views import ActionView, PropertyView, op


"""
Expand Down Expand Up @@ -62,11 +62,13 @@ def average_data(self, n: int):
class DenoiseProperty(PropertyView):
"""Value of magic_denoise"""

@op.readproperty
def get(self):
# 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

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

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

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

Expand All @@ -134,7 +138,6 @@ def cleanup():
# Create LabThings Flask app
app, labthing = create_app(
__name__,
prefix="/api",
title=f"My Lab Device API",
description="Test LabThing-based API",
version="0.1.0",
Expand Down

0 comments on commit 29ca056

Please sign in to comment.