Beispiel #1
0
 def test_find_board(self):
     """
     Test that the ThunderBorg.find_board() method finds a board.
     """
     found = ThunderBorg.find_board()
     found = found[0] if found else 0
     msg = "Found address '0x{:02X}', should be '0x{:02X}'.".format(
         found, ThunderBorg.DEFAULT_I2C_ADDRESS)
     self.assertEqual(found, ThunderBorg.DEFAULT_I2C_ADDRESS, msg)
Beispiel #2
0
 def test_set_i2c_address_without_current_address(self):
     """
     Test that the ThunderBorg.set_i2c_address() can set a different
     address. Scans address range to find current address.
     """
     # Set a new address
     new_addr = 0x70
     ThunderBorg.set_i2c_address(new_addr)
     found = ThunderBorg.find_board()
     found = found[0] if found else 0
     msg = "Found address '0x{:02X}', should be '0x{:02X}'.".format(
         found, new_addr)
     self.assertEqual(found, new_addr, msg)
Beispiel #3
0
 def test_set_i2c_address_with_current_address(self):
     """
     Test that the ThunderBorg.set_i2c_address() can set a different
     address. The current address is provided.
     """
     # Set a new address
     new_addr = 0x70
     cur_addr = ThunderBorg.DEFAULT_I2C_ADDRESS
     ThunderBorg.set_i2c_address(new_addr, cur_addr=cur_addr)
     found = ThunderBorg.find_board()
     found = found[0] if found else 0
     msg = "Found address '0x{:02X}', should be '0x{:02X}'.".format(
         found, new_addr)
     self.assertEqual(found, new_addr, msg)
Beispiel #4
0
 def test_find_address_with_invalid_default_address(self):
     """
     Test that an invalid default address will cause a board to be
     initialized if the `auto_set_addr` argument is `True`.
     """
     default_address = 0x15
     # Initialize the board by instantiating ThunderBorg.
     tb = ThunderBorg(logger_name=self.LOGGER_NAME,
                      log_level=logging.DEBUG,
                      auto_set_addr=True)
     boards = ThunderBorg.find_board()
     msg = "Boards found: {}".format(boards)
     self.assertEquals(ThunderBorg.DEFAULT_I2C_ADDRESS, 0x20, msg)
     self.assertTrue(len(boards) > 0, msg)
     self.assertEqual(boards[0], default_address, msg)