示例#1
0
    def __init__(self,
                 key,
                 primary,
                 value_type,
                 settings,
                 device=None,
                 block=None):

        Block.__init__(self, settings)

        self.key = key
        self.type = value_type
        self.primary = primary
        self.device = device
        self.block = block
        self.set(settings)

        if self.primary:
            self.id = self.device.id + "_" + self.key
        else:
            self.id = self.block.id + "_" + self.key

        # Definition de l'interface Block de l'info : c'est un bloc avec un seul output
        self.output = OutputNode(self, 'output', 'Value', self.type)
        # 		self.output = OutputNode(key = 'output',
        # 								 value_type = self.type,
        # 								 name = 'Value',
        # 								 block = self)
        self.nodes = [self.output]
示例#2
0
class BooleanConstant(Block):

    settings_format = Block.settings_format + [{
        'type': 'bool',
        'title': 'Constant',
        'desc': 'The constant value',
        'key': 'value'
    }, {
        'type': 'num',
        'title': 'Test',
        'desc': 'Just to test the settings',
        'key': 'test_value'
    }]

    def __init__(self, *args, **kwargs):
        super(BooleanConstant, self).__init__(*args, **kwargs)

        self.set({'name': 'Boolean Constant'})

        self.output = OutputNode(self, 'output', 'out', 'bool')
        if not self.settings.has_key('value'):
            self.set({'value': False, 'test_value': 36})

        self.output.add_value(self.settings['value'])
        self.add_nodes(self.output)

    def set(self, settings):
        super(BooleanConstant, self).set(settings)

        print settings

        if self.settings.has_key('value'):
            self.output.add_value(self.settings['value'])
示例#3
0
    def __init__(self, *args, **kwargs):
        super(Multiply, self).__init__(*args, **kwargs)
        self.set({'name': 'Multiply'})

        self.operands = MultiInputNode(self, 'operands', 'in', 'numeric')
        self.result = OutputNode(self, 'result', 'out', 'numeric')

        self.add_nodes(self.operands, self.result)
示例#4
0
    def __init__(self, *args, **kwargs):
        super(Not, self).__init__(*args, **kwargs)
        self.set({'name': 'Not'})

        self.input = SimpleInputNode(self, 'input', 'in', 'bool')
        self.output = OutputNode(self, 'output', 'out', 'bool')

        self.add_nodes(self.input, self.output)
示例#5
0
    def __init__(self, *args, **kwargs):
        super(And, self).__init__(*args, **kwargs)
        self.set({'name': 'And'})

        self.input1 = SimpleInputNode(self, 'input1', 'in1', 'bool')
        self.input2 = SimpleInputNode(self, 'input2', 'in2', 'bool')
        self.output = OutputNode(self, 'output', 'out', 'bool')

        self.add_nodes(self.input1, self.input2, self.output)
示例#6
0
    def __init__(self, *args, **kwargs):
        super(TriggerOnAlarm, self).__init__(*args, **kwargs)
        self.set({'name': 'Trigger on alarm'})

        self.alarm = SimpleInputNode(self, 'alarm', 'alarm', 'bool')
        self.trigger = SimpleInputNode(self, 'trigger', 'trigger', 'bool')
        self.output = OutputNode(self, 'output', 'out', 'bool')

        self.add_nodes(self.alarm, self.trigger, self.output)
示例#7
0
    def __init__(self, *args, **kwargs):
        super(BooleanConstant, self).__init__(*args, **kwargs)

        self.set({'name': 'Boolean Constant'})

        self.output = OutputNode(self, 'output', 'out', 'bool')
        if not self.settings.has_key('value'):
            self.set({'value': False, 'test_value': 36})

        self.output.add_value(self.settings['value'])
        self.add_nodes(self.output)
示例#8
0
class Not(Block):
    def __init__(self, *args, **kwargs):
        super(Not, self).__init__(*args, **kwargs)
        self.set({'name': 'Not'})

        self.input = SimpleInputNode(self, 'input', 'in', 'bool')
        self.output = OutputNode(self, 'output', 'out', 'bool')

        self.add_nodes(self.input, self.output)

    def process(self, changed_input):
        self.output.add_value(not self.input.get_value())
示例#9
0
class And(Block):
    def __init__(self, *args, **kwargs):
        super(And, self).__init__(*args, **kwargs)
        self.set({'name': 'And'})

        self.input1 = SimpleInputNode(self, 'input1', 'in1', 'bool')
        self.input2 = SimpleInputNode(self, 'input2', 'in2', 'bool')
        self.output = OutputNode(self, 'output', 'out', 'bool')

        self.add_nodes(self.input1, self.input2, self.output)

    def process(self, changed_input):
        self.output.add_value(self.input1.get_value()
                              and self.input2.get_value())
示例#10
0
class Multiply(Block):
    def __init__(self, *args, **kwargs):
        super(Multiply, self).__init__(*args, **kwargs)
        self.set({'name': 'Multiply'})

        self.operands = MultiInputNode(self, 'operands', 'in', 'numeric')
        self.result = OutputNode(self, 'result', 'out', 'numeric')

        self.add_nodes(self.operands, self.result)

    def process(self, changed_input):
        result = 1
        for value in self.operands.get_value():
            result *= value
        self.result.add_value(result)
示例#11
0
class TriggerOnAlarm(Block):
    def __init__(self, *args, **kwargs):
        super(TriggerOnAlarm, self).__init__(*args, **kwargs)
        self.set({'name': 'Trigger on alarm'})

        self.alarm = SimpleInputNode(self, 'alarm', 'alarm', 'bool')
        self.trigger = SimpleInputNode(self, 'trigger', 'trigger', 'bool')
        self.output = OutputNode(self, 'output', 'out', 'bool')

        self.add_nodes(self.alarm, self.trigger, self.output)

    def process(self, changed_input):
        if changed_input == self.alarm:
            if not self.alarm.get_value():
                self.output.add_value(False)
        elif changed_input == self.trigger:
            if self.trigger.get_value() and self.alarm.get_value():
                self.output.add_value(True)
示例#12
0
class Information(Block):
    """ Class used to wrap an information made available by a device.
	
	"""

    settings_format = [{
        'type': 'string',
        'title': 'Name',
        'desc': 'Name of the information',
        'key': 'name'
    }, {
        'type': 'string_long',
        'title': 'Description',
        'desc': 'Description of the information',
        'key': 'description'
    }, {
        'type': 'string',
        'title': 'Type',
        'desc': 'Type of the information',
        'key': 'type',
        'disabled': True
    }]

    def __init__(self,
                 key,
                 primary,
                 value_type,
                 settings,
                 device=None,
                 block=None):

        Block.__init__(self, settings)

        self.key = key
        self.type = value_type
        self.primary = primary
        self.device = device
        self.block = block
        self.set(settings)

        if self.primary:
            self.id = self.device.id + "_" + self.key
        else:
            self.id = self.block.id + "_" + self.key

        # Definition de l'interface Block de l'info : c'est un bloc avec un seul output
        self.output = OutputNode(self, 'output', 'Value', self.type)
        # 		self.output = OutputNode(key = 'output',
        # 								 value_type = self.type,
        # 								 name = 'Value',
        # 								 block = self)
        self.nodes = [self.output]

    def update(self, new_value):
        """ Updates the Information with a new value.
		
		"""

        print 'updating info ' + self.id
        result = False
        if self.check_value(new_value):
            self.output.add_value(new_value)
            result = True
        return result

    def check_value(self, new_value):
        """ *(Internal)* Checks if the new value given to update is ok.
		
		"""

        # TODO: verifier que la nouvelle valeur donnee est du bon type
        return True

    def get_value(self):
        """ Returns the last value of the information.
		"""

        return self.output.get_value()

    def get_values(self):
        """ Returns the values of the information between the *start_time* and the *ed_time* parameters.
		
		"""

        return self.output.get_values()