@@ -19,7 +19,12 @@ class SingleMapping:
1919
2020
2121class BaseController :
22+ #! Attributes passed from the device at runtime.
23+ attributes : dict [str , Attribute ]
24+
2225 def __init__ (self , path : list [str ] | None = None ) -> None :
26+ if not hasattr (self , "attributes" ):
27+ self .attributes = {}
2328 self ._path : list [str ] = path or []
2429 self .__sub_controller_tree : dict [str , BaseController ] = {}
2530
@@ -40,9 +45,19 @@ def _bind_attrs(self) -> None:
4045 for attr_name in dir (self ):
4146 attr = getattr (self , attr_name )
4247 if isinstance (attr , Attribute ):
48+ if (
49+ attr_name in self .attributes
50+ and self .attributes [attr_name ] is not attr
51+ ):
52+ raise ValueError (
53+ f"`{ type (self ).__name__ } ` has conflicting attribute "
54+ f"`{ attr_name } ` already present in the attributes dict."
55+ )
4356 new_attribute = copy (attr )
4457 setattr (self , attr_name , new_attribute )
4558
59+ self .attributes [attr_name ] = new_attribute
60+
4661 def register_sub_controller (self , name : str , sub_controller : SubController ):
4762 if name in self .__sub_controller_tree .keys ():
4863 raise ValueError (
@@ -69,7 +84,6 @@ def _get_single_mapping(controller: BaseController) -> SingleMapping:
6984 scan_methods : dict [str , Scan ] = {}
7085 put_methods : dict [str , Put ] = {}
7186 command_methods : dict [str , Command ] = {}
72- attributes : dict [str , Attribute ] = {}
7387 for attr_name in dir (controller ):
7488 attr = getattr (controller , attr_name )
7589 match attr :
@@ -79,11 +93,14 @@ def _get_single_mapping(controller: BaseController) -> SingleMapping:
7993 scan_methods [attr_name ] = scan_method
8094 case WrappedMethod (fastcs_method = Command (enabled = True ) as command_method ):
8195 command_methods [attr_name ] = command_method
82- case Attribute (enabled = True ):
83- attributes [attr_name ] = attr
8496
97+ enabled_attributes = {
98+ name : attribute
99+ for name , attribute in controller .attributes .items ()
100+ if attribute .enabled
101+ }
85102 return SingleMapping (
86- controller , scan_methods , put_methods , command_methods , attributes
103+ controller , scan_methods , put_methods , command_methods , enabled_attributes
87104 )
88105
89106
0 commit comments