Skip to content

Commit

Permalink
Update to pvi 0.8.1
Browse files Browse the repository at this point in the history
Update to pass PV prefix into EPICS backend so that it can
be included on Signals.
  • Loading branch information
GDYendell committed Apr 11, 2024
1 parent 9ae4f7a commit b169450
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = "Control system agnostic framework for building Device support in
dependencies = [
"numpy",
"pydantic",
"pvi~=0.7.1",
"pvi~=0.8.1",
"softioc",
]
dynamic = ["version"]
Expand Down
7 changes: 4 additions & 3 deletions src/fastcs/backends/epics/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@


class EpicsBackend:
def __init__(self, mapping: Mapping):
def __init__(self, mapping: Mapping, pv_prefix: str = "MY-DEVICE-PREFIX"):
self._mapping = mapping
self._pv_prefix = pv_prefix

Check warning on line 11 in src/fastcs/backends/epics/backend.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/backend.py#L11

Added line #L11 was not covered by tests

def create_docs(self, options: EpicsDocsOptions | None = None) -> None:
docs = EpicsDocs(self._mapping)
docs.create_docs(options)

def create_gui(self, options: EpicsGUIOptions | None = None) -> None:
gui = EpicsGUI(self._mapping)
gui = EpicsGUI(self._mapping, self._pv_prefix)

Check warning on line 18 in src/fastcs/backends/epics/backend.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/backend.py#L18

Added line #L18 was not covered by tests
gui.create_gui(options)

def get_ioc(self) -> EpicsIOC:
return EpicsIOC(self._mapping)
return EpicsIOC(self._mapping, self._pv_prefix)

Check warning on line 22 in src/fastcs/backends/epics/backend.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/backend.py#L22

Added line #L22 was not covered by tests
50 changes: 26 additions & 24 deletions src/fastcs/backends/epics/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pvi._format.dls import DLSFormatter
from pvi.device import (
LED,
CheckBox,
ButtonPanel,
Component,
Device,
Grid,
Expand All @@ -19,6 +19,7 @@
TextFormat,
TextRead,
TextWrite,
ToggleButton,
Tree,
WriteWidget,
)
Expand All @@ -42,18 +43,16 @@ class EpicsGUIOptions:


class EpicsGUI:
def __init__(self, mapping: Mapping) -> None:
def __init__(self, mapping: Mapping, pv_prefix: str) -> None:
self._mapping = mapping
self._pv_prefix = pv_prefix

Check warning on line 48 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L48

Added line #L48 was not covered by tests

@staticmethod
def _get_pv(attr_path: str, name: str):
def _get_pv(self, attr_path: str, name: str):
if attr_path:
attr_path = ":" + attr_path
attr_path += ":"

pv = attr_path.upper() + name.title().replace("_", "")

return pv
return f"{self._pv_prefix}{attr_path.upper()}{name.title().replace('_', '')}"

Check warning on line 55 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L55

Added line #L55 was not covered by tests

@staticmethod
def _get_read_widget(datatype: DataType) -> ReadWidget:
Expand All @@ -71,43 +70,46 @@ def _get_read_widget(datatype: DataType) -> ReadWidget:
def _get_write_widget(datatype: DataType) -> WriteWidget:
match datatype:
case Bool():
return CheckBox()
return ToggleButton()

Check warning on line 73 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L73

Added line #L73 was not covered by tests
case Int() | Float():
return TextWrite()
case String():
return TextWrite(format=TextFormat.string)
case _:
raise FastCSException(f"Unsupported type {type(datatype)}: {datatype}")

@classmethod
def _get_attribute_component(cls, attr_path: str, name: str, attribute: Attribute):
pv = cls._get_pv(attr_path, name)
def _get_attribute_component(self, attr_path: str, name: str, attribute: Attribute):
pv = self._get_pv(attr_path, name)

Check warning on line 82 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L82

Added line #L82 was not covered by tests
name = name.title().replace("_", "")

match attribute:
case AttrRW():
read_widget = cls._get_read_widget(attribute.datatype)
write_widget = cls._get_write_widget(attribute.datatype)
read_widget = self._get_read_widget(attribute.datatype)
write_widget = self._get_write_widget(attribute.datatype)

Check warning on line 88 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L87-L88

Added lines #L87 - L88 were not covered by tests
return SignalRW(
name=name,
pv=pv,
widget=write_widget,
write_pv=pv,
write_widget=write_widget,
read_pv=pv + "_RBV",
read_widget=read_widget,
)
case AttrR():
read_widget = cls._get_read_widget(attribute.datatype)
return SignalR(name=name, pv=pv, widget=read_widget)
read_widget = self._get_read_widget(attribute.datatype)
return SignalR(name=name, read_pv=pv, read_widget=read_widget)

Check warning on line 98 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L97-L98

Added lines #L97 - L98 were not covered by tests
case AttrW():
write_widget = cls._get_write_widget(attribute.datatype)
return SignalW(name=name, pv=pv, widget=TextWrite())
write_widget = self._get_write_widget(attribute.datatype)
return SignalW(name=name, write_pv=pv, write_widget=TextWrite())

Check warning on line 101 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L100-L101

Added lines #L100 - L101 were not covered by tests

@classmethod
def _get_command_component(cls, attr_path: str, name: str):
pv = cls._get_pv(attr_path, name)
def _get_command_component(self, attr_path: str, name: str):
pv = self._get_pv(attr_path, name)

Check warning on line 104 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L104

Added line #L104 was not covered by tests
name = name.title().replace("_", "")

return SignalX(name=name, pv=pv, value="1")
return SignalX(

Check warning on line 107 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L107

Added line #L107 was not covered by tests
name=name,
write_pv=pv,
value="1",
write_widget=ButtonPanel(actions={name: "1"}),
)

def create_gui(self, options: EpicsGUIOptions | None = None) -> None:
if options is None:
Expand Down Expand Up @@ -136,7 +138,7 @@ def create_gui(self, options: EpicsGUIOptions | None = None) -> None:

device = Device(label="Simple Device", children=components)

formatter.format(device, "MY-DEVICE-PREFIX", options.output_path)
formatter.format(device, options.output_path)

Check warning on line 141 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L141

Added line #L141 was not covered by tests

def extract_mapping_components(self, mapping: SingleMapping) -> list[Component]:
components: Tree[Component] = []
Expand Down
5 changes: 3 additions & 2 deletions src/fastcs/backends/epics/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ def _create_and_link_command_pvs(mapping: Mapping) -> None:


class EpicsIOC:
def __init__(self, mapping: Mapping):
def __init__(self, mapping: Mapping, pv_prefix: str):
self._mapping = mapping
self._pv_prefix = pv_prefix

Check warning on line 118 in src/fastcs/backends/epics/ioc.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/ioc.py#L118

Added line #L118 was not covered by tests

def run(self, options: EpicsIOCOptions | None = None) -> None:
if options is None:
Expand All @@ -125,7 +126,7 @@ def run(self, options: EpicsIOCOptions | None = None) -> None:
backend = Backend(self._mapping, dispatcher.loop)

# Set the record prefix
builder.SetDeviceName("MY-DEVICE-PREFIX")
builder.SetDeviceName(self._pv_prefix)

Check warning on line 129 in src/fastcs/backends/epics/ioc.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/ioc.py#L129

Added line #L129 was not covered by tests

_create_and_link_attribute_pvs(self._mapping)

Expand Down

0 comments on commit b169450

Please sign in to comment.