Skip to content

Commit

Permalink
don't double count describe
Browse files Browse the repository at this point in the history
  • Loading branch information
untzag committed Aug 14, 2023
1 parent e79a544 commit 5a9e29e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
6 changes: 3 additions & 3 deletions tests/is_discrete/test_is_discrete.py
Expand Up @@ -15,14 +15,14 @@
def test_identifier_is_in_read():
d = yaqc_bluesky.Device(38383)
read_keys = list(d.read().keys())
assert f"{d.name}_identifier" in read_keys
assert f"{d.name}_position_identifier" in read_keys


@testing.run_daemon_entry_point("fake-discrete-hardware", config=config)
def test_identifier_is_in_describe():
d = yaqc_bluesky.Device(38383)
describe_keys = list(d.describe().keys())
assert f"{d.name}_identifier" in describe_keys
assert f"{d.name}_position_identifier" in describe_keys


@testing.run_daemon_entry_point("fake-discrete-hardware", config=config)
Expand All @@ -48,7 +48,7 @@ def test_set_read():
d.set(470)
time.sleep(1)
out = d.read()
assert out[f"{d.name}_identifier"]["value"] == "blue"
assert out[f"{d.name}_position_identifier"]["value"] == "blue"
d.set("green")
time.sleep(1)
out = d.read()
Expand Down
2 changes: 1 addition & 1 deletion yaqc_bluesky/_base.py
Expand Up @@ -25,7 +25,7 @@ def __init__(self, yaq_client, *, name=None):
for key, prop in self.yaq_client.properties.items():
if key in ["destination", "position"]:
continue
if prop.type not in ["double"]:
if prop.type not in ["double", "string"]:
continue
self.children.append(PropertyDevice(self, key))
if not hasattr(self, key): # don't overwrite please
Expand Down
16 changes: 0 additions & 16 deletions yaqc_bluesky/_is_discrete.py
Expand Up @@ -7,22 +7,6 @@

class IsDiscrete(HasPosition):

def _describe(self, out):
out = super()._describe(out)
meta = OrderedDict()
meta["shape"] = []
meta["dtype"] = "string"
out[f"{self.name}_identifier"] = meta
return out

def _read(self, out, ts) -> OrderedDict:
out = super()._read(out, ts)
identifier = dict()
identifier["value"] = self.yaq_client.get_identifier()
identifier["timestamp"] = ts
out[f"{self.name}_identifier"] = identifier
return out

def set(self, value):
try:
self.yaq_client.set_position(value)
Expand Down
11 changes: 9 additions & 2 deletions yaqc_bluesky/_property.py
Expand Up @@ -15,6 +15,13 @@ def __init__(self, parent, name):
self.parent = parent
self.name = name
self._yaq_property = self.parent.yaq_client.properties[self.name]
if self._yaq_property.type in ["int", "float", "double"]:
self._dtype = "number"
elif self._yaq_property.type == "string":
self._dtype = "string"
else:
self._dtype = "array"

self._setpoint = float("nan")

def set(self, value) -> Status:
Expand All @@ -30,10 +37,10 @@ def set(self, value) -> Status:

def describe(self) -> dict:
out = dict()
out[f"{self.parent.name}_{self.name}_readback"] = {"dtype": "number", "shape": [], "source": f"yaq:{self.parent.yaq_name}"
out[f"{self.parent.name}_{self.name}_readback"] = {"dtype": self._dtype, "shape": [], "source": f"yaq:{self.parent.yaq_name}"
}
if self._yaq_property._property["getter"]:
out[f"{self.parent.name}_{self.name}_setpoint"] = {"dtype": "number", "shape": [], "source": f"yaq:{self.parent.yaq_name}"}
out[f"{self.parent.name}_{self.name}_setpoint"] = {"dtype": self._dtype, "shape": [], "source": f"yaq:{self.parent.yaq_name}"}
return out

def read(self) -> dict:
Expand Down

0 comments on commit 5a9e29e

Please sign in to comment.