From 86d866c5f9e3361465719f6402ef00a625249f8c Mon Sep 17 00:00:00 2001 From: samuelmcdermott Date: Tue, 13 Oct 2020 12:39:17 +0100 Subject: [PATCH] Moved API from action to property view --- openflexure_microscope/api/app.py | 3 +++ .../api/v2/views/__init__.py | 1 + .../api/v2/views/actions/__init__.py | 5 ---- .../api/v2/views/actions/stage.py | 18 ------------- openflexure_microscope/api/v2/views/stage.py | 26 +++++++++++++++++++ 5 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 openflexure_microscope/api/v2/views/stage.py diff --git a/openflexure_microscope/api/app.py b/openflexure_microscope/api/app.py index 7e77a757..5861804f 100644 --- a/openflexure_microscope/api/app.py +++ b/openflexure_microscope/api/app.py @@ -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") diff --git a/openflexure_microscope/api/v2/views/__init__.py b/openflexure_microscope/api/v2/views/__init__.py index 3c1fae87..ebfae436 100644 --- a/openflexure_microscope/api/v2/views/__init__.py +++ b/openflexure_microscope/api/v2/views/__init__.py @@ -2,3 +2,4 @@ from .actions import enabled_root_actions from .captures import * from .instrument import * from .streams import * +from .stage import * diff --git a/openflexure_microscope/api/v2/views/actions/__init__.py b/openflexure_microscope/api/v2/views/actions/__init__.py index 9a5e08d2..1c26e31a 100644 --- a/openflexure_microscope/api/v2/views/actions/__init__.py +++ b/openflexure_microscope/api/v2/views/actions/__init__.py @@ -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, diff --git a/openflexure_microscope/api/v2/views/actions/stage.py b/openflexure_microscope/api/v2/views/actions/stage.py index 525a1d5b..af7f3c6d 100644 --- a/openflexure_microscope/api/v2/views/actions/stage.py +++ b/openflexure_microscope/api/v2/views/actions/stage.py @@ -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"]} diff --git a/openflexure_microscope/api/v2/views/stage.py b/openflexure_microscope/api/v2/views/stage.py new file mode 100644 index 00000000..3ecd7ddd --- /dev/null +++ b/openflexure_microscope/api/v2/views/stage.py @@ -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"] +