Skip to content

Commit 2c436ff

Browse files
committed
added option to not search controller for attributes
Use a method instead.
1 parent 6cc2ef4 commit 2c436ff

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/fastcs/controller.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66

77

88
class BaseController:
9-
def __init__(self, path: list[str] | None = None) -> None:
9+
def __init__(
10+
self, path: list[str] | None = None, search_device_for_attributes: bool = True
11+
) -> None:
1012
self._path: list[str] = path or []
11-
self.__sub_controller_tree: dict[str, BaseController] = {}
13+
# If this is set to `False`, FastCS will only use attributes defined in
14+
# `additional_attributes`.
15+
self.search_device_for_attributes = search_device_for_attributes
1216

17+
self.__sub_controller_tree: dict[str, BaseController] = {}
1318
self._bind_attrs()
1419

1520
@property
16-
def additional_attributes(self) -> dict[str, Attribute] | None:
17-
"""FastCS will look for attributes on the controller, but additional attribtues
18-
be provided here."""
19-
return None
21+
def additional_attributes(self) -> dict[str, Attribute]:
22+
"""FastCS will look for attributes on the controller, but additional attributes
23+
are provided by this method."""
24+
return {}
2025

2126
@property
2227
def path(self) -> list[str]:
@@ -58,8 +63,8 @@ class Controller(BaseController):
5863
generating a UI or creating parameters for a control system.
5964
"""
6065

61-
def __init__(self) -> None:
62-
super().__init__()
66+
def __init__(self, search_device_for_attributes: bool = True) -> None:
67+
super().__init__(search_device_for_attributes=search_device_for_attributes)
6368

6469
async def initialise(self) -> None:
6570
pass
@@ -75,5 +80,5 @@ class SubController(BaseController):
7580
it as part of a larger device.
7681
"""
7782

78-
def __init__(self) -> None:
79-
super().__init__()
83+
def __init__(self, search_device_for_attributes: bool = True) -> None:
84+
super().__init__(search_device_for_attributes=search_device_for_attributes)

src/fastcs/mapping.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,17 @@ def _get_single_mapping(controller: BaseController) -> SingleMapping:
5252
case WrappedMethod(fastcs_method=Command(enabled=True) as command_method):
5353
command_methods[attr_name] = command_method
5454
case Attribute(enabled=True):
55-
attributes[attr_name] = attr
55+
if controller.search_device_for_attributes:
56+
attributes[attr_name] = attr
5657

57-
attributes.update(controller.additional_attributes or {})
58+
additional_attributes = controller.additional_attributes
59+
if common_attributes := additional_attributes.keys() ^ attributes.keys():
60+
raise RuntimeError(
61+
f"Received additional attributes {common_attributes} "
62+
"already present in the controller."
63+
)
64+
65+
attributes.update(additional_attributes)
5866

5967
return SingleMapping(
6068
controller, scan_methods, put_methods, command_methods, attributes

0 commit comments

Comments
 (0)