def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.upb = UPB(self.ms) else: self.serial = Serial('/dev/ttyUSB0', 4800) self.upb = UPB(self.serial)
def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.sg = Stargate(self.ms) else: self.serial = Serial('/dev/ttyUSB0', 2400) self.sg = Stargate(self.serial)
class InsteonInterfaceTests(TestCase): useMock = True def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.insteon = InsteonPLM(self.ms) else: # If we are running live, the insteon interface doesnt like to be bombarded with requests # time.sleep(3) # self.serial = Serial('/dev/ttyUSB0', 4800) # self.insteon = InsteonPLM(self.serial) self.tcp = TCP('192.168.13.146', 9761) self.insteon = InsteonPLM(self.tcp) #self.insteon.start() def tearDown(self): self.insteon.shutdown() self.serial = None try: self.tcp.shutdown() self.tcp = None except: pass def test_instantiation(self): self.assertIsNotNone(self.insteon, 'Insteon interface could not be instantiated') def test_get_firmware_version(self): """ >0000 02 60 .` <0000 02 60 16 F9 EC 03 05 92 06 .`....... """ self.ms.add_response({Conversions.hex_to_ascii('0260'): Conversions.hex_to_ascii('026016F9EC03059206')}) info = self.insteon.getPLMInfo() self.assertEqual(info['firmwareVersion'], "92") #select.select([], [], []) def test_device_on(self): """ Transmit> 0000 02 62 19 05 7B 0F 11 FF .b..{... < 0000 02 62 19 05 7B 0F 11 FF 06 .b..{.... < 0000 02 50 19 05 7B 16 F9 EC 2B 11 FF .P..{...+.. """ self.ms.add_response({Conversions.hex_to_ascii('026219057B0F11FF'): Conversions.hex_to_ascii('026219057B0F11FF06') + \ Conversions.hex_to_ascii('025019057B16F9EC2B11FF')}) response = self.insteon.on('19.05.7b') #time.sleep(4000) self.assertEqual(response, True) def test_insteon_level(self): response = self.insteon.l40('19.05.7b') self.assertEqual(response, False)
def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.insteon = InsteonPLM(self.ms) else: # If we are running live, the insteon interface doesnt like to be bombarded with requests # time.sleep(3) # self.serial = Serial('/dev/ttyUSB0', 4800) # self.insteon = InsteonPLM(self.serial) self.tcp = TCP('192.168.13.146', 9761) self.insteon = InsteonPLM(self.tcp)
def setUp(self): self.ms = MockInterface() self.serial = None if not self.useMock: # Use Mock Serial Port self.serial = Serial('/dev/ttyUSB0', 115200, rtscts=True) self.byvac = Bv4626(self.ms if self.useMock else self.serial, outputs='abefh', sockets='c') self.ms.add_response({'\015': '*'}) self.ms.add_response({'\033[72s': self.byvac.ACK})
class UPBInterfaceTests(TestCase): useMock = True def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.upb = UPB(self.ms) else: self.serial = Serial('/dev/ttyUSB0', 4800) self.upb = UPB(self.serial) #self.upb.start() def tearDown(self): self.upb.shutdown() self.serial = None def test_instantiation(self): self.assertIsNotNone(self.upb, 'UPB interface could not be instantiated') def test_get_firmware_version(self): # What will be written / what should we get back self.ms.add_response({'\x120202FC\x0D': 'PR021234\x0D'}) response = self.upb.get_register(2, 2) self.assertEqual(response, '1234') # if self.useMock: # self.assertEqual(self.ms._written, '\x120202FC\x0D') #sit and spin, let the magic happen #select.select([], [], []) def test_device_on(self): """ UPBPIM, myPIM, 49, 0x1B08, 30 UPBD, upb_foyer, myPIM, 49, 3 Response> Foyer Light On 0000 50 55 30 38 31 30 33 31 PU081031 0008 30 33 31 45 32 32 36 34 031E2264 0010 31 30 0D 10. """ self.ms.add_response({'\x14081031031E226410\x0D': 'PA\x0D'}) # Network / Device ID response = self.upb.on((49, 3)) self.assertTrue(response) def test_device_status(self): """ UPBPIM, myPIM, 49, 0x1B08, 30 UPBD, upb_foyer, myPIM, 49, 3 Response> Foyer Light On 0000 50 55 30 38 31 30 33 31 PU081031 0008 30 33 31 45 32 32 36 34 031E2264 0010 31 30 0D 10. """ #071031031E3067 self.ms.add_response({'\x14071031031E3067\x0D': 'PA\x0D'}) # Network / Device ID response = self.upb.status((49, 3)) self.assertTrue(response) def test_update_status(self): device = Mock() device.address.return_value ='a1' self.upb.update_status(); def test_multiple_commands_at_same_time(self): """ Response> 0000 50 55 30 38 31 30 33 31 PU081031 0008 31 32 31 45 32 32 30 30 121E2200 0010 36 35 0D 50 55 30 38 31 65.PU081 0018 30 33 31 31 32 31 45 32 031121E2 0020 32 30 30 36 35 0D 20065. """ def test_incoming_on(self): """ UBP New: PU0804310006860037:0000 50 55 30 38 30 34 33 31 PU080431 0008 30 30 30 36 38 36 30 30 00068600 0010 33 37 37 UBP New: PU0805310006860036:0000 50 55 30 38 30 35 33 31 PU080531 0008 30 30 30 36 38 36 30 30 00068600 0010 33 36 36 """ m_interface = Mock() m_interface.read.return_value = '' upb = UPB(m_interface) m_interface.callback.return_value = True upb.onCommand(address=(49,6), callback=m_interface.callback) m_interface.read.return_value = 'PU0805310006860036' # time.sleep(4000) time.sleep(2) m_interface.callback.assert_called_with(address=(49,6), command=State.OFF, source=upb) m_interface.read.return_value = '' def test_incoming_link(self): """ UBP New Response: PU8A0431260F20FFFFFFEF UPBN:49:15:38:20 """ m_interface = Mock() m_interface.callback.return_value = True m_interface.read.return_value = '' upb = UPB(m_interface) upb.onCommand(address=(49,38,'L'), callback=m_interface.callback) m_interface.read.return_value = 'PU8A0431260F20FFFFFFEF' # time.sleep(4000) time.sleep(2) m_interface.callback.assert_called_with(address=(49,38,'L'), command=State.ON, source=upb) m_interface.read.return_value = '' def test_incoming_k(self): """ 0000 50 55 30 37 31 34 31 36 PU071416 0008 31 30 46 46 33 30 39 30 10FF3090 0010 0D 50 55 30 37 31 35 31 .PU07151 0018 36 31 30 46 46 33 30 38 610FF308 0020 46 0D F. """ m_interface = Mock() m_interface.callback.return_value = True m_interface.read.return_value = '' upb = UPB(m_interface) upb.onCommand(address=(22,255), callback=m_interface.callback) m_interface.read.return_value = "PU07141610FF3090\x0DPU07151610FF308F\x0D" # time.sleep(4000) time.sleep(2) m_interface.callback.assert_called_with(address=(22,255), command='status', source=upb) m_interface.read.return_value = '' def test_level(self): self.upb.l40((39, 4)) self.assertTrue(True) def test_level2(self): self.upb.level((39, 4), 40) self.assertTrue(True) def test_link_activate(self): """ """# self.ms.add_response({'\x14081031031E226410\x0D': 'PA\x0D'}) self.ms.add_response({'\x14871031031E20F7\x0D': 'PA\x0D'}) # Network / Device ID response = self.upb.on((49, 3, "L")) self.assertTrue(response)
def setUp(self): # self.interface = WeMo( '192.168.13.141', '49153') self.interface = WeMo(MockInterface())
class Bv4626Tests(TestCase): useMock = True def setUp(self): self.ms = MockInterface() self.serial = None if not self.useMock: # Use Mock Serial Port self.serial = Serial('/dev/ttyUSB0', 115200, rtscts=True) self.byvac = Bv4626(self.ms if self.useMock else self.serial, outputs='abefh', sockets='c') self.ms.add_response({'\015': '*'}) self.ms.add_response({'\033[72s': self.byvac.ACK}) def tearDown(self): self.byvac.shutdown() self.serial = None def test_a_instantiation(self): self.assertIsNotNone(self.byvac, 'BV4626 interface could not be instantiated') def test_b_outputs(self): self.ms.add_response({'\033[' + self.byvac._modemCommands['turnOn'] + 'A': self.byvac.ACK}) self.ms.add_response({'\033[' + self.byvac._modemCommands['turnOff'] + 'A': self.byvac.ACK}) self.ms.add_response({'\033[' + self.byvac._modemCommands['turnOn'] + 'B': self.byvac.ACK}) self.ms.add_response({'\033[' + self.byvac._modemCommands['turnOff'] + 'B': self.byvac.ACK}) self.ms.add_response({'\033[255a': self.byvac.ACK}) self.ms.add_response({'\033[0a': self.byvac.ACK}) self.ms.add_response({'\033[255h': self.byvac.ACK}) self.ms.add_response({'\033[0h': self.byvac.ACK}) # Relay outputs response = self.byvac.on('A') self.assertTrue(response) self.serial and time.sleep(0.25) response = self.byvac.on('B') self.assertTrue(response) self.serial and time.sleep(0.5) response = self.byvac.off('A') self.assertTrue(response) self.serial and time.sleep(0.25) response = self.byvac.off('B') self.assertTrue(response) response = self.byvac.on('C') self.assertFalse(response) # I/O or Switch Outputs response = self.byvac.on('a') self.assertTrue(response) self.serial and time.sleep(0.25) response = self.byvac.on('h') self.assertTrue(response) self.serial and time.sleep(0.5) response = self.byvac.off('a') self.assertTrue(response) self.serial and time.sleep(0.25) response = self.byvac.off('h') self.assertTrue(response) response = self.byvac.on('c') self.assertFalse(response) # I/O mapped Maplin Wireless Sockets response = self.byvac.on('a44') self.assertFalse(response) response = self.byvac.on('c11') self.assertTrue(response) self.serial and time.sleep(0.5) response = self.byvac.off('c11') self.assertTrue(response) def test_c_get_device_id(self): # What will be written / what should we get back self.ms.add_response({'\033['+self.byvac._modemCommands['getDeviceId']: '4626'+self.byvac.ACK}) response = self.byvac.getDeviceId() self.assertEqual(response, '4626') def test_d_get_firmware_version(self): # What will be written / what should we get back self.ms.add_response({'\033['+self.byvac._modemCommands['getFirmwareVersion']: '12'+self.byvac.ACK}) response = self.byvac.getFirmwareVersion() self.assertEqual(response, '12')
class StargateInterfaceTests(TestCase): useMock = True def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.sg = Stargate(self.ms) else: self.serial = Serial('/dev/ttyUSB0', 2400) self.sg = Stargate(self.serial) #self.sg.start() def tearDown(self): self.sg.shutdown() self.serial = None def test_instantiation(self): self.assertIsNotNone(self.sg, 'SG interface could not be instantiated') def test_digital_input(self): """ digital input #1 ON !!07/01083237a0fe digital input #1 OFF !!07/01083239a0ff """ """ 0000 21 21 30 38 2F 30 31 30 !!08/010 0008 38 31 39 33 30 61 30 66 81930a0f 0010 65 e """ # What will be written / what should we get back self.ms.add_response({'##%1d\r': '!!07/01083237a001\r\n'}) # Register delegate self.sg.onCommand(callback=self._digital_input_callback, address='D1') # resend EchoMode to trigger response self.sg.echoMode() time.sleep(3) self.assertEqual(self.__digital_input_params['kwargs']['address'].upper(), 'D8') def test_digital_input_multiple(self): """ 0000 21 21 30 38 2F 30 31 30 !!08/010 0008 37 38 38 30 37 61 30 66 78807a0f 0010 65 0D 0A 21 21 30 38 2F e..!!08/ 0018 30 31 30 37 38 38 30 37 01078807 0020 34 30 30 31 0D 0A 21 21 4001..!! 0028 30 38 2F 30 31 30 37 38 08/01078 0030 38 30 37 34 31 30 30 0D 8074100. 0038 0A . """ # What will be written / what should we get back self.ms.add_response({'##%1d\r': '!!07/01083237a001\r\n!!07/01083237a000\r\n'}) # Register delegate self.sg.onCommand(callback=self._digital_input_callback, address='D1') # resend EchoMode to trigger response self.sg.echoMode() time.sleep(1.5) self.assertEqual(self.__digital_input_params['kwargs']['address'].upper(), 'D1') def _digital_input_callback(self, *args, **kwargs): print "Args:" + str(args) + " Kwargs:" + str(kwargs) self.__digital_input_params = {'args': args, 'kwargs': kwargs}
class StargateInterfaceTests(TestCase): useMock = True def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.sg = Stargate(self.ms) else: self.serial = Serial('/dev/ttyUSB0', 2400) self.sg = Stargate(self.serial) #self.sg.start() def tearDown(self): self.sg.shutdown() self.serial = None def test_instantiation(self): self.assertIsNotNone(self.sg, 'SG interface could not be instantiated') def test_digital_input(self): """ digital input #1 ON !!07/01083237a0fe digital input #1 OFF !!07/01083239a0ff """ """ 0000 21 21 30 38 2F 30 31 30 !!08/010 0008 38 31 39 33 30 61 30 66 81930a0f 0010 65 e """ # What will be written / what should we get back self.ms.add_response({'##%1d\r': '!!07/01083237a001\r\n'}) # Register delegate self.sg.onCommand(callback=self._digital_input_callback, address='D1') # resend EchoMode to trigger response self.sg.echoMode() time.sleep(3) self.assertEqual( self.__digital_input_params['kwargs']['address'].upper(), 'D8') def test_digital_input_multiple(self): """ 0000 21 21 30 38 2F 30 31 30 !!08/010 0008 37 38 38 30 37 61 30 66 78807a0f 0010 65 0D 0A 21 21 30 38 2F e..!!08/ 0018 30 31 30 37 38 38 30 37 01078807 0020 34 30 30 31 0D 0A 21 21 4001..!! 0028 30 38 2F 30 31 30 37 38 08/01078 0030 38 30 37 34 31 30 30 0D 8074100. 0038 0A . """ # What will be written / what should we get back self.ms.add_response( {'##%1d\r': '!!07/01083237a001\r\n!!07/01083237a000\r\n'}) # Register delegate self.sg.onCommand(callback=self._digital_input_callback, address='D1') # resend EchoMode to trigger response self.sg.echoMode() time.sleep(1.5) self.assertEqual( self.__digital_input_params['kwargs']['address'].upper(), 'D1') def _digital_input_callback(self, *args, **kwargs): print("Args:" + str(args) + " Kwargs:" + str(kwargs)) self.__digital_input_params = {'args': args, 'kwargs': kwargs}
class UPBInterfaceTests(TestCase): useMock = True def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.upb = UPB(self.ms) else: self.serial = Serial('/dev/ttyUSB0', 4800) self.upb = UPB(self.serial) #self.upb.start() def tearDown(self): self.upb.shutdown() self.serial = None def test_instantiation(self): self.assertIsNotNone(self.upb, 'UPB interface could not be instantiated') def test_get_firmware_version(self): # What will be written / what should we get back self.ms.add_response({'\x120202FC\x0D': 'PR021234\x0D'}) response = self.upb.get_register(2, 2) self.assertEqual(response, '1234') # if self.useMock: # self.assertEqual(self.ms._written, '\x120202FC\x0D') #sit and spin, let the magic happen #select.select([], [], []) def test_device_on(self): """ UPBPIM, myPIM, 49, 0x1B08, 30 UPBD, upb_foyer, myPIM, 49, 3 Response> Foyer Light On 0000 50 55 30 38 31 30 33 31 PU081031 0008 30 33 31 45 32 32 36 34 031E2264 0010 31 30 0D 10. """ self.ms.add_response({'\x14081031031E226410\x0D': 'PA\x0D'}) # Network / Device ID response = self.upb.on((49, 3)) self.assertTrue(response) def test_device_status(self): """ UPBPIM, myPIM, 49, 0x1B08, 30 UPBD, upb_foyer, myPIM, 49, 3 Response> Foyer Light On 0000 50 55 30 38 31 30 33 31 PU081031 0008 30 33 31 45 32 32 36 34 031E2264 0010 31 30 0D 10. """ #071031031E3067 self.ms.add_response({'\x14071031031E3067\x0D': 'PA\x0D'}) # Network / Device ID response = self.upb.status((49, 3)) self.assertTrue(response) def test_update_status(self): device = Mock() device.address.return_value ='a1' self.upb.update_status(); def test_multiple_commands_at_same_time(self): """ Response> 0000 50 55 30 38 31 30 33 31 PU081031 0008 31 32 31 45 32 32 30 30 121E2200 0010 36 35 0D 50 55 30 38 31 65.PU081 0018 30 33 31 31 32 31 45 32 031121E2 0020 32 30 30 36 35 0D 20065. """ def test_incoming_on(self): """ UBP New: PU0804310006860037:0000 50 55 30 38 30 34 33 31 PU080431 0008 30 30 30 36 38 36 30 30 00068600 0010 33 37 37 UBP New: PU0805310006860036:0000 50 55 30 38 30 35 33 31 PU080531 0008 30 30 30 36 38 36 30 30 00068600 0010 33 36 36 """ m_interface = Mock() m_interface.read.return_value = '' upb = UPB(m_interface) m_interface.callback.return_value = True upb.onCommand(address=(49,6), callback=m_interface.callback) m_interface.read.return_value = 'PU0805310006860036' # time.sleep(4000) time.sleep(2) m_interface.callback.assert_called_with(address=(49,6), command=State.OFF, source=upb) m_interface.read.return_value = '' def test_incoming_link(self): """ UBP New Response: PU8A0431260F20FFFFFFEF UPBN:49:15:38:20 """ m_interface = Mock() m_interface.callback.return_value = True m_interface.read.return_value = '' upb = UPB(m_interface) upb.onCommand(address=(49,38,'L'), callback=m_interface.callback) m_interface.read.return_value = 'PU8A0431260F20FFFFFFEF' # time.sleep(4000) time.sleep(2) m_interface.callback.assert_called_with(address=(49,38,'L'), command=State.ON, source=upb) m_interface.read.return_value = '' def test_incoming_k(self): """ 0000 50 55 30 37 31 34 31 36 PU071416 0008 31 30 46 46 33 30 39 30 10FF3090 0010 0D 50 55 30 37 31 35 31 .PU07151 0018 36 31 30 46 46 33 30 38 610FF308 0020 46 0D F. """ m_interface = Mock() m_interface.callback.return_value = True m_interface.read.return_value = '' upb = UPB(m_interface) upb.onCommand(address=(22,255), callback=m_interface.callback) m_interface.read.return_value = "PU07141610FF3090\x0DPU07151610FF308F\x0D" # time.sleep(4000) time.sleep(2) m_interface.callback.assert_called_with(address=(22,255), command='status', source=upb) m_interface.read.return_value = '' def test_level(self): response = self.upb.l40((39, 4)) self.assertTrue(True) def test_level2(self): response = self.upb.level((39, 4), 40) self.assertTrue(True) def test_link_activate(self): """ """# self.ms.add_response({'\x14081031031E226410\x0D': 'PA\x0D'}) self.ms.add_response({'\x14871031031E20F7\x0D': 'PA\x0D'}) # Network / Device ID response = self.upb.on((49, 3, "L")) self.assertTrue(response)