Moved API from action to property view

This commit is contained in:
samuelmcdermott 2020-10-13 12:39:17 +01:00
parent e886e9db28
commit 86d866c5f9
5 changed files with 30 additions and 23 deletions

View file

@ -129,6 +129,9 @@ labthing.add_view(
)
labthing.add_root_link(views.ConfigurationProperty, "instrumentConfiguration")
# Attach stage resources
labthing.add_view(views.StageTypeProperty, "/properties/stage/type")
# Attach streams resources
labthing.add_view(views.MjpegStream, f"/streams/mjpeg")

View file

@ -2,3 +2,4 @@ from .actions import enabled_root_actions
from .captures import *
from .instrument import *
from .streams import *
from .stage import *

View file

@ -39,11 +39,6 @@ _actions = {
"view_class": stage.ZeroStageAPI,
"conditions": True,
},
"setStage": {
"rule" : "/stage/type/",
"view_class": stage.StageTypeAPI,
"conditions": True,
},
"shutdown": {
"rule": "/system/shutdown/",
"view_class": system.ShutdownAPI,

View file

@ -66,22 +66,4 @@ class ZeroStageAPI(ActionView):
# TODO: Make schema for microscope state
return microscope.state["stage"]
class StageTypeAPI(ActionView):
args = {
"stage_type": fields.String(missing = None, example = "SangaStage", description = "The stage geometry [SangaStage, SangaDeltaStage]")
}
def post(self,args):
"""
Set the stage geometry.
"""
microscope = find_component("org.openflexure.microscope")
microscope.set_stage(stage_type=args.get("stage_type"))
return {"stage_type": microscope.configuration["stage"]["type"]}
def get(self):
"""
Get the stage geometry.
"""
microscope = find_component("org.openflexure.microscope")
return {"stage_type": microscope.configuration["stage"]["type"]}

View file

@ -0,0 +1,26 @@
from labthings import find_component, fields, schema
from labthings.views import PropertyView
import logging
class StageTypeProperty(PropertyView):
"""The type of the stage"""
def get(self):
"""
Get the stage geometry.
"""
microscope = find_component("org.openflexure.microscope")
return microscope.configuration['stage']['type']
schema = fields.String(missing=None, example="SangaStage", description="The stage geometry [SangaStage, SangaDeltaStage]")
def put(self,stage_type):
"""
Set the stage geometry.
"""
microscope = find_component("org.openflexure.microscope")
microscope.set_stage(stage_type=stage_type)
return microscope.configuration["stage"]["type"]