-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor Part to separate __init__ and Method.call_function, and add …
…cadoublepart
- Loading branch information
Showing
8 changed files
with
111 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
from malcolm.core.loggable import Loggable | ||
|
||
class Part(Loggable): | ||
|
||
def __init__(self, name, process, block): | ||
class Part(Loggable): | ||
def __init__(self, name, process, block, params): | ||
self.process = process | ||
self.block = block | ||
self.name = name | ||
self.set_logger_name("%s.%s" % (block, name)) | ||
self._call_setup(params) | ||
|
||
def _call_setup(self, params): | ||
# Expect setup() implementation to be decorated with @takes so it will | ||
# have a Method attached to it. Calling the Method will fill in defaults | ||
if not hasattr(self.setup, "Method"): | ||
raise NotImplementedError() | ||
# unfortunately thi has to be done now rather than at @takes decorate | ||
# time so it gets the bound method rather than the unbound function | ||
self.setup.Method.set_function(self.setup) | ||
self.setup.Method.call_function(params) | ||
|
||
def setup(selfself, params): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import numpy as np | ||
|
||
from malcolm.parts.ca.capart import CAPart | ||
from malcolm.metas.numbermeta import NumberMeta | ||
from malcolm.metas.stringmeta import StringMeta | ||
from malcolm.core.method import takes, returns, REQUIRED | ||
|
||
|
||
class CADoublePart(CAPart): | ||
""" Defines a part which connects via channel access to a DBR_DOUBLE pv""" | ||
|
||
@takes( | ||
StringMeta("name", "name of created attribute"), REQUIRED, | ||
StringMeta("description", "desc of created attribute"), REQUIRED, | ||
StringMeta("pv", "full pv of demand and default for rbv"), REQUIRED, | ||
StringMeta("rbv", "override for rbv"), None, | ||
StringMeta("rbv_suff", "set rbv ro pv + rbv_suff"), None, | ||
) | ||
def setup(self, params): | ||
""" setup is called by the base class Part.__init__ via self.Method. | ||
self. Method is defined by the @takes decorator above. | ||
It defines an attribute to publish the pv via Malcolm | ||
Args: | ||
params(OrderedDict): parameters described in @takes | ||
""" | ||
meta = NumberMeta("meta", params.description, np.float64) | ||
self.create_attribute(meta, params.pv, rbv=params.rbv, | ||
rbv_suff=params.rbv_suff) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
import sys | ||
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..")) | ||
import setup_malcolm_paths | ||
|
||
from malcolm.parts.ca.cadoublepart import CADoublePart | ||
|
||
import unittest | ||
from mock import Mock, patch, ANY | ||
|
||
|
||
class TestCADoublePart(unittest.TestCase): | ||
|
||
def test_init(self): | ||
CADoublePart.create_attribute = Mock() | ||
# reading yaml will result in a dictionary such as:- | ||
exposure_pv={"name": "exposure", | ||
"description": "shutter time", | ||
"pv": "BL00I-EA-DET-01:AcquireTime", | ||
"rbv_suff": "_RBV"} | ||
p = CADoublePart("exp", Mock(), Mock(), exposure_pv) | ||
|
||
# TODO: add above exposure_pv params | ||
p.create_attribute.assert_called_once_with(ANY, | ||
"BL00I-EA-DET-01:AcquireTime", rbv=None, rbv_suff='_RBV') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters