Skip to content

Commit ee8a5e2

Browse files
authored
Do not propagate DRVL and DRVH to in type records in CA transport (#185)
1 parent ff0be1d commit ee8a5e2

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

src/fastcs/transport/epics/ca/ioc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def _make_record(
187187
)
188188

189189
def datatype_updater(datatype: DataType):
190-
for name, value in record_metadata_from_datatype(datatype).items():
190+
for name, value in record_metadata_from_datatype(datatype, out_record).items():
191191
record.set_field(name, value)
192192

193193
attribute.add_update_datatype_callback(datatype_updater)

src/fastcs/transport/epics/ca/util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def record_metadata_from_datatype(
6262
if field in DATATYPE_FIELD_TO_RECORD_FIELD
6363
}
6464

65+
if not out_record:
66+
# in type records don't have DRVL/DRVH fields
67+
arguments.pop("DRVL", None)
68+
arguments.pop("DRVH", None)
69+
6570
match datatype:
6671
case Waveform():
6772
if len(datatype.shape) != 1:

tests/transport/epics/ca/test_softioc.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def test_make_output_record(
181181
pv = "PV"
182182
_make_record(pv, attribute, on_update=update, out_record=True)
183183

184-
kwargs.update(record_metadata_from_datatype(attribute.datatype))
184+
kwargs.update(record_metadata_from_datatype(attribute.datatype, out_record=True))
185185
kwargs.update(record_metadata_from_attribute(attribute))
186186
kwargs.update({"always_update": True, "on_update": update})
187187

@@ -266,7 +266,8 @@ def test_ioc(mocker: MockerFixture, epics_controller_api: ControllerAPI):
266266
epics_controller_api.attributes["read_write_float"]
267267
),
268268
**record_metadata_from_datatype(
269-
epics_controller_api.attributes["read_write_float"].datatype
269+
epics_controller_api.attributes["read_write_float"].datatype,
270+
out_record=True,
270271
),
271272
)
272273
builder.longIn.assert_any_call(
@@ -286,7 +287,7 @@ def test_ioc(mocker: MockerFixture, epics_controller_api: ControllerAPI):
286287
epics_controller_api.attributes["read_write_int"]
287288
),
288289
**record_metadata_from_datatype(
289-
epics_controller_api.attributes["read_write_int"].datatype
290+
epics_controller_api.attributes["read_write_int"].datatype, out_record=True
290291
),
291292
)
292293
builder.mbbIn.assert_called_once_with(
@@ -302,7 +303,7 @@ def test_ioc(mocker: MockerFixture, epics_controller_api: ControllerAPI):
302303
on_update=mocker.ANY,
303304
**record_metadata_from_attribute(epics_controller_api.attributes["enum"]),
304305
**record_metadata_from_datatype(
305-
epics_controller_api.attributes["enum"].datatype
306+
epics_controller_api.attributes["enum"].datatype, out_record=True
306307
),
307308
)
308309
builder.boolOut.assert_called_once_with(
@@ -311,7 +312,7 @@ def test_ioc(mocker: MockerFixture, epics_controller_api: ControllerAPI):
311312
on_update=mocker.ANY,
312313
**record_metadata_from_attribute(epics_controller_api.attributes["write_bool"]),
313314
**record_metadata_from_datatype(
314-
epics_controller_api.attributes["write_bool"].datatype
315+
epics_controller_api.attributes["write_bool"].datatype, out_record=True
315316
),
316317
)
317318
ioc_builder.Action.assert_any_call(
@@ -452,7 +453,8 @@ def test_long_pv_names_discarded(mocker: MockerFixture):
452453
always_update=True,
453454
on_update=mocker.ANY,
454455
**record_metadata_from_datatype(
455-
long_name_controller_api.attributes["attr_rw_short_name"].datatype
456+
long_name_controller_api.attributes["attr_rw_short_name"].datatype,
457+
out_record=True,
456458
),
457459
**record_metadata_from_attribute(
458460
long_name_controller_api.attributes["attr_rw_short_name"]
@@ -528,9 +530,9 @@ def test_update_datatype(mocker: MockerFixture):
528530
**record_metadata_from_datatype(attr_r.datatype),
529531
)
530532
record_r.set_field.assert_not_called()
531-
attr_r.update_datatype(Int(units="m", min=-3))
533+
attr_r.update_datatype(Int(units="m", min_alarm=-3))
532534
record_r.set_field.assert_any_call("EGU", "m")
533-
record_r.set_field.assert_any_call("DRVL", -3)
535+
record_r.set_field.assert_any_call("LOPR", -3)
534536

535537
with pytest.raises(
536538
ValueError,
@@ -539,16 +541,17 @@ def test_update_datatype(mocker: MockerFixture):
539541
attr_r.update_datatype(String()) # type: ignore
540542

541543
attr_w = AttrW(Int())
542-
record_w = _make_record(pv_name, attr_w, on_update=mocker.ANY)
544+
record_w = _make_record(pv_name, attr_w, on_update=mocker.ANY, out_record=True)
543545

544546
builder.longIn.assert_called_once_with(
545547
pv_name,
546548
**record_metadata_from_attribute(attr_w),
547549
**record_metadata_from_datatype(attr_w.datatype),
548550
)
549551
record_w.set_field.assert_not_called()
550-
attr_w.update_datatype(Int(units="m", min=-3))
552+
attr_w.update_datatype(Int(units="m", min_alarm=-1, min=-3))
551553
record_w.set_field.assert_any_call("EGU", "m")
554+
record_w.set_field.assert_any_call("LOPR", -1)
552555
record_w.set_field.assert_any_call("DRVL", -3)
553556

554557
with pytest.raises(

tests/transport/epics/ca/test_util.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
builder_callable_from_attribute,
1010
cast_from_epics_type,
1111
cast_to_epics_type,
12+
record_metadata_from_datatype,
1213
)
1314

1415

@@ -148,3 +149,18 @@ def test_builder_callable_enum_types(datatype, in_record, out_record):
148149
attr = AttrRW(datatype)
149150
assert builder_callable_from_attribute(attr, False) == out_record
150151
assert builder_callable_from_attribute(attr, True) == in_record
152+
153+
154+
def test_drive_metadata_from_datatype():
155+
dtype = Float(units="mm", min=-10.0, max=10.0, min_alarm=-5, max_alarm=5, prec=3)
156+
out_arguments = record_metadata_from_datatype(dtype, True)
157+
assert out_arguments == {
158+
"DRVH": 10.0,
159+
"DRVL": -10.0,
160+
"EGU": "mm",
161+
"HOPR": 5,
162+
"LOPR": -5,
163+
"PREC": 3,
164+
}
165+
in_arguments = record_metadata_from_datatype(dtype, False)
166+
assert in_arguments == {"EGU": "mm", "HOPR": 5, "LOPR": -5, "PREC": 3}

0 commit comments

Comments
 (0)