Explorar el Código

传感器复位删除设备数据

locky hace 2 años
padre
commit
bbff607bca
Se han modificado 1 ficheros con 14 adiciones y 3 borrados
  1. 14 3
      Controller/SensorGateway/SubDeviceController.py

+ 14 - 3
Controller/SensorGateway/SubDeviceController.py

@@ -620,7 +620,7 @@ class GatewaySubDeviceView(View):
         """
         更新子设备在线状态
         @param request_dict: 请求参数
-        @request_dict online: 在线状态, 1:在线, 0:离线
+        @request_dict online: 在线状态, 0:离线, 1:在线, 2:复位
         @request_dict ieee_addr: 长地址
         @param response: 响应对象
         @return: response
@@ -632,12 +632,23 @@ class GatewaySubDeviceView(View):
             return response.json(444, {'error param': 'online or ieee_addr'})
         online = int(online)
         try:
-            GatewaySubDevice.objects.filter(ieee_addr=ieee_addr).update(status=online)
+            if online == 2:     # 复位删除设备
+                gateway_sub_device_qs = GatewaySubDevice.objects.filter(ieee_addr=ieee_addr).values('id')
+                if not gateway_sub_device_qs.exists():
+                    return response.json(0)
+                sub_device_id = gateway_sub_device_qs[0]['id']
+                # 删除设备信息,场景信息,场景日志
+                with transaction.atomic():
+                    gateway_sub_device_qs.delete()
+                    SmartScene.objects.filter(sub_device_id=sub_device_id).delete()
+                    SceneLog.objects.filter(sub_device_id=sub_device_id).delete()
+            else:
+                GatewaySubDevice.objects.filter(ieee_addr=ieee_addr).update(status=online)
             return response.json(0)
         except Exception as e:
-            print(e)
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
+
 #
 #                   ___====-_  _-====___
 #             _--^^^#####//      \\#####^^^--_