Use instance_loader to load observers
@@ -25,6 +25,7 @@ from moler.device.state_machine import StateMachine
from moler.exceptions import CommandWrongState, DeviceFailure, EventWrongState, DeviceChangeStateFailure
from moler.helpers import copy_dict
from moler.helpers import update_dict
+from moler.instance_loader import create_instance_from_class_fullname
# TODO: name, logger/logger_name as param
@@ -339,15 +340,13 @@ class TextualDevice(object):
available_observer_names = self._eventnames_available_in_state[for_state]
if observer_name in available_observer_names:
- # TODO: GL refactor to instance_loader
- observer_splited = available_observer_names[observer_name].split('.')
- observer_module_name = ".".join(observer_splited[:-1])
- observer_class_name = observer_splited[-1]
-
- observer_module = importlib.import_module(observer_module_name)
- observer_class = getattr(observer_module, observer_class_name)
- observer = observer_class(connection=self.io_connection.moler_connection, **kwargs)
-
+ observer = create_instance_from_class_fullname(
+ class_fullname=available_observer_names[observer_name],
+ constructor_parameters={
+ "connection": self.io_connection.moler_connection,
+ **kwargs
+ }
+ )
return observer
exc = DeviceFailure(
