|
@@ -104,7 +104,15 @@ class SmartSceneView(View):
|
|
创建智能场景
|
|
创建智能场景
|
|
@param request_dict: 请求参数
|
|
@param request_dict: 请求参数
|
|
@param user_id: 用户id
|
|
@param user_id: 用户id
|
|
|
|
+ @request_dict deviceId: 网关设备id
|
|
@request_dict gatewaySubId: 子设备id
|
|
@request_dict gatewaySubId: 子设备id
|
|
|
|
+ @request_dict sceneName: 场景名称
|
|
|
|
+ @request_dict conditions: 条件
|
|
|
|
+ @request_dict tasks: 任务
|
|
|
|
+ @request_dict isAllDay: 是否全天执行
|
|
|
|
+ @request_dict startTime: 开始时间
|
|
|
|
+ @request_dict endTime: 结束时间
|
|
|
|
+ @request_dict repeat: 重复周期
|
|
@param response: 响应对象
|
|
@param response: 响应对象
|
|
@return: response
|
|
@return: response
|
|
"""
|
|
"""
|
|
@@ -113,15 +121,20 @@ class SmartSceneView(View):
|
|
scene_name = request_dict.get('sceneName', None)
|
|
scene_name = request_dict.get('sceneName', None)
|
|
conditions = request_dict.get('conditions', None)
|
|
conditions = request_dict.get('conditions', None)
|
|
tasks = request_dict.get('tasks', None)
|
|
tasks = request_dict.get('tasks', None)
|
|
- all_day = request_dict.get('allDay', None)
|
|
|
|
|
|
+ is_all_day = request_dict.get('isAllDay', None)
|
|
|
|
|
|
if not any([device_id, sub_device_id]):
|
|
if not any([device_id, sub_device_id]):
|
|
return response.json(444, {'error param': 'deviceId or subDeviceId'})
|
|
return response.json(444, {'error param': 'deviceId or subDeviceId'})
|
|
if not all([conditions, tasks]):
|
|
if not all([conditions, tasks]):
|
|
- return response.json(444)
|
|
|
|
|
|
+ return response.json(444, {'error param': 'conditions and tasks'})
|
|
|
|
|
|
now_time = int(time.time())
|
|
now_time = int(time.time())
|
|
try:
|
|
try:
|
|
|
|
+ # 判断是否已存在该场景名
|
|
|
|
+ smart_scene_qs = SmartScene.objects.filter(user_id=user_id, scene_name=scene_name)
|
|
|
|
+ if smart_scene_qs.exists():
|
|
|
|
+ return response.json(174)
|
|
|
|
+
|
|
smart_scene_dict = {
|
|
smart_scene_dict = {
|
|
'user_id': user_id,
|
|
'user_id': user_id,
|
|
'scene_name': scene_name,
|
|
'scene_name': scene_name,
|
|
@@ -134,19 +147,21 @@ class SmartSceneView(View):
|
|
smart_scene_dict['device_id'] = device_id
|
|
smart_scene_dict['device_id'] = device_id
|
|
else:
|
|
else:
|
|
smart_scene_dict['sub_device_id'] = sub_device_id
|
|
smart_scene_dict['sub_device_id'] = sub_device_id
|
|
- if all_day:
|
|
|
|
|
|
+ if is_all_day:
|
|
SmartScene.objects.create(**smart_scene_dict)
|
|
SmartScene.objects.create(**smart_scene_dict)
|
|
else:
|
|
else:
|
|
start_time = request_dict.get('startTime', None)
|
|
start_time = request_dict.get('startTime', None)
|
|
end_time = request_dict.get('endTime', None)
|
|
end_time = request_dict.get('endTime', None)
|
|
repeat = request_dict.get('repeat', None)
|
|
repeat = request_dict.get('repeat', None)
|
|
if not all([start_time, end_time, repeat]):
|
|
if not all([start_time, end_time, repeat]):
|
|
- return response.json(444)
|
|
|
|
- effective_time_qs = EffectiveTime.objects.filter(start_time=start_time, end_time=end_time, repeat=repeat).values('id')
|
|
|
|
|
|
+ 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():
|
|
if effective_time_qs.exists():
|
|
effective_time_id = effective_time_qs[0]['id']
|
|
effective_time_id = effective_time_qs[0]['id']
|
|
else:
|
|
else:
|
|
- effective_time_id = EffectiveTime.objects.create(start_time=start_time, end_time=end_time, repeat=repeat).id
|
|
|
|
|
|
+ effective_time_id = EffectiveTime.objects.create(start_time=start_time, end_time=end_time,
|
|
|
|
+ repeat=repeat).id
|
|
smart_scene_dict['effective_time_id'] = effective_time_id
|
|
smart_scene_dict['effective_time_id'] = effective_time_id
|
|
SmartScene.objects.create(**smart_scene_dict)
|
|
SmartScene.objects.create(**smart_scene_dict)
|
|
return response.json(0)
|
|
return response.json(0)
|