:art: chg_sta

huangqimin001 3 jaren geleden
bovenliggende
commit
84e7af2e6a
1 gewijzigde bestanden met toevoegingen van 17 en 18 verwijderingen
  1. 17 18
      api/eqpt_views.py

+ 17 - 18
api/eqpt_views.py

@@ -291,12 +291,6 @@ def mqtt_upload_temperature(payload):
291 291
     except Exception:
292 292
         return
293 293
 
294
-    # 充电状态,true 充电,false 未充电
295
-    chg_sta = payload.get('chg_sta', False)
296
-    # 充电状态,温度忽略
297
-    if chg_sta:
298
-        return
299
-
300 294
     alg_temp = payload.get('alg_temp', '')
301 295
 
302 296
     temp = alg_temp.split(',')
@@ -307,11 +301,15 @@ def mqtt_upload_temperature(payload):
307 301
 
308 302
     temperature = max(temp) / 100
309 303
 
304
+    # 充电状态,true 充电,false 未充电
305
+    chg_sta = payload.get('chg_sta', False)
310 306
     # 电量剩余 65%,有效电量范围[0, 100]
311 307
     bat = payload.get('bat', 0)
312
-    # 电量剩余 100% + 温度超过 37 度,温度忽略
313
-    if bat == 100 and temperature > 37:
314
-        return
308
+    # 充电状态 or (电量剩余 100% + 温度超过 37 度),温度忽略
309
+    ignore_temperature = False
310
+    if chg_sta or (bat == 100 and temperature > 37):
311
+        ignore_temperature = True
312
+        chg_sta = True
315 313
 
316 314
     macid = payload.get('mac', '')
317 315
     macid = f'{macid[:2]}:{macid[2:4]}:{macid[4:6]}:{macid[6:8]}:{macid[8:10]}:{macid[10:12]}'
@@ -336,16 +334,17 @@ def mqtt_upload_temperature(payload):
336 334
     except IsolationPointUserInfo.DoesNotExist:
337 335
         ipui = None
338 336
     if ipui:
339
-        temperature__max = ThermometerMeasureLogInfo.objects.filter(
340
-            point_id=eqpt.point_id,
341
-            macid=macid,
342
-            created_at=tc.utc_datetime(hours=-1),
343
-        ).aggregate(Max('temperature')).get('temperature__max') or 0
344
-        ipui.observed_ymds = list(set(ipui.observed_ymds + [tc.local_string(format='%Y-%m-%d')]))
345
-        ipui.observed_days = len(ipui.observed_ymds)
337
+        if not ignore_temperature:
338
+            temperature__max = ThermometerMeasureLogInfo.objects.filter(
339
+                point_id=eqpt.point_id,
340
+                macid=macid,
341
+                created_at=tc.utc_datetime(hours=-1),
342
+            ).aggregate(Max('temperature')).get('temperature__max') or 0
343
+            ipui.observed_ymds = list(set(ipui.observed_ymds + [tc.local_string(format='%Y-%m-%d')]))
344
+            ipui.observed_days = len(ipui.observed_ymds)
345
+            ipui.temperature = temperature__max or ipui.temperature
346
+            ipui.last_submit_at = tc.utc_datetime()
346 347
         ipui.chg_sta = chg_sta
347
-        ipui.temperature = temperature__max or ipui.temperature
348
-        ipui.last_submit_at = tc.utc_datetime()
349 348
         ipui.save()
350 349
 
351 350
     set_screen_info(point.point_id, get_screen_data(point))