浏览代码

添加智能场景接口允许task列表subDeviceId字段传空

peng 3 年之前
父节点
当前提交
cef0df7a21
共有 1 个文件被更改,包括 2 次插入14 次删除
  1. 2 14
      Controller/SensorGateway/SmartSceneController.py

+ 2 - 14
Controller/SensorGateway/SmartSceneController.py

@@ -235,20 +235,9 @@ class SmartSceneView(View):
                 if not is_all_day or is_all_day == 1:  # 不设置时间或全天
                     smart_scene_qs = SmartScene.objects.create(**smart_scene_dict)
                 elif is_all_day == 2:
-                    # if is_all_day == '0':
-                    #     effective_time_qs = EffectiveTime.objects.filter(is_all_day=True).values('id')
-                    #     if effective_time_qs.exists():
-                    #         effective_time_id = effective_time_qs[0]['id']
-                    #     else:
-                    #         effective_time_id = EffectiveTime.objects.create(is_all_day=True).id
-                    #     smart_scene_dict['effective_time_id'] = effective_time_id
-                    #     smart_scene_qs = SmartScene.objects.create(**smart_scene_dict)
-                    # else:
                     start_time = int(request_dict.get('startTime', None))
                     end_time = int(request_dict.get('endTime', None))
                     repeat = int(request_dict.get('repeat', None))
-                    # if not all([start_time, end_time, repeat]):
-                    #     return response.json(444, {'error param': 'startTime and endTime and repeat'})
                     effective_time_qs = EffectiveTime.objects.filter(start_time=start_time, end_time=end_time,
                                                                      repeat=repeat).values('id')
                     if effective_time_qs.exists():
@@ -275,13 +264,12 @@ class SmartSceneView(View):
                         'sensor_type': task['device_type'],
                         'sensor_action': task['event_type']
                     }
-                    if 'subDeviceId' in task:
-                        sub_device_id = task['subDeviceId']
+                    sub_device_id = task.get('subDeviceId', None)
+                    if sub_device_id:
                         sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('src_addr').first()
                         task_temp['sensor_src'] = int(sub_device_qs['src_addr'], 16)
                     task_list.append(task_temp)
                 msg['task'] = task_list
-                # smart_scene_qs.update(device_data=json.dumps(msg))
                 smart_scene_qs.device_data = json.dumps(msg)
                 smart_scene_qs.save()
                 # 发布MQTT消息通知网关设备