Selaa lähdekoodia

新增更新智能按钮紧急开关状态接口,修改判断智能按钮不能创建触发条件相同的场景逻辑

locky 3 vuotta sitten
vanhempi
commit
705b359353

+ 8 - 7
Controller/SensorGateway/SmartSceneController.py

@@ -200,7 +200,6 @@ class SmartSceneView(View):
         now_time = int(time.time())
         conditions_dict = eval(conditions)
         tasks_list = eval(tasks)
-        device_type = conditions_dict['sensor']['eventValues'][0]['event_type']
 
         try:
             # 判断是否已存在该场景名
@@ -235,12 +234,14 @@ class SmartSceneView(View):
                 if not sub_device_id:
                     return response.json(444, {'error param': 'subDeviceId'})
 
-                smart_scene_qs = SmartScene.objects.filter(sub_device_id=sub_device_id).values('conditions')
-                if smart_scene_qs.exists():
-                    for item in smart_scene_qs:
-                        conditions_temp = eval(item['conditions'])
-                        if device_type == conditions_temp['sensor']['eventValues'][0]['event_type']:
-                            return response.json(172)
+                # 智能按钮不能创建触发条件相同的场景
+                device_type = conditions_dict['sensor']['device_type']
+                if device_type == '216':
+                    event_type = conditions_dict['sensor']['eventValues'][0]['event_type']
+                    smart_scene_qs = SmartScene.objects.filter(sub_device_id=sub_device_id,
+                                                               conditions__contains=event_type)
+                    if smart_scene_qs.exists():
+                        return response.json(180)
 
                 smart_scene_dict['sub_device_id'] = sub_device_id
                 sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('device__serial_number',

+ 22 - 0
Controller/SensorGateway/SubDeviceController.py

@@ -46,6 +46,8 @@ class GatewaySubDeviceView(View):
             return self.records_date(request_dict, response)
         elif operation == 'home':  # 查询传感器主页信息
             return self.sensor_home_info(request_dict, response)
+        elif operation == 'update-emergency-status':  # 更新智能按钮紧急开关状态
+            return self.update_emergency_status(request_dict, response)
         else:
             return response.json(414)
 
@@ -424,3 +426,23 @@ class GatewaySubDeviceView(View):
             return response.json(0, res)
         except Exception as e:
             return response.json(500, repr(e))
+
+    @staticmethod
+    def update_emergency_status(request_dict, response):
+        """
+        更新智能按钮紧急开关状态
+        @param request_dict: 请求参数
+        @request_dict gatewaySubId: 子设备id
+        @param response: 响应对象
+        @return: response
+        """
+        sub_device_id = request_dict.get('gatewaySubId', None)
+        emergency_status = request_dict.get('emergencyStatus', None)
+        if not all([sub_device_id, emergency_status]):
+            return response.json(444, {'error param': 'gatewaySubId or emergency_status'})
+
+        try:
+            GatewaySubDevice.objects.filter(id=sub_device_id).update(is_tampered=emergency_status)
+            return response.json(0)
+        except Exception as e:
+            return response.json(500, repr(e))

+ 2 - 0
Object/ResponseObject.py

@@ -43,6 +43,7 @@ class ResponseObject(object):
             177: 'Update error',
             178: 'ADD error',
             179: 'Nickname repeated',
+            180: 'Smart button scene trigger conditions cannot be repeated',
             201: 'You can only add 3 custom voice at most',
             306: 'The link has expired!',
             309: 'Please ReLogin! errmsg token',
@@ -150,6 +151,7 @@ class ResponseObject(object):
             177: '更新错误',
             178: '增加错误',
             179: '名称不能重复',
+            180: '智能按钮场景触发条件不能重复',
             201: '最多只能添加3条自定义语音',
             306: '链接已超过有效期!',
             309: '请重新登录!',