Skip to content

Commit ba3a72c

Browse files
committed
alias the record with pascal case if the pv_name is not pascal case already
1 parent 066f771 commit ba3a72c

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

src/fastcs/attributes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +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
55+
description: str | None = None,
5656
) -> None:
5757
assert (
5858
datatype.dtype in ATTRIBUTE_TYPES
@@ -103,7 +103,7 @@ def __init__(
103103
group,
104104
handler,
105105
allowed_values=allowed_values, # type: ignore
106-
description=description
106+
description=description,
107107
)
108108
self._value: T = datatype.dtype()
109109
self._update_callback: AttrCallback[T] | None = None
@@ -136,15 +136,15 @@ def __init__(
136136
group: str | None = None,
137137
handler: Sender | None = None,
138138
allowed_values: list[T] | None = None,
139-
description: str | None = None
139+
description: str | None = None,
140140
) -> None:
141141
super().__init__(
142142
datatype, # type: ignore
143143
access_mode,
144144
group,
145145
handler,
146146
allowed_values=allowed_values, # type: ignore
147-
description=description
147+
description=description,
148148
)
149149
self._process_callback: AttrCallback[T] | None = None
150150
self._write_display_callback: AttrCallback[T] | None = None
@@ -186,15 +186,15 @@ def __init__(
186186
group: str | None = None,
187187
handler: Handler | None = None,
188188
allowed_values: list[T] | None = None,
189-
description: str | None = None
189+
description: str | None = None,
190190
) -> None:
191191
super().__init__(
192192
datatype, # type: ignore
193193
access_mode,
194194
group,
195195
handler,
196196
allowed_values, # type: ignore
197-
description=description
197+
description=description,
198198
)
199199

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

src/fastcs/backends/epics/ioc.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _create_and_link_attribute_pvs(pv_prefix: str, mapping: Mapping) -> None:
118118
for single_mapping in mapping.get_controller_mappings():
119119
path = single_mapping.controller.path
120120
for attr_name, attribute in single_mapping.attributes.items():
121-
pv_name = attr_name.title().replace("_", "")
121+
pv_name = attr_name.replace("_", "")
122122
_pv_prefix = ":".join([pv_prefix] + path)
123123
full_pv_name_length = len(f"{_pv_prefix}:{pv_name}")
124124

@@ -222,6 +222,10 @@ async def async_write_display(value: T):
222222
record = _get_output_record(
223223
f"{pv_prefix}:{pv_name}", attribute, on_update=on_update
224224
)
225+
pascal_case_pv_name = pv_name.title()
226+
if pascal_case_pv_name != pv_name:
227+
record.add_alias(f"{pv_prefix}:{pascal_case_pv_name}")
228+
225229
_add_attr_pvi_info(record, pv_prefix, attr_name, "w")
226230

227231
attribute.set_write_display_callback(async_write_display)
@@ -236,7 +240,13 @@ def _get_output_record(pv: str, attribute: AttrW, on_update: Callable) -> Any:
236240
isinstance(v, str) for v in attribute.allowed_values
237241
)
238242
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)
243+
return builder.mbbOut(
244+
pv,
245+
always_update=True,
246+
on_update=on_update,
247+
**state_keys,
248+
**attribute_fields,
249+
)
240250

241251
match attribute.datatype:
242252
case Bool(znam, onam):
@@ -248,11 +258,21 @@ def _get_output_record(pv: str, attribute: AttrW, on_update: Callable) -> Any:
248258
on_update=on_update,
249259
)
250260
case Int():
251-
return builder.longOut(pv, always_update=True, on_update=on_update, **attribute_fields)
261+
return builder.longOut(
262+
pv, always_update=True, on_update=on_update, **attribute_fields
263+
)
252264
case Float(prec):
253-
return builder.aOut(pv, always_update=True, on_update=on_update, PREC=prec, **attribute_fields)
265+
return builder.aOut(
266+
pv,
267+
always_update=True,
268+
on_update=on_update,
269+
PREC=prec,
270+
**attribute_fields,
271+
)
254272
case String():
255-
return builder.longStringOut(pv, always_update=True, on_update=on_update, **attribute_fields)
273+
return builder.longStringOut(
274+
pv, always_update=True, on_update=on_update, **attribute_fields
275+
)
256276
case _:
257277
raise FastCSException(
258278
f"Unsupported type {type(attribute.datatype)}: {attribute.datatype}"

tests/backends/epics/test_ioc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ def test_add_attr_pvi_info(mocker: MockerFixture):
357357
)
358358

359359

360-
async def do_nothing(arg): ...
360+
async def do_nothing(arg):
361+
...
361362

362363

363364
class NothingCommand:

0 commit comments

Comments
 (0)