MQTT: Fix crash when browsing locations
authorEdouard Tisserant <edouard@beremiz.fr>
Thu, 18 Jul 2024 11:28:38 +0200
changeset 3991 28354ba489b9
parent 3990 24656e0e8732
child 3992 056657cd1484
MQTT: Fix crash when browsing locations
mqtt/client.py
--- a/mqtt/client.py	Wed Jul 17 17:02:32 2024 +0200
+++ b/mqtt/client.py	Thu Jul 18 11:28:38 2024 +0200
@@ -137,24 +137,33 @@
         current_location = self.GetCurrentLocation()
         locstr = "_".join(map(str, current_location))
         name = self.BaseParams.getName()
+
         entries = []
-        for direction, data in self.modeldata.iteritems():
-            iec_direction_prefix = {"input": "__I", "output": "__Q"}[direction]
-            for row in data:
-                dname, ua_nsidx, ua_nodeid_type, _ua_node_id, ua_type, iec_number = row
-                iec_type, C_type, iec_size_prefix, ua_type_enum, ua_type = MQTT_IEC_types[ua_type]
-                c_loc_name = iec_direction_prefix + iec_size_prefix + locstr + "_" + str(iec_number)
-                entries.append({
-                    "name": dname,
-                    "type": {"input": LOCATION_VAR_INPUT, "output": LOCATION_VAR_OUTPUT}[direction],
-                    "size": {"X":1, "B":8, "W":16, "D":32, "L":64}[iec_size_prefix],
-                    "IEC_type": iec_type,
-                    "var_name": c_loc_name,
-                    "location": iec_size_prefix + ".".join([str(i) for i in current_location]) + "." + str(iec_number),
-                    "description": "",
-                    "children": []})
+        children = []
+
+        for row in self.modeldata["output"]:
+            Topic, QoS, _Retained, iec_type, iec_number = row
+            entries.append((Topic, QoS, iec_type, iec_number, "Q", LOCATION_VAR_OUTPUT))
+
+        for row in self.modeldata["input"]:
+            Topic, QoS, iec_type, iec_number = row
+            entries.append((Topic, QoS, iec_type, iec_number, "I", LOCATION_VAR_INPUT))
+
+        for Topic, QoS, iec_type, iec_number, iec_dir_prefix, loc_type in entries:
+            C_type, iec_size_prefix = MQTT_IEC_types[iec_type]
+            c_loc_name = "__" + iec_dir_prefix + iec_size_prefix + locstr + "_" + str(iec_number)
+            children.append({
+                "name": Topic,
+                "type": loc_type,
+                "size": {"X":1, "B":8, "W":16, "D":32, "L":64}[iec_size_prefix],
+                "IEC_type": iec_type,
+                "var_name": c_loc_name,
+                "location": "%" + iec_dir_prefix + iec_size_prefix + ".".join([str(i) for i in current_location]) + "." + str(iec_number),
+                "description": "",
+                "children": []})
+
         return {"name": name,
                 "type": LOCATION_CONFNODE,
                 "location": ".".join([str(i) for i in current_location]) + ".x",
-                "children": entries}
+                "children": children}