import logging
import random

from obnl.core.client import ClientNode


class ClientTestNode(ClientNode):

    def __init__(self, host, vhost, username, password, config_file,
                 input_attributes=None, output_attributes=None, is_first=False):
        super().__init__(host, vhost, username, password, config_file,
                         input_attributes, output_attributes, is_first)
        self._node_impl.activate_console_logging(logging.DEBUG)

    def step(self, current_time, time_step):
        print('----- '+self.name+' -----')
        print(self.name, time_step)
        print(self.name, current_time)
        print(self.name, self.input_values)

        for o in self.output_attributes:
            rv = random.random()
            print(self.name, o, ':', rv)
            self.update_attribute(o, rv)
        print('=============')


if __name__ == "__main__":

    a = ClientTestNode('localhost', 'obnl_vhost', 'obnl', 'obnl', 'test/data/A.json',
                       output_attributes=['ta'], input_attributes=['seta'], is_first=True)
    b = ClientTestNode('localhost', 'obnl_vhost', 'obnl', 'obnl', 'test/data/B.json',
                       output_attributes=['tb'])
    c = ClientTestNode('localhost', 'obnl_vhost', 'obnl', 'obnl', 'test/data/C.json',
                       input_attributes=['t1', 't2'], output_attributes=['setc'])

    a.start()
    b.start()
    c.start()

@@ -161,32 +161,55 @@
 d, config_file,%0A
+                 data,%0A
                 
@@ -273,16 +273,16 @@
 False):%0A
-
         
@@ -479,16 +479,62 @@
 g.DEBUG)
+%0A        self._data = data%0A        self._i = 0
 %0A%0A    de
@@ -797,23 +797,39 @@
 v = 
-random.random()
+self._data%5B0 %25 len(self._data)%5D
 %0A   
@@ -968,16 +968,108 @@
 in__%22:%0A%0A
+    data_a = %5B1, 2, 3, 4%5D%0A%0A    data_b = %5B1.1, 2.2, 3.3, 4.4, 5.5%5D%0A%0A    data_c = %5B0.1, 0.2%5D%0A%0A
     a = 
@@ -1138,32 +1138,63 @@
 t/data/A.json',%0A
+                       data_a,%0A
                 
@@ -1346,32 +1346,63 @@
 t/data/B.json',%0A
+                       data_b,%0A
                 
@@ -1434,16 +1434,16 @@
 %5B'tb'%5D)%0A
-
     c = 
@@ -1512,32 +1512,63 @@
 t/data/C.json',%0A
+                       data_c,%0A
                 

update test to add init value at creation