Coverage for janitoo.value_factory : 59%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
"""
This file is part of Janitoo.
Janitoo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Janitoo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Janitoo. If not, see <http://www.gnu.org/licenses/>.
"""
# Set default logging handler to avoid "No handler found" warnings.
############################################################## #Check that we are in sync with the official command classes #Must be implemented for non-regression
##############################################################
"""Implement a value entry for the factory. Used to create complex values. """ """ """ """
""" """ return self._create_config_value(**kwargs)
""" """ return self._create_poll_value(**kwargs)
"""Create a config value associated to the main value """ index=index, type=type, get_data_cb=get_data_cb, set_data_cb=set_data_cb, cmd_class=COMMAND_CONFIGURATION, genre=0x03, is_writeonly=False, is_readonly=False, master_config_value=self)
""" """ if index not in self.instances: self.instances[index] = {} try: if index not in self.instances or self.instances[index]['config'] != data: self.instances[index]['config'] = data self.options.set_option(node_uuid, '%s_%s_%s'%(self.uuid, 'config', index), data) except: logger.exception('Exception when writing %s_%s_%s for node %s'%(self.uuid, 'config', index, node_uuid))
""" """ if self.instances[index]['config'] is None: try: self.instances[index]['config'] = self.options.get_option(node_uuid, '%s_%s_%s'%(self.uuid, 'config', index)) except: logger.exception('Exception when retrieving %s_%s_%s for node %s'%(self.uuid, 'config', index, node_uuid)) else: #~ print "get data", self.uuid, data self.instances[i] = {} else: except: logger.exception('Exception when retrieving %s_%s_%s for node %s'%(self.uuid, 'config', i, node_uuid))
"""Create a poll value associated to the main value """ index=index, units=units, poll_delay=default, get_data_cb=get_data_cb, set_data_cb=set_data_cb, cmd_class=COMMAND_CONFIGURATION, genre=0x03, type=0x04, is_writeonly=False, is_readonly=False)
""" """ else: self.is_polled = False self.poll_delay = 0
""" """ try: if index not in self.instances: self.instances[index] = {} if index not in self.instances or self.instances[index]['poll'] != int(data): self.instances[index]['poll'] = int(data) self.options.set_option(node_uuid, '%s_%s_%s'%(self.uuid, 'poll', index), data) if index == 0: self._update_poll(self.instances[index]['poll']) except: logger.exception('Exception when writing %s_%s_%s for node %s'%(self.uuid, 'poll', index, node_uuid))
""" """ except: logger.exception('Exception when retrieving %s_%s_%s for node %s'%(self.uuid, 'poll', index, node_uuid))
""" """
""" """ #~ print "_instances", self.instances else: #~ print "ret of index_configs", ret
""" """ try: if node_uuid is None: node_uuid = self.node_uuid if config is not None: configs = self.get_index_configs() i = 0 for conf in configs: if config == conf: index = i break i += 1 if index is None: index = self.index if self._data is None: self.instances[index]['data'] = self.default return self.instances[index]['data'] except: logger.exception('Exception when retrieving %s_%s_%s for node %s'%(self.uuid, 'poll', index, node_uuid)) return self.default
""" """ if node_uuid is None: node_uuid = self.node_uuid if config is not None: configs = self.get_index_configs() i = 0 for conf in configs: if config == conf: index = i break i += 1 if index is None: index = self.index if index not in self.instances: self.instances[index] = {} if 'data' not in self.instances[index]: self.instances[index]['data'] = None #~ print index, self.instances[index]['data'], data try: self.instances[index]['data'] = self.default if node_uuid is None: node_uuid = self.node_uuid if index is None: index = self.index self.instances[index]['data'] = data if index == 0: self._data = data #~ print index, self.instances[index]['data'] except: logger.exception('Exception when setting %s_%s_%s for node %s'%(self.uuid, 'data', index, node_uuid))
"""Retrieve a json version of the value """ initial = JNTValue.to_dict(self) #~ print "len(configs)", len(configs) return res elif self._get_data_cb is not None: res['data'] = self._get_data_cb(self.node_uuid, index) else: res['data'] = self.default #~ print "---------------------------------------------------------- res ", res
"""Retrieve a dict version of the value """ #~ print "self.instances[0] %s"%self.instances[0] #~ print "---------------------------------------------------------- self.get_max_index() ", self.get_max_index() #~ print "---------------------------------------------------------- self.instances ", self.instances return {} #~ print "self.get_index_configs() %s"%configs #~ print i, res['label'] #~ print i, '%s'%self.instances #~ print i, '%s'%self.instances[i] #~ print "---------------------------------------------------------- i ", i #~ print i, res['label'], configs[i] except: logger.exception('Exception in to_dict_with_indexes') #~ print "---------------------------------------------------------- ret ", ret
"""Retrieve a json version of the value """ #~ print "to_json_with_indexes", res except: logger.exception('Exception in to_json_with_indexes') return None |