Skip to content

Commit 899f055

Browse files
author
Joel Collins
committed
Updated examples
1 parent 667c848 commit 899f055

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

examples/builder.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import logging
88

99
from labthings.server.quick import create_app
10+
from labthings.server import fields
1011

1112
from components.pdf_component import PdfComponent
1213

@@ -33,21 +34,33 @@
3334
"magic_denoise", # Objects attribute name
3435
"/denoise", # URL to bind the property to
3536
description="A magic denoise property",
37+
schema=fields.Int(example=200), # Property should be integer formatted
3638
)
3739

3840
labthing.build_property(
3941
my_component, # Python object
4042
"magic_dictionary", # Objects attribute name
4143
"/dictionary", # URL to bind the property to
4244
description="A big dictionary of little properties",
45+
schema={ # Property is a dictionary, with these value types
46+
"voltage": fields.Int(),
47+
"volume": fields.List(fields.Int()),
48+
"mode": fields.String(),
49+
"light_on": fields.Bool(),
50+
"user": {"name": fields.String(), "id": fields.Int()},
51+
"bytes": fields.Bytes(),
52+
},
4353
)
4454

4555
labthing.build_action(
4656
my_component.average_data, # Python function
4757
"/average", # URL to bind the action to
4858
description="Take an averaged measurement",
4959
safe=True, # Is the state of the Thing unchanged by calling the action?
50-
idempotent=True, # Can the action be called repeatedly with the same result?
60+
idempotent=True, # Can the action be called repeatedly with the same result?,
61+
args={ # How do we convert from the request input to function arguments?
62+
"n": fields.Int(description="Number of averages to take", example=5, default=5)
63+
},
5164
)
5265

5366

examples/components/pdf_component.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import math
33
import time
44

5-
from typing import List
6-
75
"""
86
Class for our lab component functionality. This could include serial communication,
97
equipment API calls, network requests, or a "virtual" device as seen here.
@@ -41,7 +39,7 @@ def data(self):
4139
"""Return a 1D data trace."""
4240
return [self.noisy_pdf(x) for x in self.x_range]
4341

44-
def average_data(self, n: int, optlist: List[int] = [1, 2, 3]):
42+
def average_data(self, n: int):
4543
"""Average n-sets of data. Emulates a measurement that may take a while."""
4644
summed_data = self.data
4745

0 commit comments

Comments
 (0)