diff --git a/simulators/plc/plcSimulator.py b/simulators/plc/plcSimulator.py index 0dbfa93..366b7f0 100755 --- a/simulators/plc/plcSimulator.py +++ b/simulators/plc/plcSimulator.py @@ -72,10 +72,14 @@ class PLCSimulator(DeviceSim, StatusManager): {"name": "status", "value": "on", "unit": "string", "comment": "on or off"}, {"name": "current", "value": 0.234, "unit": "Ampere", "comment": ""} ] + }, + {"name": "GLOBAL", + "values": [ + {"name": "mode", "value": "AUTO", "unit": "String", "comment": "AUTO OFF MANU"}, + {"name": "is_safe", "value": True, "unit": "bool", "comment": "True or False"}, + ] } ], - "mode": "AUTO", - "is_safe": True } list = {"name": "LIST", "from": "Beckhoff", "version_firmware": "20170809", "site": "OSM-Mexico", diff --git a/src/dashboard/views.py b/src/dashboard/views.py index bd76ea7..9d31ceb 100644 --- a/src/dashboard/views.py +++ b/src/dashboard/views.py @@ -54,14 +54,15 @@ def retrieve_env_navbar(request): if request.is_ajax(): try: weather_status = WeatherWatch.objects.latest('updated') - plc_mode = PlcDeviceStatus.objects.latest('created').plc_mode - is_safe = PlcDeviceStatus.objects.latest('created').is_safe - ack = Config.objects.get(id=1).ack + plc_mode = PlcDeviceStatus.objects.exclude(plc_mode=None).latest('created').plc_mode + is_safe = PlcDeviceStatus.objects.exclude(plc_mode=None).latest('created').is_safe weather = serializers.serialize('json', [weather_status]) weather = json.loads(weather) + ack = Config.objects.get(id=1).ack weather[0]['sunelev'] = randint(-30, 30) #remplacer par l'appel au code d'Alain quand il sera dispo weather[0]["plc_mode"] = plc_mode weather[0]["is_safe"] = is_safe + weather[0]["ACK"] = ack return HttpResponse(json.dumps(weather), content_type="application/json") except WeatherWatch.DoesNotExist: raise Http404("No WeatherWatch matches the given query.") @@ -71,10 +72,11 @@ def retrieve_main_icon(request): try: weather_status = WeatherWatch.objects.latest('updated') plc_mode = PlcDeviceStatus.objects.latest('created').plc_mode + weather = serializers.serialize('json', [weather_status]) weather = json.loads(weather) weather[0]["plc_mode"] = plc_mode - weather[0]["ACK"] = ack + return HttpResponse(json.dumps(weather), content_type="application/json") except WeatherWatch.DoesNotExist: raise Http404("No WeatherWatch matches the given query.") diff --git a/src/monitoring/tasks.py b/src/monitoring/tasks.py index f4e91c0..ebdec59 100644 --- a/src/monitoring/tasks.py +++ b/src/monitoring/tasks.py @@ -160,16 +160,16 @@ class Monitoring(Task): def extractFromDict(self, status): synthesis = {} devices = status["device"] - is_safe_str = status["is_safe"] - mode = status["mode"] + #is_safe_str = status["is_safe"] + #mode = status["mode"] for device in devices: for value in device["values"]: synthesis[value["name"]] = value["value"] synthesis[value["name"] + "_unit"] = value["unit"] - return synthesis,is_safe_str, mode + return synthesis # TODO ATTENTION SI DEUX DEVICES ONT LE MEME NOM - def saveContent(self, content, is_safe_str, mode): + def saveContent(self, content): devices = content["device"] for device in devices: status = PlcDeviceStatus() @@ -182,8 +182,8 @@ class Monitoring(Task): for value in device["values"]: status.setValue(value["name"], value["value"], value["unit"]) - status.setValue("mode", mode) - status.setValue("is_safe", is_safe_str) + #status.setValue("mode", mode) + #status.setValue("is_safe", is_safe_str) status.save() ''' @@ -195,8 +195,8 @@ class Monitoring(Task): dict = json.loads(status_plc)[0] if dict["name"] == "STATUS": if self.isStatusValid(): - status, is_safe_str, mode = self.extractFromDict(dict) - self.saveContent(dict, is_safe_str, mode) + status = self.extractFromDict(dict) + self.saveContent(dict) else: # TODO HANDLE ERROR HERE pass -- libgit2 0.21.2