Commit e519f61deb0de105a8dd104eaed62710479ac25d
1 parent
d18e437e
Exists in
dev
test valid device for database
Showing
3 changed files
with
26 additions
and
20 deletions
Show diff stats
simulators/plc/colibri-new-fixed-2.json
@@ -247,7 +247,7 @@ | @@ -247,7 +247,7 @@ | ||
247 | "device_name": "VantagePro", | 247 | "device_name": "VantagePro", |
248 | "device_type": "meteo", | 248 | "device_type": "meteo", |
249 | "serial_number": "ERTRY2344324", | 249 | "serial_number": "ERTRY2344324", |
250 | - "valid": "yes", | 250 | + "valid": "no", |
251 | "device_values": [ | 251 | "device_values": [ |
252 | { | 252 | { |
253 | "name": "OutsideTemp", | 253 | "name": "OutsideTemp", |
simulators/plc/plcSimulator.py
@@ -144,6 +144,7 @@ class PLCSimulator(DeviceSim, StatusManager): | @@ -144,6 +144,7 @@ class PLCSimulator(DeviceSim, StatusManager): | ||
144 | return self.loop_1() | 144 | return self.loop_1() |
145 | #return (0) | 145 | #return (0) |
146 | 146 | ||
147 | + # deprecated | ||
147 | def set_status(self): | 148 | def set_status(self): |
148 | self.status = { | 149 | self.status = { |
149 | "name": "STATUS", "from": "Beckhoff", "version_firmware": "20170809", "site": "OSM-Mexico", | 150 | "name": "STATUS", "from": "Beckhoff", "version_firmware": "20170809", "site": "OSM-Mexico", |
@@ -214,7 +215,7 @@ class PLCSimulator(DeviceSim, StatusManager): | @@ -214,7 +215,7 @@ class PLCSimulator(DeviceSim, StatusManager): | ||
214 | ''' | 215 | ''' |
215 | 216 | ||
216 | def get_status(self, count, answer): | 217 | def get_status(self, count, answer): |
217 | - list = {"name": "LIST", "from": "Beckhoff", "version_firmware": "20170809", "site": "OSM-Mexico", | 218 | + """list = {"name": "LIST", "from": "Beckhoff", "version_firmware": "20170809", "site": "OSM-Mexico", |
218 | "date": "2017-03-03T13:42:46", | 219 | "date": "2017-03-03T13:42:46", |
219 | "command": [ | 220 | "command": [ |
220 | {"name": "LIST", "type": "", | 221 | {"name": "LIST", "type": "", |
@@ -230,7 +231,7 @@ class PLCSimulator(DeviceSim, StatusManager): | @@ -230,7 +231,7 @@ class PLCSimulator(DeviceSim, StatusManager): | ||
230 | ] | 231 | ] |
231 | } | 232 | } |
232 | ] | 233 | ] |
233 | - } | 234 | + }""" |
234 | if count: | 235 | if count: |
235 | answer += ',' | 236 | answer += ',' |
236 | answer += json.dumps(self.status) | 237 | answer += json.dumps(self.status) |
src/monitoring/tasks.py
@@ -164,29 +164,34 @@ class Monitoring(Task): | @@ -164,29 +164,34 @@ class Monitoring(Task): | ||
164 | #is_safe_str = status["is_safe"] | 164 | #is_safe_str = status["is_safe"] |
165 | #mode = status["mode"] | 165 | #mode = status["mode"] |
166 | for device in devices: | 166 | for device in devices: |
167 | - for value in device["device_values"]: | ||
168 | - synthesis[value["name"]] = value["value"] | ||
169 | - synthesis[value["name"] + "_unit"] = value["unit"] | 167 | + if device['valid'] == "yes": |
168 | + for value in device["device_values"]: | ||
169 | + synthesis[value["name"]] = value["value"] | ||
170 | + synthesis[value["name"] + "_unit"] = value["unit"] | ||
170 | return synthesis | 171 | return synthesis |
171 | 172 | ||
172 | # TODO ATTENTION SI DEUX DEVICES ONT LE MEME NOM | 173 | # TODO ATTENTION SI DEUX DEVICES ONT LE MEME NOM |
174 | + # TODO SAVE SYNTHESIS | ||
173 | def saveContent(self, content): | 175 | def saveContent(self, content): |
174 | devices = content[0]["devices"] | 176 | devices = content[0]["devices"] |
175 | - | 177 | + print("saveContent") |
176 | for device in devices: | 178 | for device in devices: |
177 | - status = PlcDeviceStatus() | ||
178 | - try: | ||
179 | - database_device = PlcDevice.objects.get(name=device["device_name"]) | ||
180 | - except Exception as e: | ||
181 | - # plc = Plc.objects.first() | ||
182 | - database_device = PlcDevice.objects.create(name=device["name"]) | ||
183 | - status.device = database_device | ||
184 | - for value in device["device_values"]: | ||
185 | - status.setValue(value["name"], value["value"], value["unit"]) | ||
186 | - | ||
187 | - #status.setValue("mode", mode) | ||
188 | - #status.setValue("is_safe", is_safe_str) | ||
189 | - status.save() | 179 | + if device['valid'] == "yes": |
180 | + status = PlcDeviceStatus() | ||
181 | + try: | ||
182 | + database_device = PlcDevice.objects.get(name=device["device_name"]) | ||
183 | + except Exception as e: | ||
184 | + # plc = Plc.objects.first() | ||
185 | + database_device = PlcDevice.objects.create(name=device["name"]) | ||
186 | + status.device = database_device | ||
187 | + for value in device["device_values"]: | ||
188 | + status.setValue(value["name"], value["value"], value["unit"]) | ||
189 | + if value["name"] == "OutsideTemp": | ||
190 | + print(value["name"], value["value"]) | ||
191 | + | ||
192 | + #status.setValue("mode", mode) | ||
193 | + #status.setValue("is_safe", is_safe_str) | ||
194 | + status.save() | ||
190 | 195 | ||
191 | ''' | 196 | ''' |
192 | Parse status returned by plc | 197 | Parse status returned by plc |