Skip to content

Commit 066f771

Browse files
committed
added optional description to attributes
1 parent bdab4fa commit 066f771

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/fastcs/attributes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(
5252
group: str | None = None,
5353
handler: Any = None,
5454
allowed_values: list[T] | None = None,
55+
description: str | None = None
5556
) -> None:
5657
assert (
5758
datatype.dtype in ATTRIBUTE_TYPES
@@ -61,6 +62,7 @@ def __init__(
6162
self._group = group
6263
self.enabled = True
6364
self._allowed_values: list[T] | None = allowed_values
65+
self.description = description
6466

6567
@property
6668
def datatype(self) -> DataType[T]:
@@ -93,13 +95,15 @@ def __init__(
9395
group: str | None = None,
9496
handler: Updater | None = None,
9597
allowed_values: list[T] | None = None,
98+
description: str | None = None,
9699
) -> None:
97100
super().__init__(
98101
datatype, # type: ignore
99102
access_mode,
100103
group,
101104
handler,
102105
allowed_values=allowed_values, # type: ignore
106+
description=description
103107
)
104108
self._value: T = datatype.dtype()
105109
self._update_callback: AttrCallback[T] | None = None
@@ -132,13 +136,15 @@ def __init__(
132136
group: str | None = None,
133137
handler: Sender | None = None,
134138
allowed_values: list[T] | None = None,
139+
description: str | None = None
135140
) -> None:
136141
super().__init__(
137142
datatype, # type: ignore
138143
access_mode,
139144
group,
140145
handler,
141146
allowed_values=allowed_values, # type: ignore
147+
description=description
142148
)
143149
self._process_callback: AttrCallback[T] | None = None
144150
self._write_display_callback: AttrCallback[T] | None = None
@@ -180,13 +186,15 @@ def __init__(
180186
group: str | None = None,
181187
handler: Handler | None = None,
182188
allowed_values: list[T] | None = None,
189+
description: str | None = None
183190
) -> None:
184191
super().__init__(
185192
datatype, # type: ignore
186193
access_mode,
187194
group,
188195
handler,
189196
allowed_values, # type: ignore
197+
description=description
190198
)
191199

192200
async def process(self, value: T) -> None:

src/fastcs/backends/epics/ioc.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,26 @@ async def async_record_set(value: T):
172172

173173

174174
def _get_input_record(pv: str, attribute: AttrR) -> RecordWrapper:
175+
attribute_fields = {}
176+
if attribute.description is not None:
177+
attribute_fields.update({"DESC": attribute.description})
178+
175179
if attr_is_enum(attribute):
176180
assert attribute.allowed_values is not None and all(
177181
isinstance(v, str) for v in attribute.allowed_values
178182
)
179183
state_keys = dict(zip(MBB_STATE_FIELDS, attribute.allowed_values, strict=False))
180-
return builder.mbbIn(pv, **state_keys)
184+
return builder.mbbIn(pv, **state_keys, **attribute_fields)
181185

182186
match attribute.datatype:
183187
case Bool(znam, onam):
184-
return builder.boolIn(pv, ZNAM=znam, ONAM=onam)
188+
return builder.boolIn(pv, ZNAM=znam, ONAM=onam, **attribute_fields)
185189
case Int():
186-
return builder.longIn(pv)
190+
return builder.longIn(pv, **attribute_fields)
187191
case Float(prec):
188-
return builder.aIn(pv, PREC=prec)
192+
return builder.aIn(pv, PREC=prec, **attribute_fields)
189193
case String():
190-
return builder.longStringIn(pv)
194+
return builder.longStringIn(pv, **attribute_fields)
191195
case _:
192196
raise FastCSException(
193197
f"Unsupported type {type(attribute.datatype)}: {attribute.datatype}"
@@ -224,12 +228,15 @@ async def async_write_display(value: T):
224228

225229

226230
def _get_output_record(pv: str, attribute: AttrW, on_update: Callable) -> Any:
231+
attribute_fields = {}
232+
if attribute.description is not None:
233+
attribute_fields.update({"DESC": attribute.description})
227234
if attr_is_enum(attribute):
228235
assert attribute.allowed_values is not None and all(
229236
isinstance(v, str) for v in attribute.allowed_values
230237
)
231238
state_keys = dict(zip(MBB_STATE_FIELDS, attribute.allowed_values, strict=False))
232-
return builder.mbbOut(pv, always_update=True, on_update=on_update, **state_keys)
239+
return builder.mbbOut(pv, always_update=True, on_update=on_update, **state_keys, **attribute_fields)
233240

234241
match attribute.datatype:
235242
case Bool(znam, onam):
@@ -241,11 +248,11 @@ def _get_output_record(pv: str, attribute: AttrW, on_update: Callable) -> Any:
241248
on_update=on_update,
242249
)
243250
case Int():
244-
return builder.longOut(pv, always_update=True, on_update=on_update)
251+
return builder.longOut(pv, always_update=True, on_update=on_update, **attribute_fields)
245252
case Float(prec):
246-
return builder.aOut(pv, always_update=True, on_update=on_update, PREC=prec)
253+
return builder.aOut(pv, always_update=True, on_update=on_update, PREC=prec, **attribute_fields)
247254
case String():
248-
return builder.longStringOut(pv, always_update=True, on_update=on_update)
255+
return builder.longStringOut(pv, always_update=True, on_update=on_update, **attribute_fields)
249256
case _:
250257
raise FastCSException(
251258
f"Unsupported type {type(attribute.datatype)}: {attribute.datatype}"

0 commit comments

Comments
 (0)