Commit abecab00 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by Samuel Debionne
Browse files

[CLIENT] Allow device parameters to be directly created from dicts

parent 40580182
......@@ -50,16 +50,14 @@ class ParamBase:
# from_model: create an item of type t from a Model instance x
# to_model: return Model instance from item value v
ItemKind = namedtuple('Detector_Param_ItemKind',
['name', 'from_model', 'to_model'])
['name', 'to_model', 'from_model'],
defaults=[lambda t, x: t(x)])
ItemKinds = [ItemKind('enums',
lambda t, x: t(x),
lambda v: v.value),
ItemKind('types',
lambda t, x: t(**x),
lambda v: v.getModelDict()),
ItemKind('arrays',
lambda t, x: t(x),
lambda v: v.getModelList())]
# class dict with the three kind of items: enums, types, arrays
......@@ -69,6 +67,10 @@ class ParamBase:
model = self.Model(*args, **kws)
self.__dict__.update({'__model__': model})
# Also parse dictionary passed as unique arg
if len(args) == 1:
kws.update(args[0])
# collect the class dicts provided on type creation, one per ItemKind:
# self.Enums, self.Types, self.Arrays
dicts = {n: getattr(self, n.capitalize()) for n in self.ItemKindDict}
......@@ -192,7 +194,7 @@ class ParamBase:
def __deepcopy__(self, memo):
klass = self.__class__
return klass(**self.getModelDict())
return klass(self.getModelDict())
class ParamArray(list):
......@@ -452,7 +454,7 @@ class Detector:
def GetAttrData(n):
type_data = get_type_data(n, GetSchema(n))
json_data = json.loads(getattr(d, n))
value = type_data.klass(**json_data)
value = type_data.klass(json_data)
return dict(type_data=type_data, value=value)
names = tango_db.get_class_attribute_list(tango_class, '*')
attr_names = [n for n in names for attr in d.attribute_list_query()
......@@ -761,7 +763,7 @@ def test_acq_params_schema(d):
pretty_print_json(acq_params_json, 'acq_params_json')
acq_params_dict = json.loads(acq_params_json)
print(f'acq_params_dict={acq_params_dict} [{type(acq_params_dict)}]')
acq_params = AcqParams(**acq_params_dict)
acq_params = AcqParams(acq_params_dict)
print(f'acq_params={acq_params}')
expo_time = acq_params.acq.expo_time
print(f'expo_time={expo_time} [{type(expo_time)}]')
......@@ -805,7 +807,7 @@ def test_acq_params_schema(d):
for k in 'flip', 'roi':
partial_acq_params_dict['img'].pop(k, None)
print(f'partial_acq_params_dict={partial_acq_params_dict}')
partial_acq_params = AcqParams(**partial_acq_params_dict)
partial_acq_params = AcqParams(partial_acq_params_dict)
partial_acq_params.acq.nb_frames *= 5
partial_acq_params.acq.expo_time *= 10
tl = dict(x=10, y=10)
......@@ -831,7 +833,7 @@ def test_proc_params_schema(d):
pretty_print_json(proc_params_json, 'proc_params_json')
proc_params_dict = json.loads(proc_params_json)
print(f'proc_params_dict={proc_params_dict} [{type(proc_params_dict)}]')
proc_params = ProcParams(**proc_params_dict)
proc_params = ProcParams(proc_params_dict)
print(f'proc_params={proc_params}')
proc_params_modified = False
if 'counters' in proc_params:
......@@ -980,7 +982,7 @@ def main():
klass_name = cpp_2_python_name(name)
klass = getattr(device, klass_name, None)
if klass:
config[name] = klass(**par_json)
config[name] = klass(par_json)
test_acquisition_states(device, config)
......
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