Commit ff6e8ece82a768f8f067f5cfd4635d32dfa70b20

Authored by Patrick Maeght
1 parent 5716be60
Exists in dev

check captors config page

src/dashboard/templates/dashboard/config_weather.html
... ... @@ -16,28 +16,26 @@
16 16 <table class="table">
17 17 <thead>
18 18 <tr>
19   - <th>Device type</th>
20   - <th>Deice id </th>
21   - <th>value </th>
  19 + <th>device_name</th>
  20 + <th>device_type</th>
  21 + <th>serial_number</th>
  22 + <th>valid</th>
  23 + <th>name</th>
  24 + <th>type</th>
22 25 <th>Select </th>
23 26 </tr>
24 27 </thead>
25 28 <tbody>
26   - {% for key1, value1 in weather_config.items %}
27   - <tr>
28   - <td>{{key1}}</td>
29   - <td></td>
30   - <td></td>
31   - <td></td
  29 + {% for line in weather_config%}
  30 + <tr class="info">
  31 + <td>{{line.0}}</td>
  32 + <td>{{line.1}}</td>
  33 + <td>{{line.2}}</td>
  34 + <td>{{line.3}}</td>
  35 + <td>{{line.4}}</td>
  36 + <td>{{line.5}}</td>
  37 + <td><input class="form-check-input" name="{{line.4}}" value="{{line.6}}" checked="" type="radio"></td>
32 38 </tr>
33   - {% for key2, value2 in value1.items %}
34   - <tr class="info">
35   - <td></td>
36   - <td>{{key2}}</td>
37   - <td>{{value2}}</td>
38   - <td><input class="form-check-input" name="{{key1}}" id="{{key1}}/{{key2}}" value="{{key1}}/{{key2}}" checked="" type="radio"></td>
39   - </tr>
40   - {% endfor %}
41 39 {% endfor %}
42 40 </tbody>
43 41 </table>
... ...
src/dashboard/views.py
... ... @@ -181,7 +181,7 @@ def weather_config(request):
181 181 plc_checker = PlcChecker()
182 182 #plc_checker.scan_sensors()
183 183 # Return template with sensors list
184   - return render(request, 'dashboard/config_weather.html', {'weather_config' : plc_checker.captors_conf, 'base_template' : "base.html"})
  184 + return render(request, 'dashboard/config_weather.html', {'weather_config' : plc_checker.captors_table, 'base_template' : "base.html"})
185 185 except Config.DoesNotExist:
186 186 return render(request, 'dashboard/config_weather.html', {'weather_info' : None})
187 187  
... ...
src/monitoring/plc_checker.py
... ... @@ -13,8 +13,6 @@ class PlcChecker(object):
13 13 self.struct = None
14 14 self.path_list = None
15 15 # self.plc_global = copy.copy(self.struct["devices"])
16   - #
17   - self.load_config()
18 16 self.device_name = None
19 17 self.device_type = None
20 18 self.serial_number = None
... ... @@ -33,11 +31,12 @@ class PlcChecker(object):
33 31 ]
34 32 self.captors_conf = {}
35 33 self.captors_table = []
  34 + self.load_config()
36 35  
37 36 def load_config(self):
38 37 try:
39 38 colibri_json = open("./monitoring/plc_config.json")
40   - self.struct = json.load(colibri_json)
  39 + self.captors_table = json.load(colibri_json)
41 40 logger.info("Loaded : plc_config.json")
42 41 colibri_json.close
43 42 except:
... ... @@ -46,7 +45,7 @@ class PlcChecker(object):
46 45 def save_config(self):
47 46 #try:
48 47 _file = open("./monitoring/plc_config.json" , 'w')
49   - _file.write(json.dumps(self.captors_conf))
  48 + _file.write(json.dumps(self.captors_table))
50 49 _file.close()
51 50 logger.info("Saved : plc_config.json")
52 51 #except:
... ... @@ -58,17 +57,18 @@ class PlcChecker(object):
58 57 self.struct = struct[0]
59 58 else:
60 59 self.struct = struct
61   - if self.struct["entity_name"] == "PLC_STATUS":
62   - if not self.same_origin():
  60 + if not self.same_origin():
63 61 self.scan_sensors()
64 62 self.save_config()
65   - else:
66   - logger.info("No PLC_STATUS")
67 63  
68 64 def same_origin(self):
  65 + # check new origin
69 66 if self.struct["from"] == self.plc_from and self.struct["site"] == self.plc_site:
70 67 return True
71 68 else:
  69 + # update origin
  70 + self.plc_from = self.struct["from"]
  71 + self.plc_site = self.struct["site"]
72 72 return False
73 73  
74 74 def get_key(self, struct, key):
... ... @@ -80,15 +80,19 @@ class PlcChecker(object):
80 80  
81 81 def scan_sensors(self):
82 82 # return captors table from struct
  83 + self.captors_table = []
83 84 try:
84 85 logger.debug(self.struct["date"])
85 86 except Exception as e:
86 87 logger.debug("No date")
  88 + ind1 = 0
87 89 for device in self.struct["devices"]:
88 90 self.device_name = self.get_key(device, "device_name")
89 91 self.device_type = self.get_key(device, "device_type")
90 92 self.serial_number = self.get_key(device, "serial_number")
91 93 self.valid = self.get_key(device, "valid")
  94 + ind1 += 1
  95 + ind2 = 0
92 96 for device_values in device["device_values"]:
93 97 captor = []
94 98 captor.append(self.device_name)
... ... @@ -97,7 +101,9 @@ class PlcChecker(object):
97 101 captor.append(self.valid)
98 102 captor.append(self.get_key(device_values, "name"))
99 103 captor.append(self.get_key(device_values, "type"))
  104 + captor.append(str(ind1) + "_" + str(ind2))
100 105 self.captors_table.append(captor)
  106 + ind2 += 1
101 107  
102 108  
103 109 # deprecated find captor list in struct
... ...
src/monitoring/tasks.py
... ... @@ -259,7 +259,7 @@ class Monitoring(Task):
259 259  
260 260 def parseNewStatus(self,status_plc ):
261 261 # """ PM 20181009 parse new status for config
262   - if status_plc[:7] != "NOT_SET":
  262 + if status_plc.find('PLC_STATUS') >= 0:
263 263 self.plc_checker.chk_config(status_plc)
264 264  
265 265 '''
... ...