Skip to content

Commit 5aa7a12

Browse files
authored
fix: Prevent grouping attributes in the pva pvi. (#136)
Unlike controllers, attributes should not be grouped in the pva pvi tree.
1 parent 920a8b2 commit 5aa7a12

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/fastcs/transport/epics/pva/pvi_tree.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,20 @@ def _get_signal_infos(self) -> dict[str, _PviSignalInfo]:
7676
def _make_p4p_raw_value(self) -> dict:
7777
p4p_raw_value = defaultdict(dict)
7878
for pv_leaf, signal_info in self._get_signal_infos().items():
79-
pvi_name, number = _pv_to_pvi_name(pv_leaf.rstrip(":PVI") or pv_leaf)
80-
if number is not None:
79+
stripped_leaf = pv_leaf.rstrip(":PVI")
80+
is_controller = stripped_leaf != pv_leaf
81+
pvi_name, number = _pv_to_pvi_name(stripped_leaf or pv_leaf)
82+
if is_controller and number is not None:
8183
if signal_info.access not in p4p_raw_value[pvi_name]:
8284
p4p_raw_value[pvi_name][signal_info.access] = {}
8385
p4p_raw_value[pvi_name][signal_info.access][f"v{number}"] = (
8486
signal_info.pv
8587
)
86-
else:
88+
elif is_controller:
8789
p4p_raw_value[pvi_name][signal_info.access] = signal_info.pv
90+
else:
91+
attr_pvi_name = f"{pvi_name}{'' if number is None else number}"
92+
p4p_raw_value[attr_pvi_name][signal_info.access] = signal_info.pv
8893

8994
return p4p_raw_value
9095

tests/transport/epics/pva/test_p4p.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,10 @@ class SomeController(Controller):
352352
"value": {
353353
"additional_child": {"d": f"{pv_prefix}:AdditionalChild:PVI"},
354354
"another_child": {"d": f"{pv_prefix}:AnotherChild:PVI"},
355-
"another_attr": {
356-
"rw": {
357-
"v0": f"{pv_prefix}:AnotherAttr0",
358-
"v1000": f"{pv_prefix}:AnotherAttr1000",
359-
}
360-
},
355+
"another_attr0": {"rw": f"{pv_prefix}:AnotherAttr0"},
356+
"another_attr1000": {"rw": f"{pv_prefix}:AnotherAttr1000"},
361357
"a_third_attr": {"w": f"{pv_prefix}:AThirdAttr"},
362-
"attr": {"rw": {"v1": f"{pv_prefix}:Attr1"}},
358+
"attr1": {"rw": f"{pv_prefix}:Attr1"},
363359
"child": {
364360
"d": {
365361
"v0": f"{pv_prefix}:Child0:PVI",

0 commit comments

Comments
 (0)