Skip to content

Commit

Permalink
cleaned up after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Jun 18, 2024
1 parent c3f3a95 commit e2a5618
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/ophyd_async/core/soft_signal_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, datatype: Union[RuntimeEnum, Enum]): # type: ignore
if issubclass(datatype, Enum):
self.choices = tuple(v.value for v in datatype)
else:
self.choices = datatype.choices
self.choices = tuple(datatype.choices)

def write_value(self, value: Union[Enum, str]) -> str:
if isinstance(value, Enum):
Expand All @@ -99,12 +99,11 @@ def write_value(self, value: Union[Enum, str]) -> str:
return value

def get_datakey(self, source: str, value, **metadata) -> DataKey:
choices = [e.value for e in self.enum_class]
return {
"source": source,
"dtype": "string",
"shape": [],
"choices": choices,
"choices": self.choices,
**metadata,
}

Expand Down
3 changes: 2 additions & 1 deletion src/ophyd_async/epics/_backend/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from enum import Enum
from typing import Dict, Optional, Tuple, Type, TypedDict

from ophyd_async.core.signal_backend import RuntimeEnum

common_meta = {
"units",
"precision",
Expand All @@ -24,7 +26,6 @@ class Limits(TypedDict):
def __bool__(self) -> bool:
return any(self.alarm, self.control, self.display, self.warning)

from ophyd_async.core.signal_backend import RuntimeEnum


def get_supported_values(
Expand Down
8 changes: 5 additions & 3 deletions tests/epics/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from aioca import CANothing, purge_channel_caches
from bluesky.protocols import DataKey, Reading

from ophyd_async.core import SignalBackend, T, get_dtype, load_from_yaml, save_to_yaml
from ophyd_async.core import SignalBackend, T, load_from_yaml, save_to_yaml
from ophyd_async.core.signal_backend import RuntimeEnum
from ophyd_async.core.utils import NotConnected
from ophyd_async.epics._backend.common import LimitPair, Limits
Expand Down Expand Up @@ -245,7 +245,10 @@ def get_dtype(suffix: str) -> str:

d = {"dtype": dtype, "shape": [len(value)] if dtype == "array" else []}
if get_internal_dtype(suffix) == "enum":
d["choices"] = [e.value for e in type(value)]
if issubclass(type(value), Enum):
d["choices"] = [e.value for e in type(value)]
else:
d["choices"] = list(value.choices)

d.update(_metadata[protocol].get(get_internal_dtype(suffix), {}))

Expand All @@ -264,7 +267,6 @@ def get_dtype(suffix: str) -> str:
(float, "float", 3.141, 43.5, {"ca", "pva"}),
(str, "str", "hello", "goodbye", {"ca", "pva"}),
(MyEnum, "enum", MyEnum.b, MyEnum.c, {"ca", "pva"}),
(RuntimeEnum["Aaa", "Bbb"], "enum", "Bbb", "Ccc", {"ca", "pva"}),
# numpy arrays of numpy types
(
npt.NDArray[np.int8],
Expand Down

0 comments on commit e2a5618

Please sign in to comment.