Esempio n. 1
0
    def test_preset_index_with_all_presets_filled(self):
        p = PresetIndex()
        p.count = 64
        p.indexes = [num for num in range(0, 64)]

        # Should have 64 presets
        self.assertEqual(64, p.number_of_presets)

        # And no free slots
        self.assertIsNone(p.first_empty_index_position)
Esempio n. 2
0
 def test_throws_exception_if_index_out_of_range(self):
     p = PresetIndex()
     p.count = 4
     p.set_indexes([0, 1, 2, 3, 255])
     self.assertEqual(p.number_of_presets, 4)
     self.assertFalse(p.is_valid_index(4))
     self.assertFalse(p.is_valid_index(-1))
     self.assertTrue(p.is_valid_index(0))
     self.assertTrue(p.is_valid_index(1))
     self.assertTrue(p.is_valid_index(3))
Esempio n. 3
0
    def get_full_preset_list(self):
        (count,) = self.charger.modbus_read_registers(0x8800, "H", function_code=cst.READ_HOLDING_REGISTERS)

        # There are apparently 64 indexes. Apparently.
        read_a_bit_format = "32B"
        data_1 = self.charger.modbus_read_registers(0x8800 + 1, read_a_bit_format,
                                                    function_code=cst.READ_HOLDING_REGISTERS)
        data_2 = self.charger.modbus_read_registers(0x8800 + 16, read_a_bit_format,
                                                    function_code=cst.READ_HOLDING_REGISTERS)
        list_of_all_indexes = list(data_1)
        list_of_all_indexes.extend(list(data_2))

        return PresetIndex.modbus(count, list_of_all_indexes)
Esempio n. 4
0
    def test_adding_preset_modifies_both_index_and_preset(self):
        p = Preset()
        p.index = 123

        pi = PresetIndex()
        pi.set_indexes([0, 1, 2, 3, 255])

        pi.add_to_index(p)
        self.assertEqual(p.memory_slot, 4)
        self.assertEqual(pi.index_of_preset_with_memory_slot_number(4), 4)
        print "PI: {0}".format(pi.indexes)
Esempio n. 5
0
    def test_deleting_shuffles_indexes_left(self):
        p = PresetIndex()
        p.set_indexes([0, 1, 2, 3, 255])
        self.assertEqual(4, p.number_of_presets)

        expected_index_list = list(p.indexes)
        del expected_index_list[0]
        expected_index_list.append(255)

        # logger.info("Is now: {0}".format(p.indexes))
        p.delete_item_at_index(0)
        self.assertEqual(expected_index_list, p.indexes)
        self.assertEqual(3, p.number_of_presets)
Esempio n. 6
0
 def post(self):
     json_dict = request.json
     preset_list = PresetIndex(json_dict)
     return comms.save_full_preset_list(preset_list)
Esempio n. 7
0
    def test_preset_index_can_provide_next_available_slot(self):
        p = PresetIndex()
        p.set_indexes([0, 1, 2, 3, 255])
        self.assertEqual(4, p.next_available_memory_slot)

        p.set_indexes([0, 2, 8, 10, 255])
        self.assertEqual(1, p.next_available_memory_slot)

        p.set_indexes([1, 2, 8, 10, 255])
        self.assertEqual(0, p.next_available_memory_slot)

        p.set_indexes([1, 0, 2, 8, 10, 255])
        self.assertEqual(3, p.next_available_memory_slot)

        # Fill it up entirely
        p.set_indexes(list(range(0, 64)))
        self.assertIsNone(p.next_available_memory_slot)
Esempio n. 8
0
 def test_preset_index_filling_gives_us_64_items(self):
     p = PresetIndex()
     p.set_indexes([0, 255])
     self.assertEqual(1, p.number_of_presets)
     self.assertEqual(64, len(p.indexes))
Esempio n. 9
0
 def test_preset_indexes_are_swapped_ok(self):
     p = PresetIndex()
     p.count = 4
     p.indexes = [0, 1, 2, 3, 255]
     p.swap(0, 3)
     self.assertEqual([3, 1, 2, 0, 255], p.indexes)