Skip to content

Commit 111287a

Browse files
committed
added option for attributes being pascal and controllers being capitalized
1 parent 2c436ff commit 111287a

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

src/fastcs/backends/epics/gui.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from pydantic import ValidationError
2828

2929
from fastcs.attributes import Attribute, AttrR, AttrRW, AttrW
30-
from fastcs.backends.epics.util import EpicsNameOptions, _convert_attr_name_to_pv_name
30+
from fastcs.backends.epics.util import EpicsNameOptions, _convert_attribute_name_to_pv_name
3131
from fastcs.cs_methods import Command
3232
from fastcs.datatypes import Bool, Float, Int, String
3333
from fastcs.exceptions import FastCSException
@@ -64,14 +64,14 @@ def _get_pv(self, attr_path: list[str], name: str):
6464
self._pv_prefix,
6565
]
6666
+ [
67-
_convert_attr_name_to_pv_name(
68-
attr_name, self.epics_name_options.pv_naming_convention
67+
_convert_attribute_name_to_pv_name(
68+
attr_name, self.epics_name_options.pv_naming_convention, is_attribute=False
6969
)
7070
for attr_name in attr_path
7171
]
7272
+ [
73-
_convert_attr_name_to_pv_name(
74-
name, self.epics_name_options.pv_naming_convention
73+
_convert_attribute_name_to_pv_name(
74+
name, self.epics_name_options.pv_naming_convention, is_attribute=True
7575
),
7676
],
7777
)

src/fastcs/backends/epics/ioc.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from fastcs.backends.epics.util import (
1212
MBB_STATE_FIELDS,
1313
EpicsNameOptions,
14-
PvNamingConvention,
14+
_convert_attribute_name_to_pv_name,
1515
attr_is_enum,
1616
enum_index_to_value,
1717
enum_value_to_index,
@@ -30,15 +30,6 @@ class EpicsIOCOptions:
3030
name_options: EpicsNameOptions = EpicsNameOptions()
3131

3232

33-
def _convert_attr_name_to_pv_name(
34-
attr_name: str, naming_convention: PvNamingConvention
35-
) -> str:
36-
if naming_convention == PvNamingConvention.PASCAL:
37-
return attr_name.title().replace("_", "")
38-
elif naming_convention == PvNamingConvention.CAPITALIZED:
39-
return attr_name.upper().replace("_", "-")
40-
return attr_name
41-
4233

4334
class EpicsIOC:
4435
def __init__(
@@ -80,8 +71,10 @@ def _add_sub_controller_pvi_info(self, pv_prefix: str, parent: BaseController):
8071
child_pvi = self._name_options.pv_separator.join(
8172
[pv_prefix]
8273
+ [
83-
_convert_attr_name_to_pv_name(
84-
path, self._name_options.pv_naming_convention
74+
_convert_attribute_name_to_pv_name(
75+
path,
76+
self._name_options.pv_naming_convention,
77+
is_attribute=False
8578
)
8679
for path in child.path
8780
]
@@ -96,14 +89,14 @@ def _add_sub_controller_pvi_info(self, pv_prefix: str, parent: BaseController):
9689
def _create_and_link_attribute_pvs(self, pv_prefix: str, mapping: Mapping) -> None:
9790
for single_mapping in mapping.get_controller_mappings():
9891
formatted_path = [
99-
_convert_attr_name_to_pv_name(
100-
p, self._name_options.pv_naming_convention
92+
_convert_attribute_name_to_pv_name(
93+
p, self._name_options.pv_naming_convention, is_attribute=False
10194
)
10295
for p in single_mapping.controller.path
10396
]
10497
for attr_name, attribute in single_mapping.attributes.items():
105-
pv_name = _convert_attr_name_to_pv_name(
106-
attr_name, self._name_options.pv_naming_convention
98+
pv_name = _convert_attribute_name_to_pv_name(
99+
attr_name, self._name_options.pv_naming_convention, is_attribute=True
107100
)
108101
_pv_prefix = self._name_options.pv_separator.join(
109102
[pv_prefix] + formatted_path
@@ -169,14 +162,14 @@ async def async_record_set(value: T):
169162
def _create_and_link_command_pvs(self, pv_prefix: str, mapping: Mapping) -> None:
170163
for single_mapping in mapping.get_controller_mappings():
171164
formatted_path = [
172-
_convert_attr_name_to_pv_name(
173-
p, self._name_options.pv_naming_convention
165+
_convert_attribute_name_to_pv_name(
166+
p, self._name_options.pv_naming_convention, is_attribute=False
174167
)
175168
for p in single_mapping.controller.path
176169
]
177170
for attr_name, method in single_mapping.command_methods.items():
178-
pv_name = _convert_attr_name_to_pv_name(
179-
attr_name, self._name_options.pv_naming_convention
171+
pv_name = _convert_attribute_name_to_pv_name(
172+
attr_name, self._name_options.pv_naming_convention, is_attribute=True
180173
)
181174
_pv_prefix = self._name_options.pv_separator.join(
182175
[pv_prefix] + formatted_path

src/fastcs/backends/epics/util.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class PvNamingConvention(Enum):
3232
NO_CONVERSION = "NO_CONVERSION"
3333
PASCAL = "PASCAL"
3434
CAPITALIZED = "CAPITALIZED"
35+
CAPITALIZED_CONTROLLER_PASCAL_ATTRIBUTE = "CAPITALIZED_CONTROLLER_PASCAL_ATTRIBUTE"
3536

3637

3738
DEFAULT_PV_SEPARATOR = ":"
@@ -43,13 +44,17 @@ class EpicsNameOptions:
4344
pv_separator: str = DEFAULT_PV_SEPARATOR
4445

4546

46-
def _convert_attr_name_to_pv_name(
47-
attr_name: str, naming_convention: PvNamingConvention
47+
def _convert_attribute_name_to_pv_name(
48+
attr_name: str, naming_convention: PvNamingConvention, is_attribute: bool = False
4849
) -> str:
4950
if naming_convention == PvNamingConvention.PASCAL:
5051
return attr_name.title().replace("_", "")
5152
elif naming_convention == PvNamingConvention.CAPITALIZED:
5253
return attr_name.upper().replace("_", "-")
54+
elif naming_convention == PvNamingConvention.CAPITALIZED_CONTROLLER_PASCAL_ATTRIBUTE:
55+
if is_attribute:
56+
return _convert_attribute_name_to_pv_name(attr_name, PvNamingConvention.PASCAL, is_attribute)
57+
return _convert_attribute_name_to_pv_name(attr_name, PvNamingConvention.CAPITALIZED)
5358
return attr_name
5459

5560

src/fastcs/mapping.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def _get_single_mapping(controller: BaseController) -> SingleMapping:
5656
attributes[attr_name] = attr
5757

5858
additional_attributes = controller.additional_attributes
59-
if common_attributes := additional_attributes.keys() ^ attributes.keys():
59+
if common_attributes := additional_attributes.keys() & attributes.keys():
6060
raise RuntimeError(
6161
f"Received additional attributes {common_attributes} "
62-
"already present in the controller."
62+
f"already present in the controller {controller}."
6363
)
6464

6565
attributes.update(additional_attributes)

0 commit comments

Comments
 (0)