Commit 86d866c5 authored by Samuel McDermott's avatar Samuel McDermott
Browse files

Moved API from action to property view

parent e886e9db
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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")
+1 −0
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@ from .actions import enabled_root_actions
from .captures import *
from .instrument import *
from .streams import *
from .stage import *
+0 −5
Original line number Diff line number Diff line
@@ -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,
+0 −18
Original line number Diff line number Diff line
@@ -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"]}
+26 −0
Original line number Diff line number Diff line
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"]