fix(galilsignalbase): fix root access for controller from parent.
This commit is contained in:
@@ -348,23 +348,7 @@ class GalilSignalBase(SocketSignal):
|
||||
def __init__(self, signal_name, **kwargs):
|
||||
self.signal_name = signal_name
|
||||
super().__init__(**kwargs)
|
||||
self.controller: Controller = self._find_attribute_recursively("controller")
|
||||
|
||||
def _find_attribute_recursively(self, attribute: str) -> Any:
|
||||
"""
|
||||
Find an attribute recursively for nested sub-devices.
|
||||
This is needed to find for example the controller instance for DDC components,
|
||||
thus nested devices.
|
||||
"""
|
||||
max_depth = 10 # to prevent infinite recursion
|
||||
current_parent = self.parent
|
||||
depth = 0
|
||||
while current_parent is not None and depth < max_depth:
|
||||
if hasattr(current_parent, attribute):
|
||||
return getattr(current_parent, attribute)
|
||||
current_parent = getattr(current_parent, "parent", None)
|
||||
depth += 1
|
||||
raise RuntimeError(f"Attribute '{attribute}' not found within maximum depth {max_depth}.")
|
||||
self.controller = self.root.controller if hasattr(self.root, "controller") else None
|
||||
|
||||
|
||||
class GalilSignalRO(GalilSignalBase):
|
||||
|
||||
@@ -84,7 +84,11 @@ class GalilRIOSignal(GalilSignalBase):
|
||||
|
||||
def __init__(self, signal_name: str, channel: int, parent: GalilRIO, **kwargs):
|
||||
super().__init__(signal_name, parent=parent, **kwargs)
|
||||
self._readback_metadata = self._find_attribute_recursively("_readback_metadata")
|
||||
self._readback_metadata = (
|
||||
self.root._readback_metadata
|
||||
if hasattr(self.root, "_readback_metadata")
|
||||
else {"last_readback": 0.0}
|
||||
)
|
||||
self._channel = channel
|
||||
self._metadata["connected"] = False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user