Skip to content

Commit 0e06e16

Browse files
committed
added EGU options to Attributes in Int and Float
1 parent 40455e4 commit 0e06e16

File tree

3 files changed

+48
-17
lines changed

3 files changed

+48
-17
lines changed

src/fastcs/backends/epics/ioc.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,11 @@ def _get_input_record(pv: str, attribute: AttrR) -> RecordWrapper:
187187
case Bool(znam, onam):
188188
return builder.boolIn(pv, ZNAM=znam, ONAM=onam, **attribute_fields)
189189
case Int():
190-
return builder.longIn(pv, **attribute_fields)
190+
return builder.longIn(pv, EGU=attribute.datatype.units, **attribute_fields)
191191
case Float(prec):
192-
return builder.aIn(pv, PREC=prec, **attribute_fields)
192+
return builder.aIn(
193+
pv, EGU=attribute.datatype.units, PREC=prec, **attribute_fields
194+
)
193195
case String():
194196
return builder.longStringIn(pv, **attribute_fields)
195197
case _:
@@ -236,7 +238,13 @@ def _get_output_record(pv: str, attribute: AttrW, on_update: Callable) -> Any:
236238
isinstance(v, str) for v in attribute.allowed_values
237239
)
238240
state_keys = dict(zip(MBB_STATE_FIELDS, attribute.allowed_values, strict=False))
239-
return builder.mbbOut(pv, always_update=True, on_update=on_update, **state_keys, **attribute_fields)
241+
return builder.mbbOut(
242+
pv,
243+
always_update=True,
244+
on_update=on_update,
245+
**state_keys,
246+
**attribute_fields,
247+
)
240248

241249
match attribute.datatype:
242250
case Bool(znam, onam):
@@ -247,12 +255,27 @@ def _get_output_record(pv: str, attribute: AttrW, on_update: Callable) -> Any:
247255
always_update=True,
248256
on_update=on_update,
249257
)
250-
case Int():
251-
return builder.longOut(pv, always_update=True, on_update=on_update, **attribute_fields)
252-
case Float(prec):
253-
return builder.aOut(pv, always_update=True, on_update=on_update, PREC=prec, **attribute_fields)
258+
case Int(units=units):
259+
return builder.longOut(
260+
pv,
261+
always_update=True,
262+
on_update=on_update,
263+
EGU=units,
264+
**attribute_fields,
265+
)
266+
case Float(prec=prec, units=units):
267+
return builder.aOut(
268+
pv,
269+
always_update=True,
270+
on_update=on_update,
271+
EGU=units,
272+
PREC=prec,
273+
**attribute_fields,
274+
)
254275
case String():
255-
return builder.longStringOut(pv, always_update=True, on_update=on_update, **attribute_fields)
276+
return builder.longStringOut(
277+
pv, always_update=True, on_update=on_update, **attribute_fields
278+
)
256279
case _:
257280
raise FastCSException(
258281
f"Unsupported type {type(attribute.datatype)}: {attribute.datatype}"

src/fastcs/datatypes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def dtype(self) -> type[T]: # Using property due to lack of Generic ClassVars
2525
class Int(DataType[int]):
2626
"""`DataType` mapping to builtin ``int``."""
2727

28+
units: str | None = None
29+
2830
@property
2931
def dtype(self) -> type[int]:
3032
return int
@@ -35,6 +37,7 @@ class Float(DataType[float]):
3537
"""`DataType` mapping to builtin ``float``."""
3638

3739
prec: int = 2
40+
units: str | None = None
3841

3942
@property
4043
def dtype(self) -> type[float]:

tests/backends/epics/test_ioc.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,21 @@ def test_ioc(mocker: MockerFixture, mapping: Mapping):
222222

223223
# Check records are created
224224
builder.boolIn.assert_called_once_with(f"{DEVICE}:ReadBool", ZNAM="OFF", ONAM="ON")
225-
builder.longIn.assert_any_call(f"{DEVICE}:ReadInt")
226-
builder.aIn.assert_called_once_with(f"{DEVICE}:ReadWriteFloat_RBV", PREC=2)
225+
builder.longIn.assert_any_call(f"{DEVICE}:ReadInt", EGU=None)
226+
builder.aIn.assert_called_once_with(
227+
f"{DEVICE}:ReadWriteFloat_RBV", PREC=2, EGU=None
228+
)
227229
builder.aOut.assert_any_call(
228-
f"{DEVICE}:ReadWriteFloat", always_update=True, on_update=mocker.ANY, PREC=2
230+
f"{DEVICE}:ReadWriteFloat",
231+
always_update=True,
232+
on_update=mocker.ANY,
233+
PREC=2,
234+
EGU=None,
229235
)
230-
builder.longIn.assert_any_call(f"{DEVICE}:BigEnum")
231-
builder.longIn.assert_any_call(f"{DEVICE}:ReadWriteInt_RBV")
236+
builder.longIn.assert_any_call(f"{DEVICE}:BigEnum", EGU=None)
237+
builder.longIn.assert_any_call(f"{DEVICE}:ReadWriteInt_RBV", EGU=None)
232238
builder.longOut.assert_called_with(
233-
f"{DEVICE}:ReadWriteInt", always_update=True, on_update=mocker.ANY
239+
f"{DEVICE}:ReadWriteInt", always_update=True, on_update=mocker.ANY, EGU=None
234240
)
235241
builder.mbbIn.assert_called_once_with(
236242
f"{DEVICE}:StringEnum_RBV", ZRST="red", ONST="green", TWST="blue"
@@ -390,10 +396,9 @@ def test_long_pv_names_discarded(mocker: MockerFixture):
390396
f"{DEVICE}:{short_pv_name}",
391397
always_update=True,
392398
on_update=mocker.ANY,
399+
EGU=None,
393400
)
394-
builder.longIn.assert_called_once_with(
395-
f"{DEVICE}:{short_pv_name}_RBV",
396-
)
401+
builder.longIn.assert_called_once_with(f"{DEVICE}:{short_pv_name}_RBV", EGU=None)
397402

398403
long_pv_name = long_attr_name.title().replace("_", "")
399404
with pytest.raises(AssertionError):

0 commit comments

Comments
 (0)