Beispiel #1
0
 def testLoadConfigWithDuplicate(self):
     c = Controller()
     try:
         c.loadConfig(os.path.join(os.path.dirname(__file__), 'testDuplicateDevice.json'))
         self.fail("Didn't throw an exception when adding a duplicated device ID")
     except DuplicateDeviceIDError as e:
         self.assertEqual("Device already exists: Duplicate", str(e))
Beispiel #2
0
    def testLoadConfig(self):
        c = Controller()
        c.loadConfig(os.path.join(os.path.dirname(__file__), 'testConfig.json'))

        self.assertTrue(c.hasDevice("Main"))
        self.assertTrue(c.hasDevice("Main Listener"))

        self.assertTrue(isinstance(c.getDevice("Main"), KramerVP88))
        self.assertTrue(isinstance(c.getDevice("Main Listener"), KramerVP88Listener))

        self.assertEqual("testController", c.controllerID)
Beispiel #3
0
    def testKramer602Listener(self):
        port = MockSerialPort()
        port.read = MagicMock(return_value=[
            chr(0x28), chr(0x81)
        ])  # Notification that input 1 sent to output 1

        k = Kramer602("Test", port)

        c = Controller()
        c.addDevice(k)
        kl = Kramer602Listener("TestListener", k.deviceID, c, machineNumber=1)

        dispatcher = NullDispatcher()
        dispatcher.updateOutputMappings = MagicMock()
        kl.registerDispatcher(dispatcher)
        kl.start()
        threading.Event().wait(0.1)
        kl.stop()

        dispatcher.updateOutputMappings.assert_called_with({'Test': {1: 1}})

        port = MockSerialPort()
        port.read = MagicMock(return_value=[
            chr(0x28), chr(0x8A)
        ])  # Notification that input 5 sent to output 2

        k = Kramer602("Test", port)
        c = Controller()
        c.addDevice(k)
        kl = Kramer602Listener("TestListener", k.deviceID, c, machineNumber=1)

        dispatcher = NullDispatcher()
        dispatcher.updateOutputMappings = MagicMock()
        kl.registerDispatcher(dispatcher)
        kl.start()
        threading.Event().wait(0.1)
        kl.stop()

        dispatcher.updateOutputMappings.assert_called_with({'Test': {2: 5}})
Beispiel #4
0
    def testCallRemoteController(self):
        master = Controller()
        slave = Controller()

        cp = ControllerProxy(master)

        self.PyroThread(master.daemon).start()
        self.PyroThread(slave.daemon).start()

        switcher = KramerVP88("Test", FakeSerialPort())
        switcher.sendInputToOutput = MagicMock(return_value=1)

        slave.addDevice(switcher)

        self.assertFalse(master.hasDevice("Test"))
        self.assertTrue(slave.hasDevice("Test"))

        master.slaves.append(slave)

        cp["Test"].sendInputToOutput(1, 2)
        switcher.sendInputToOutput.assert_called_once_with(1, 2)

        master.daemon.shutdown()
        slave.daemon.shutdown()
Beispiel #5
0
    def testSendControlSignalsToBlinds(self):
        c = Controller()
        cp = ControllerProxy(c)

        self.PyroThread(c.daemon).start()

        blinds = UpDownStopArray("Blinds", c)
        blinds.lower = MagicMock(return_value=0)
        blinds.raiseUp = MagicMock(return_value=0)
        blinds.stop = MagicMock(return_value=0)

        c.addDevice(blinds)

        cp["Blinds"].lower(1)
        blinds.lower.assert_called_once_with(1)

        cp["Blinds"].raiseUp(256)
        blinds.raiseUp.assert_called_once_with(256)

        cp["Blinds"].stop(1138)
        blinds.stop.assert_called_once_with(1138)
        c.daemon.shutdown()