Commit 927b859906552bbd0cda2e3c27084fd353c05151
1 parent
fe7a5e18
Exists in
dev
Moving plc_mode and safe into GLOBAL device
Showing
3 changed files
with
20 additions
and
14 deletions
Show diff stats
simulators/plc/plcSimulator.py
... | ... | @@ -72,10 +72,14 @@ class PLCSimulator(DeviceSim, StatusManager): |
72 | 72 | {"name": "status", "value": "on", "unit": "string", "comment": "on or off"}, |
73 | 73 | {"name": "current", "value": 0.234, "unit": "Ampere", "comment": ""} |
74 | 74 | ] |
75 | + }, | |
76 | + {"name": "GLOBAL", | |
77 | + "values": [ | |
78 | + {"name": "mode", "value": "AUTO", "unit": "String", "comment": "AUTO OFF MANU"}, | |
79 | + {"name": "is_safe", "value": True, "unit": "bool", "comment": "True or False"}, | |
80 | + ] | |
75 | 81 | } |
76 | 82 | ], |
77 | - "mode": "AUTO", | |
78 | - "is_safe": True | |
79 | 83 | } |
80 | 84 | |
81 | 85 | list = {"name": "LIST", "from": "Beckhoff", "version_firmware": "20170809", "site": "OSM-Mexico", | ... | ... |
src/dashboard/views.py
... | ... | @@ -54,14 +54,15 @@ def retrieve_env_navbar(request): |
54 | 54 | if request.is_ajax(): |
55 | 55 | try: |
56 | 56 | weather_status = WeatherWatch.objects.latest('updated') |
57 | - plc_mode = PlcDeviceStatus.objects.latest('created').plc_mode | |
58 | - is_safe = PlcDeviceStatus.objects.latest('created').is_safe | |
59 | - ack = Config.objects.get(id=1).ack | |
57 | + plc_mode = PlcDeviceStatus.objects.exclude(plc_mode=None).latest('created').plc_mode | |
58 | + is_safe = PlcDeviceStatus.objects.exclude(plc_mode=None).latest('created').is_safe | |
60 | 59 | weather = serializers.serialize('json', [weather_status]) |
61 | 60 | weather = json.loads(weather) |
61 | + ack = Config.objects.get(id=1).ack | |
62 | 62 | weather[0]['sunelev'] = randint(-30, 30) #remplacer par l'appel au code d'Alain quand il sera dispo |
63 | 63 | weather[0]["plc_mode"] = plc_mode |
64 | 64 | weather[0]["is_safe"] = is_safe |
65 | + weather[0]["ACK"] = ack | |
65 | 66 | return HttpResponse(json.dumps(weather), content_type="application/json") |
66 | 67 | except WeatherWatch.DoesNotExist: |
67 | 68 | raise Http404("No WeatherWatch matches the given query.") |
... | ... | @@ -71,10 +72,11 @@ def retrieve_main_icon(request): |
71 | 72 | try: |
72 | 73 | weather_status = WeatherWatch.objects.latest('updated') |
73 | 74 | plc_mode = PlcDeviceStatus.objects.latest('created').plc_mode |
75 | + | |
74 | 76 | weather = serializers.serialize('json', [weather_status]) |
75 | 77 | weather = json.loads(weather) |
76 | 78 | weather[0]["plc_mode"] = plc_mode |
77 | - weather[0]["ACK"] = ack | |
79 | + | |
78 | 80 | return HttpResponse(json.dumps(weather), content_type="application/json") |
79 | 81 | except WeatherWatch.DoesNotExist: |
80 | 82 | raise Http404("No WeatherWatch matches the given query.") | ... | ... |
src/monitoring/tasks.py
... | ... | @@ -160,16 +160,16 @@ class Monitoring(Task): |
160 | 160 | def extractFromDict(self, status): |
161 | 161 | synthesis = {} |
162 | 162 | devices = status["device"] |
163 | - is_safe_str = status["is_safe"] | |
164 | - mode = status["mode"] | |
163 | + #is_safe_str = status["is_safe"] | |
164 | + #mode = status["mode"] | |
165 | 165 | for device in devices: |
166 | 166 | for value in device["values"]: |
167 | 167 | synthesis[value["name"]] = value["value"] |
168 | 168 | synthesis[value["name"] + "_unit"] = value["unit"] |
169 | - return synthesis,is_safe_str, mode | |
169 | + return synthesis | |
170 | 170 | |
171 | 171 | # TODO ATTENTION SI DEUX DEVICES ONT LE MEME NOM |
172 | - def saveContent(self, content, is_safe_str, mode): | |
172 | + def saveContent(self, content): | |
173 | 173 | devices = content["device"] |
174 | 174 | for device in devices: |
175 | 175 | status = PlcDeviceStatus() |
... | ... | @@ -182,8 +182,8 @@ class Monitoring(Task): |
182 | 182 | for value in device["values"]: |
183 | 183 | status.setValue(value["name"], value["value"], value["unit"]) |
184 | 184 | |
185 | - status.setValue("mode", mode) | |
186 | - status.setValue("is_safe", is_safe_str) | |
185 | + #status.setValue("mode", mode) | |
186 | + #status.setValue("is_safe", is_safe_str) | |
187 | 187 | status.save() |
188 | 188 | |
189 | 189 | ''' |
... | ... | @@ -195,8 +195,8 @@ class Monitoring(Task): |
195 | 195 | dict = json.loads(status_plc)[0] |
196 | 196 | if dict["name"] == "STATUS": |
197 | 197 | if self.isStatusValid(): |
198 | - status, is_safe_str, mode = self.extractFromDict(dict) | |
199 | - self.saveContent(dict, is_safe_str, mode) | |
198 | + status = self.extractFromDict(dict) | |
199 | + self.saveContent(dict) | |
200 | 200 | else: |
201 | 201 | # TODO HANDLE ERROR HERE |
202 | 202 | pass | ... | ... |