Skip to content

Commit 9bd7793

Browse files
committed
WIP
A
1 parent 9d3d9bf commit 9bd7793

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/fastcs/controller.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def register_sub_controller(self, name: str, sub_controller: SubController):
4242
def get_sub_controllers(self) -> dict[str, BaseController]:
4343
return self.__sub_controller_tree
4444

45+
def get_attributes(self) -> dict[str, Attribute]:
46+
"""For getting any attributes which aren't defined on the class itself."""
47+
48+
return {}
49+
4550

4651
class Controller(BaseController):
4752
"""Top-level controller for a device.

src/fastcs/mapping.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def _get_single_mapping(controller: BaseController) -> SingleMapping:
4141
scan_methods: dict[str, Scan] = {}
4242
put_methods: dict[str, Put] = {}
4343
command_methods: dict[str, Command] = {}
44-
attributes: dict[str, Attribute] = {}
4544
for attr_name in dir(controller):
4645
attr = getattr(controller, attr_name)
4746
match attr:
@@ -51,8 +50,26 @@ def _get_single_mapping(controller: BaseController) -> SingleMapping:
5150
scan_methods[attr_name] = scan_method
5251
case WrappedMethod(fastcs_method=Command(enabled=True) as command_method):
5352
command_methods[attr_name] = command_method
54-
case Attribute(enabled=True):
55-
attributes[attr_name] = attr
53+
54+
attributes: dict[str, Attribute] = {}
55+
for name in dir(type(controller)):
56+
if isinstance((attr := getattr(controller, name, None)), Attribute):
57+
attributes[name] = attr
58+
59+
object_defined_attributes = controller.get_attributes()
60+
61+
if conflicting_keys := {
62+
key
63+
for key in object_defined_attributes.keys() & attributes.keys()
64+
if object_defined_attributes[key] is not attributes[key]
65+
}:
66+
raise TypeError(
67+
f"{controller} has conflicting attributes between those passed in"
68+
"`get_attributes` and those obtained from the class definition: "
69+
f"{conflicting_keys}"
70+
)
71+
72+
attributes.update(object_defined_attributes)
5673

5774
return SingleMapping(
5875
controller, scan_methods, put_methods, command_methods, attributes

0 commit comments

Comments
 (0)