def _create_new_test_preset(self, name="Test Preset"): test_preset_dict = self.load_json_file("presets/preset-0.json") self.assertIsNotNone(test_preset_dict) test_preset = Preset(test_preset_dict) test_preset.auto_save = False test_preset.name = name return test_preset
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)
def get_preset(self, memory_slot_number): # First, load the indicies and see if in fact this is mapped. If not, don't bother even trying preset_index = self.get_full_preset_list() if preset_index.index_of_preset_with_memory_slot_number(memory_slot_number) is None: message = "there is no preset mapped to slot number {0}".format(memory_slot_number) raise ObjectNotFoundException(message) result = self.select_memory_program(memory_slot_number) # use-flag -> channel mode vars1 = ReadDataSegment(self.charger, "vars1", "H38sLBB7cHB", base=0x8c00) # save to sd -> bal-set-point vars2 = ReadDataSegment(self.charger, "vars2", "BHH12BHBBB", prev_format=vars1) # bal-delay, keep-charge-enable -> reg discharge mode vars3 = ReadDataSegment(self.charger, "vars3", "BB14H", prev_format=vars2) # ni-peak -> cycle-delay vars4 = ReadDataSegment(self.charger, "vars4", "16H", prev_format=vars3) # cycle-mode -> ni-zn-cell vars5 = ReadDataSegment(self.charger, "vars5", "B6HB2HB3HB", prev_format=vars4) preset = Preset.modbus(memory_slot_number, vars1, vars2, vars3, vars4, vars5) # if preset.is_unused: # message = "Preset in slot {0} appears to exist, is marked as unused.".format(memory_slot_number) # raise ObjectNotFoundException(message) return preset
def put(self): json_dict = request.json # Turn it into a Preset object preset = Preset(json_dict) logger.info("Asked to add a new preset: {0}".format(json_dict)) return comms.add_new_preset(preset).to_native()
def put(self, preset_memory_slot): preset_memory_slot = int(preset_memory_slot) json_dict = request.json # Turn it into a Preset object preset = Preset(json_dict) logger.info("Asked to save preset to mem slot: {0} with {1}".format( preset_memory_slot, json_dict)) return comms.save_preset_to_memory_slot(preset, preset_memory_slot)
def _turn_response_into_preset_list(self, response): json_dict = json.loads(response.data) if type(json_dict) is not list: message = "{0} isn't a list!".format(json_dict) raise Exception(message) list_of_presets = [] for item in json_dict: list_of_presets.append(Preset(item)) return list_of_presets
def test_can_reconstruct_preset_from_json(self): preset_data = self.load_json_file("presets/preset-0.json") p = Preset(preset_data) self.assertEqual(p['lipo_storage_cell_voltage'], p.lipo_storage_cell_voltage) self.assertEqual(p['end_charge'], p.end_charge) self.assertEqual(p['ni_discharge_voltage'], p.ni_discharge_voltage) self.assertEqual(p['pb_cell'], p.pb_cell) self.assertEqual(p['safety_cap_c'], p.safety_cap_c) self.assertEqual(p['safety_cap_d'], p.safety_cap_d) self.assertEqual(p['lilo_storage_cell_voltage'], p.lilo_storage_cell_voltage) self.assertEqual(p['fast_store'], p.fast_store)
def test_preset_op_enable_mask(self): p = Preset() p.op_enable_mask = 255 self.assertTrue(p.charge_enabled) self.assertTrue(p.storage_enabled) self.assertTrue(p.discharge_enabled) self.assertTrue(p.cycle_enabled) self.assertTrue(p.balance_enabled) p.charge_enabled = False self.assertEquals(p.op_enable_mask, 254) p.discharge_enabled = False self.assertEquals(p.op_enable_mask, 246) p.storage_enabled = False self.assertEquals(p.op_enable_mask, 242) p.cycle_enabled = False self.assertEquals(p.op_enable_mask, 226) p.balance_enabled = False self.assertEquals(p.op_enable_mask, 194)