Skip to content

Commit

Permalink
Merge pull request #112 from epics-containers/signalr-default-widget
Browse files Browse the repository at this point in the history
Fix validation of default SignalR.read_widget
  • Loading branch information
GDYendell authored Mar 28, 2024
2 parents 96de431 + f0688af commit 21cb12e
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/pvi/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,12 @@ class SignalR(Signal):

read_pv: str = Field(description="PV to use for readback")
read_widget: ReadWidgetUnion = Field(
None, description="Widget to use for display. `TextRead` will be used if unset."
None,
description="Widget to use for display. `TextRead` will be used if unset.",
validate_default=True,
)

@field_validator("read_widget")
@field_validator("read_widget", mode="before")
@classmethod
def _validate_read_widget(cls, read_widget: Any):
if read_widget is None:
Expand Down
25 changes: 25 additions & 0 deletions tests/format/input/signal_default_widgets.pvi.device.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# yaml-language-server: $schema=../../../schemas/pvi.device.schema.json

label: label
children:

- type: SignalR
name: Read
read_pv: Read

- type: SignalW
name: Write
write_pv: Write

- type: SignalRW
name: ReadWriteSingle
write_pv: ReadWriteSingle

- type: SignalRW
name: ReadWrite
write_pv: ReadWrite
read_pv: ReadWrite_RBV

- type: SignalX
name: Execute
write_pv: Execute
138 changes: 138 additions & 0 deletions tests/format/output/signal_default_widgets.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<display version="2.0.0">
<name>Display</name>
<x>0</x>
<y use_class="true">0</y>
<width>274</width>
<height>150</height>
<grid_step_x>4</grid_step_x>
<grid_step_y>4</grid_step_y>
<widget type="label" version="2.0.0">
<name>Title</name>
<class>TITLE</class>
<text>label</text>
<x use_class="true">0</x>
<y use_class="true">0</y>
<width>274</width>
<height>26</height>
<font use_class="true">
<font name="Header 1" family="Liberation Sans" style="BOLD" size="22.0">
</font>
</font>
<foreground_color use_class="true">
<color name="Text" red="0" green="0" blue="0">
</color>
</foreground_color>
<transparent use_class="true">true</transparent>
<horizontal_alignment>1</horizontal_alignment>
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
<text>Read</text>
<x>22</x>
<y>30</y>
<width>120</width>
<height>20</height>
</widget>
<widget type="textupdate" version="2.0.0">
<name>TextUpdate</name>
<pv_name>Read</pv_name>
<x>146</x>
<y>30</y>
<width>124</width>
<height>20</height>
<font>
<font name="Default Bold" family="Liberation Sans" style="BOLD" size="14.0">
</font>
</font>
<horizontal_alignment>1</horizontal_alignment>
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
<text>Write</text>
<x>22</x>
<y>54</y>
<width>120</width>
<height>20</height>
</widget>
<widget type="textentry" version="3.0.0">
<name>TextEntry</name>
<pv_name>Write</pv_name>
<x>146</x>
<y>54</y>
<width>124</width>
<height>20</height>
<horizontal_alignment>1</horizontal_alignment>
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
<text>Read Write Single</text>
<x>22</x>
<y>78</y>
<width>120</width>
<height>20</height>
</widget>
<widget type="textentry" version="3.0.0">
<name>TextEntry</name>
<pv_name>ReadWriteSingle</pv_name>
<x>146</x>
<y>78</y>
<width>124</width>
<height>20</height>
<horizontal_alignment>1</horizontal_alignment>
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
<text>Read Write</text>
<x>22</x>
<y>102</y>
<width>120</width>
<height>20</height>
</widget>
<widget type="textentry" version="3.0.0">
<name>TextEntry</name>
<pv_name>ReadWrite</pv_name>
<x>146</x>
<y>102</y>
<width>60</width>
<height>20</height>
<horizontal_alignment>1</horizontal_alignment>
</widget>
<widget type="textupdate" version="2.0.0">
<name>TextUpdate</name>
<pv_name>ReadWrite_RBV</pv_name>
<x>210</x>
<y>102</y>
<width>60</width>
<height>20</height>
<font>
<font name="Default Bold" family="Liberation Sans" style="BOLD" size="14.0">
</font>
</font>
<horizontal_alignment>1</horizontal_alignment>
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
<text>Execute</text>
<x>22</x>
<y>126</y>
<width>120</width>
<height>20</height>
</widget>
<widget type="action_button" version="3.0.0">
<name>WritePV</name>
<pv_name>Execute</pv_name>
<actions>
<action type="write_pv">
<pv_name>$(pv_name)</pv_name>
<value>1</value>
<description>$(name)</description>
</action>
</actions>
<text>Go</text>
<x>146</x>
<y>126</y>
<width>124</width>
<height>20</height>
<tooltip>$(actions)</tooltip>
</widget>
</display>
14 changes: 14 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ def test_format(tmp_path, helper, filename, formatter):
)


def test_signal_default_widgets(tmp_path, helper):
expected_path = HERE / "format" / "output" / "signal_default_widgets.bob"
input_path = HERE / "format" / "input"
formatter_path = input_path / "dls.bob.pvi.formatter.yaml"
helper.assert_cli_output_matches(
app,
expected_path,
"format --yaml-path " + str(input_path),
tmp_path / "signal_default_widgets.bob",
HERE / "format" / "input" / "signal_default_widgets.pvi.device.yaml",
formatter_path,
)


def test_convert(tmp_path, helper):
expected_path = HERE / "convert" / "output"
input_path = HERE / "convert" / "input"
Expand Down

0 comments on commit 21cb12e

Please sign in to comment.