Exemple #1
0
class TestNetworkApi(TestPyZWave):
    @classmethod
    def setUpClass(self):
        super(TestNetworkApi, self).setUpClass()
        self.options = None
        self.network = None

    @classmethod
    def tearDownClass(self):
        if self.network is not None:
            self.network.stop()
            self.network = None
        super(TestNetworkApi, self).tearDownClass()

    def test_000_api_network(self):
        self.touchFile("ttyUSBO_fake")
        self.options = ZWaveOption(device="ttyUSBO_fake", user_path=self.userpath)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("Debug")
        self.options.set_logging(True)
        self.options.lock()
        self.network = ZWaveNetwork(self.options, autostart=False)
        self.rmFile("ttyUSBO_fake")

    def test_900_api_singleton(self):
        self.skipPython3()

        class SingletonTest(object):
            __metaclass__ = Singleton

        s1 = SingletonTest()
        s2 = SingletonTest()
        self.assertIs(s1, s2)

    def test_905_network_singleton(self):
        self.skipPython3()
        self.touchFile("ttyUSBO_fake")
        self.options = ZWaveOptionSingleton(device="ttyUSBO_fake", user_path=self.userpath)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("Debug")
        self.options.set_logging(True)
        self.options.lock()
        options2 = ZWaveOptionSingleton(device="ttyUSBO_fake", user_path=self.userpath)
        self.assertIs(self.options, options2)
        self.network = ZWaveNetworkSingleton(self.options, autostart=False)
        network2 = ZWaveNetworkSingleton(self.options, autostart=False)
        self.assertIs(self.network, network2)
        self.rmFile("ttyUSBO_fake")
Exemple #2
0
class TestNetworkApi(TestPyZWave):
    @classmethod
    def setUpClass(self):
        super(TestNetworkApi, self).setUpClass()
        self.options = None
        self.network = None

    @classmethod
    def tearDownClass(self):
        if self.network is not None:
            self.network.stop()
            self.network = None
        super(TestNetworkApi, self).tearDownClass()

    def test_000_api_network(self):
        self.touchFile('ttyUSBO_fake')
        self.options = ZWaveOption(device='ttyUSBO_fake',
                                   user_path=self.userpath)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("Debug")
        self.options.set_logging(True)
        self.options.lock()
        self.network = ZWaveNetwork(self.options, autostart=False)
        self.rmFile('ttyUSBO_fake')

    def test_900_api_singleton(self):
        class SingletonTest(object):
            __metaclass__ = Singleton

        s1 = SingletonTest()
        s2 = SingletonTest()
        self.assertIs(s1, s2)

    def test_905_network_singleton(self):
        self.touchFile('ttyUSBO_fake')
        self.options = ZWaveOptionSingleton(device='ttyUSBO_fake',
                                            user_path=self.userpath)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("Debug")
        self.options.set_logging(True)
        self.options.lock()
        options2 = ZWaveOptionSingleton(device='ttyUSBO_fake',
                                        user_path=self.userpath)
        self.assertIs(self.options, options2)
        self.network = ZWaveNetworkSingleton(self.options, autostart=False)
        network2 = ZWaveNetworkSingleton(self.options, autostart=False)
        self.assertIs(self.network, network2)
        self.rmFile('ttyUSBO_fake')
class TestNetworkStartStop(TestPyZWave):

    @classmethod
    def setUpClass(self):
        super(TestNetworkStartStop, self).setUpClass()
        self.options = None
        self.network = None

    @classmethod
    def tearDownClass(self):
        if self.network is not None:
            self.network.stop()
            self.network.destroy()
            self.network = None
        super(TestNetworkStartStop, self).tearDownClass()

    def driver_ready_message(self, network, controller):
        self.driver_ready = True

    def driver_removed_message(self, network):
        self.driver_removed = True

    def network_started_message(self, network):
        self.driver_removed = True

    def network_stopped_message(self, network):
        self.driver_removed = True

    def test_000_network_start_stop(self):
        self.driver_ready = False
        self.driver_removed = False
        self.options = ZWaveOption(device=self.device, user_path=self.userpath)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("Debug")
        self.options.set_logging(True)
        self.options.lock()
        dispatcher.connect(self.driver_ready_message, ZWaveNetwork.SIGNAL_DRIVER_READY)
        dispatcher.connect(self.driver_removed_message, ZWaveNetwork.SIGNAL_DRIVER_REMOVED)
        self.network = ZWaveNetwork(self.options)
        for i in range(0, SLEEP):
            if self.network.state>=self.network.STATE_AWAKED:
                break
            else:
                time.sleep(1.0)
        self.assertTrue(self.driver_ready)
        self.network.stop()
        for i in range(0, SLEEP):
            if self.network.state==self.network.STATE_STOPPED:
                break
            else:
                time.sleep(1.0)
        self.assertEqual(self.network.state, self.network.STATE_STOPPED)
        #self.assertTrue(self.driver_removed)

    def test_010_network_start_stop_start_stop(self):
        self.driver_ready = False
        self.driver_removed = False
        self.options = ZWaveOption(device=self.device, user_path=self.userpath)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("Debug")
        self.options.set_logging(True)
        self.options.lock()
        dispatcher.connect(self.driver_ready_message, ZWaveNetwork.SIGNAL_DRIVER_READY)
        dispatcher.connect(self.driver_removed_message, ZWaveNetwork.SIGNAL_DRIVER_REMOVED)
        dispatcher.connect(self.driver_ready_message, ZWaveNetwork.SIGNAL_NETWORK_STARTED)
        dispatcher.connect(self.driver_removed_message, ZWaveNetwork.SIGNAL_DRIVER_REMOVED)
        self.network = ZWaveNetwork(self.options)
        for i in range(0, SLEEP):
            if self.network.state>=self.network.STATE_STARTED:
                break
            else:
                time.sleep(0.1)
        self.network.stop()
        for i in range(0, SLEEP*10):
            if self.network.state==self.network.STATE_STOPPED:
                break
            else:
                time.sleep(0.1)
        self.assertEqual(self.network.state, self.network.STATE_STOPPED)
        self.network.start()
        for i in range(0, SLEEP*10):
            if self.network.state>=self.network.STATE_STARTED:
                break
            else:
                time.sleep(0.1)
        self.network.stop()
        for i in range(0, SLEEP*10):
            if self.network.state==self.network.STATE_STOPPED:
                break
            else:
                time.sleep(0.1)
        self.assertEqual(self.network.state, self.network.STATE_STOPPED)
        #self.assertTrue(self.driver_removed)

    def test_100_network_start_stop_singleton(self):
        self.wipTest()
        self.driver_ready = False
        self.driver_removed = False
        self.options = ZWaveOptionSingleton(device=self.device, user_path=self.userpath)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("Debug")
        self.options.set_logging(True)
        self.options.lock()
        dispatcher.connect(self.driver_ready_message, ZWaveNetwork.SIGNAL_DRIVER_READY)
        dispatcher.connect(self.driver_removed_message, ZWaveNetwork.SIGNAL_DRIVER_REMOVED)
        self.network = ZWaveNetworkSingleton(self.options)
        for i in range(0, SLEEP):
            if self.network.state>=self.network.STATE_AWAKED:
                break
            else:
                time.sleep(1.0)
        self.assertTrue(self.driver_ready)
        network2 = ZWaveNetworkSingleton(self.options, autostart=False)
        self.assertIs(self.network, network2)
        self.network.stop()
        for i in range(0, SLEEP):
            if self.network.state==self.network.STATE_STOPPED:
                break
            else:
                time.sleep(1.0)
        self.assertEqual(self.network.state, self.network.STATE_STOPPED)
class TestNetworkStartStop(TestPyZWave):
    @classmethod
    def setUpClass(self):
        super(TestNetworkStartStop, self).setUpClass()
        self.options = None
        self.network = None

    @classmethod
    def tearDownClass(self):
        if self.network is not None:
            self.network.stop()
            self.network.destroy()
            self.network = None
        super(TestNetworkStartStop, self).tearDownClass()

    def driver_ready_message(self, network, controller):
        self.driver_ready = True

    def driver_removed_message(self, network):
        self.driver_removed = True

    def network_started_message(self, network):
        self.driver_removed = True

    def network_stopped_message(self, network):
        self.driver_removed = True

    def test_000_network_start_stop(self):
        self.driver_ready = False
        self.driver_removed = False
        self.options = ZWaveOption(device=self.device, user_path=self.userpath)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("Debug")
        self.options.set_logging(True)
        self.options.lock()
        dispatcher.connect(self.driver_ready_message,
                           ZWaveNetwork.SIGNAL_DRIVER_READY)
        dispatcher.connect(self.driver_removed_message,
                           ZWaveNetwork.SIGNAL_DRIVER_REMOVED)
        self.network = ZWaveNetwork(self.options)
        for i in range(0, SLEEP):
            if self.network.state >= self.network.STATE_AWAKED:
                break
            else:
                time.sleep(1.0)
        self.assertTrue(self.driver_ready)
        self.network.stop()
        for i in range(0, SLEEP):
            if self.network.state == self.network.STATE_STOPPED:
                break
            else:
                time.sleep(1.0)
        self.assertEqual(self.network.state, self.network.STATE_STOPPED)
        #self.assertTrue(self.driver_removed)

    def test_010_network_start_stop_start_stop(self):
        self.driver_ready = False
        self.driver_removed = False
        self.options = ZWaveOption(device=self.device, user_path=self.userpath)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("Debug")
        self.options.set_logging(True)
        self.options.lock()
        dispatcher.connect(self.driver_ready_message,
                           ZWaveNetwork.SIGNAL_DRIVER_READY)
        dispatcher.connect(self.driver_removed_message,
                           ZWaveNetwork.SIGNAL_DRIVER_REMOVED)
        dispatcher.connect(self.driver_ready_message,
                           ZWaveNetwork.SIGNAL_NETWORK_STARTED)
        dispatcher.connect(self.driver_removed_message,
                           ZWaveNetwork.SIGNAL_DRIVER_REMOVED)
        self.network = ZWaveNetwork(self.options)
        for i in range(0, SLEEP):
            if self.network.state >= self.network.STATE_STARTED:
                break
            else:
                time.sleep(0.1)
        self.network.stop()
        for i in range(0, SLEEP * 10):
            if self.network.state == self.network.STATE_STOPPED:
                break
            else:
                time.sleep(0.1)
        self.assertEqual(self.network.state, self.network.STATE_STOPPED)
        self.network.start()
        for i in range(0, SLEEP * 10):
            if self.network.state >= self.network.STATE_STARTED:
                break
            else:
                time.sleep(0.1)
        self.network.stop()
        for i in range(0, SLEEP * 10):
            if self.network.state == self.network.STATE_STOPPED:
                break
            else:
                time.sleep(0.1)
        self.assertEqual(self.network.state, self.network.STATE_STOPPED)
        #self.assertTrue(self.driver_removed)

    def test_100_network_start_stop_singleton(self):
        self.wipTest()
        self.driver_ready = False
        self.driver_removed = False
        self.options = ZWaveOptionSingleton(device=self.device,
                                            user_path=self.userpath)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("Debug")
        self.options.set_logging(True)
        self.options.lock()
        dispatcher.connect(self.driver_ready_message,
                           ZWaveNetwork.SIGNAL_DRIVER_READY)
        dispatcher.connect(self.driver_removed_message,
                           ZWaveNetwork.SIGNAL_DRIVER_REMOVED)
        self.network = ZWaveNetworkSingleton(self.options)
        for i in range(0, SLEEP):
            if self.network.state >= self.network.STATE_AWAKED:
                break
            else:
                time.sleep(1.0)
        self.assertTrue(self.driver_ready)
        network2 = ZWaveNetworkSingleton(self.options, autostart=False)
        self.assertIs(self.network, network2)
        self.network.stop()
        for i in range(0, SLEEP):
            if self.network.state == self.network.STATE_STOPPED:
                break
            else:
                time.sleep(1.0)
        self.assertEqual(self.network.state, self.network.STATE_STOPPED)