diff --git a/wa/framework/configuration/core.py b/wa/framework/configuration/core.py index 8db5d553..cfe5ea65 100644 --- a/wa/framework/configuration/core.py +++ b/wa/framework/configuration/core.py @@ -118,6 +118,10 @@ class LoggingConfig(dict): 'color': True, } + @staticmethod + def from_pod(pod): + return LoggingConfig(pod) + def __init__(self, config=None): dict.__init__(self) if isinstance(config, dict): @@ -136,6 +140,9 @@ class LoggingConfig(dict): else: raise ValueError(config) + def to_pod(self): + return self + def get_type_name(kind): typename = str(kind) @@ -254,7 +261,7 @@ class ConfigurationPoint(object): def set_value(self, obj, value=None, check_mandatory=True): if value is None: if self.default is not None: - value = self.default + value = self.kind(self.default) elif check_mandatory and self.mandatory: msg = 'No values specified for mandatory parameter "{}" in {}' raise ConfigError(msg.format(self.name, obj.name)) diff --git a/wa/instrumentation/energy_measurement.py b/wa/instrumentation/energy_measurement.py index 6c7a17c3..b796e32f 100644 --- a/wa/instrumentation/energy_measurement.py +++ b/wa/instrumentation/energy_measurement.py @@ -29,7 +29,7 @@ from wa import Instrument, Parameter from wa.framework import pluginloader from wa.framework.plugin import Plugin from wa.framework.exception import ConfigError -from wa.utils.types import list_of_strings, list_of_ints, list_or_string +from wa.utils.types import list_of_strings, list_of_ints, list_or_string, obj_dict class EnergyInstrumentBackend(Plugin): @@ -214,18 +214,16 @@ class EnergyMeasurement(Instrument): self.measurement_csv = None self.loader = loader self.backend = self.loader.get_plugin(self.instrument) - self.params = {} + self.params = obj_dict() if self.backend.instrument.mode != CONTINUOUS: msg = '{} instrument does not support continuous measurement collection' raise ConfigError(msg.format(self.instrument)) supported_params = self.backend.get_parameters() - for name, value in supported_params.iteritems(): - if name in self.instrument_parameters: - self.params[name] = self.instrument_parameters[name] - elif value.default: - self.params[name] = value.default + for name, param in supported_params.iteritems(): + value = self.instrument_parameters.get(name) + param.set_value(self.params, value) self.backend.validate_parameters(self.params) def initialize(self, context): diff --git a/wa/utils/types.py b/wa/utils/types.py index f299eefb..d19bdf1f 100644 --- a/wa/utils/types.py +++ b/wa/utils/types.py @@ -107,6 +107,12 @@ def list_of(type_): def extend(self, other): list.extend(self, map(type_, other)) + def from_pod(cls, pod): + return cls(map(type_, pod)) + + def _to_pod(self): + return self + def __setitem__(self, idx, value): list.__setitem__(self, idx, type_(value)) @@ -116,6 +122,8 @@ def list_of(type_): "__setitem__": __setitem__, "append": append, "extend": extend, + "to_pod": _to_pod, + "from_pod": classmethod(from_pod), })