Commit f13ce3dd authored by Matias Guijarro's avatar Matias Guijarro Committed by Matias Guijarro
Browse files

motor config: make .get() behaving like a Python dictionary

parent 7c89003d
......@@ -11,9 +11,6 @@ import time
class StaticConfig:
NO_VALUE = Null()
def __init__(self, config_node):
self.__config_dict = config_node
self.__config_has_changed = False
......@@ -32,14 +29,13 @@ class StaticConfig:
def config_dict(self):
return self.__config_dict
def get(self, property_name, converter=str, default=NO_VALUE):
def get(self, property_name, converter=str, default=None):
"""Get static property
Args:
property_name (str): Property name
converter (function): Default :func:`str`, Conversion function from configuration format to Python
default: Default: NO_VALUE, default value for property
inherited (bool): Default: False, Property can be inherited
default: default value for property if key does not exist (defaults to None)
Returns:
Property value
......@@ -51,18 +47,14 @@ class StaticConfig:
if self.__config_has_changed:
self.reload()
self.__config_has_changed = False
property_value = self.config_dict.get(property_name)
if property_value is not None:
if property_value is None:
return default
else:
if callable(converter):
return converter(property_value)
else:
return property_value
else:
if default != self.NO_VALUE:
return default
raise KeyError("no property '%s` in config" % property_name)
def set(self, property_name, value):
if self.__config_has_changed:
......
......@@ -87,24 +87,15 @@ class ESRF_Undulator(Controller):
log_debug(self, f"attr_pos_name={attr_pos_name}")
try:
attr_vel_name = axis.config.get("attribute_velocity", str)
except KeyError:
attr_vel_name = "Velocity"
attr_vel_name = axis.config.get("attribute_velocity", str, "Velocity")
log_debug(self, f"attr_vel_name={attr_vel_name}")
try:
attr_fvel_name = axis.config.get("attribute_first_velocity", str)
except KeyError:
attr_fvel_name = "FirstVelocity"
attr_fvel_name = axis.config.get(
"attribute_first_velocity", str, "FirstVelocity"
)
log_debug(self, f"attr_fvel_name={attr_fvel_name}")
try:
attr_acc_name = axis.config.get("attribute_acceleration", str)
except KeyError:
attr_acc_name = "Acceleration"
attr_acc_name = axis.config.get("attribute_acceleration", str, "Acceleration")
log_debug(self, f"attr_acc_name={attr_acc_name}")
alpha = axis.config.get("alpha", float, 0.0)
......@@ -112,19 +103,18 @@ class ESRF_Undulator(Controller):
log_debug(self, f"alpha={alpha} period={period}")
try:
undu_prefix = axis.config.get("undu_prefix", str)
attr_pos_name = undu_prefix + attr_pos_name
attr_vel_name = undu_prefix + attr_vel_name
attr_fvel_name = undu_prefix + attr_fvel_name
attr_acc_name = undu_prefix + attr_acc_name
except KeyError:
undu_prefix = axis.config.get("undu_prefix", str)
if undu_prefix is None:
log_debug(self, "'undu_prefix' not specified in config")
if attr_pos_name == "Position":
raise RuntimeError("'undu_prefix' must be specified in config")
else:
undu_prefix = ""
else:
attr_pos_name = undu_prefix + attr_pos_name
attr_vel_name = undu_prefix + attr_vel_name
attr_fvel_name = undu_prefix + attr_fvel_name
attr_acc_name = undu_prefix + attr_acc_name
# check for revolver undulator
is_revolver = False
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment