Modbus: Delete stored configuration when identical to default configuration.
authorEdouard Tisserant
Tue, 16 Jun 2020 10:12:21 +0200
changeset 2675 3ca5611d6308
parent 2674 a8975ff44cd1
child 2676 b276d05bdb09
Modbus: Delete stored configuration when identical to default configuration.
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