Эх сурвалжийг харах

智能场景添加、编辑接口修改温湿度返回值

peng 3 жил өмнө
parent
commit
39664b7482

+ 32 - 7
Controller/SensorGateway/SmartSceneController.py

@@ -242,8 +242,8 @@ class SmartSceneView(View):
                 if not sub_device_id:
                     return response.json(444, {'error param': 'subDeviceId'})
 
-                # 智能按钮不能创建触发条件相同的场景
                 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,
@@ -251,6 +251,19 @@ class SmartSceneView(View):
                     if smart_scene_qs.exists():
                         return response.json(180)
 
+                # 温湿度传感器返回温湿度
+                elif device_type == '220':
+                    event_values = conditions_dict['sensor']['eventValues'][0]
+                    if '≥' in event_values['value']:
+                        replace_str = '≥ '
+                        msg['sensor_symbol'] = 2
+                    else:
+                        replace_str = '≤ '
+                        msg['sensor_symbol'] = 1
+                    value = event_values['value'].replace(replace_str, '')
+                    msg['sensor_data'] = float(value)
+
+
                 smart_scene_dict['sub_device_id'] = sub_device_id
                 sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('device__serial_number',
                                                                                          'src_addr')
@@ -550,15 +563,27 @@ class SmartSceneView(View):
                 if not sub_device_id:
                     return response.json(444, {'error param': 'subDeviceId'})
 
-                # 智能按钮不能创建触发条件相同的场景
                 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():
+                    smart_scene_temp_qs = smart_scene_qs.filter(sub_device_id=sub_device_id,
+                                                                conditions__contains=event_type)
+                    if smart_scene_temp_qs.exists():
                         return response.json(180)
 
+                # 温湿度传感器返回温湿度
+                elif device_type == '220':
+                    event_values = conditions_dict['sensor']['eventValues'][0]
+                    if '≥' in event_values['value']:
+                        replace_str = '≥ '
+                        msg['sensor_symbol'] = 2
+                    else:
+                        replace_str = '≤ '
+                        msg['sensor_symbol'] = 1
+                    value = event_values['value'].replace(replace_str, '')
+                    msg['sensor_data'] = float(value)
+
                 device_id = ''
                 sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('src_addr',
                                                                                          'device__serial_number')
@@ -566,7 +591,7 @@ class SmartSceneView(View):
                     return response.json(173)
                 serial_number = sub_device_qs[0]['device__serial_number']
                 msg['smart_scene_id'] = smart_scene_id
-                msg['scene_status'] = 1
+                msg['scene_status'] = 1 if smart_scene_qs[0].is_enable else 0
                 msg['sensor_type'] = conditions_dict['sensor']['device_type']
                 msg['sensor_src'] = int(sub_device_qs[0]['src_addr'], 16)
                 msg['sensor_status'] = int(conditions_dict['sensor']['eventValues'][0]['event_type'])
@@ -839,7 +864,7 @@ class SmartSceneView(View):
                 time.sleep(1)
 
             # 下发智能按钮数据
-            smart_button_qs = GatewaySubDevice.objects.filter(device_id=device_id, device_type=216).\
+            smart_button_qs = GatewaySubDevice.objects.filter(device_id=device_id, device_type=216). \
                 values('src_addr', 'is_tampered')
             if smart_button_qs.exists():
                 sos_count = smart_button_qs.count()