# HG changeset patch # User Edouard Tisserant # Date 1592295141 -7200 # Node ID 3ca5611d63080852814dc7c2ef8a66f682aec6ff # Parent a8975ff44cd1f1f5e19c89c99875a0bf33e16da2 Modbus: Delete stored configuration when identical to default configuration. diff -r a8975ff44cd1 -r 3ca5611d6308 modbus/web_settings.py --- a/modbus/web_settings.py Mon Jun 15 14:34:00 2020 +0200 +++ b/modbus/web_settings.py Tue Jun 16 10:12:21 2020 +0200 @@ -215,21 +215,29 @@ def _SetSavedConfiguration(WebNode_id, newConfig): """ Stores a dictionary in a persistant file containing the Modbus parameter configuration """ - - # Add the addr_type and node_type to the data that will be saved to file - # This allows us to confirm the saved data contains the correct addr_type - # when loading from file - save_info = {} - save_info["addr_type"] = _WebNodeList[WebNode_id]["addr_type"] - save_info["node_type"] = _WebNodeList[WebNode_id]["node_type"] - save_info["config" ] = newConfig - - filename = _WebNodeList[WebNode_id]["filename"] - - with open(os.path.realpath(filename), 'w') as f: - json.dump(save_info, f, sort_keys=True, indent=4) + WebNode_entry = _WebNodeList[WebNode_id] + + if WebNode_entry["DefaultConfiguration"] == newConfig: + + _DelSavedConfiguration(WebNode_id) + WebNode_entry["SavedConfiguration"] = None + + else: + + # Add the addr_type and node_type to the data that will be saved to file + # This allows us to confirm the saved data contains the correct addr_type + # when loading from file + save_info = {} + save_info["addr_type"] = ["addr_type"] + save_info["node_type"] = WebNode_entry["node_type"] + save_info["config" ] = newConfig - _WebNodeList[WebNode_id]["SavedConfiguration"] = newConfig + filename = WebNode_entry["filename"] + + with open(os.path.realpath(filename), 'w') as f: + json.dump(save_info, f, sort_keys=True, indent=4) + + WebNode_entry["SavedConfiguration"] = newConfig