|
@@ -504,8 +504,6 @@ class SmartSceneView(View):
|
|
if is_all_day:
|
|
if is_all_day:
|
|
is_all_day = int(is_all_day)
|
|
is_all_day = int(is_all_day)
|
|
effective_time['is_all_day'] = is_all_day
|
|
effective_time['is_all_day'] = is_all_day
|
|
- else:
|
|
|
|
- is_all_day = 0
|
|
|
|
|
|
|
|
if not all([smart_scene_id, scene_name, conditions, tasks]):
|
|
if not all([smart_scene_id, scene_name, conditions, tasks]):
|
|
return response.json(444, {'error param': 'smartSceneId,sceneName,conditions or tasks'})
|
|
return response.json(444, {'error param': 'smartSceneId,sceneName,conditions or tasks'})
|
|
@@ -529,16 +527,25 @@ class SmartSceneView(View):
|
|
return response.json(180)
|
|
return response.json(180)
|
|
|
|
|
|
device_id = ''
|
|
device_id = ''
|
|
- sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('src_addr').first()
|
|
|
|
|
|
+ sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('src_addr',
|
|
|
|
+ 'device__serial_number')
|
|
|
|
+ if not sub_device_qs.exists():
|
|
|
|
+ return response.json(173)
|
|
|
|
+ serial_number = sub_device_qs[0]['device__serial_number']
|
|
msg['smart_scene_id'] = smart_scene_id
|
|
msg['smart_scene_id'] = smart_scene_id
|
|
msg['scene_status'] = 1
|
|
msg['scene_status'] = 1
|
|
- msg['sensor_type'] = int(conditions_dict['sensor']['device_type'])
|
|
|
|
- msg['sensor_src'] = int(sub_device_qs['src_addr'], 16)
|
|
|
|
|
|
+ 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'])
|
|
msg['sensor_status'] = int(conditions_dict['sensor']['eventValues'][0]['event_type'])
|
|
else:
|
|
else:
|
|
if not device_id:
|
|
if not device_id:
|
|
return response.json(444, {'error param': 'deviceId'})
|
|
return response.json(444, {'error param': 'deviceId'})
|
|
sub_device_id = 0
|
|
sub_device_id = 0
|
|
|
|
+ device_qs = Device_Info.objects.filter(id=device_id).value('serial_number')
|
|
|
|
+ if not device_qs.exists():
|
|
|
|
+ return response.json(173)
|
|
|
|
+ serial_number = device_qs[0]['serial_number']
|
|
|
|
+
|
|
|
|
|
|
task_list = []
|
|
task_list = []
|
|
for task in tasks_list:
|
|
for task in tasks_list:
|
|
@@ -558,8 +565,17 @@ class SmartSceneView(View):
|
|
device_data=json.dumps(msg), updated_time=now_time, device_id=device_id,
|
|
device_data=json.dumps(msg), updated_time=now_time, device_id=device_id,
|
|
sub_device_id=sub_device_id)
|
|
sub_device_id=sub_device_id)
|
|
|
|
|
|
- if is_all_day == 0 or is_all_day == 1: # 不设置时间或全天
|
|
|
|
|
|
+ if is_all_day is None: # 不设置时间或全天
|
|
|
|
+ smart_scene_qs.update(effective_time_id=0, is_all_day=0)
|
|
|
|
+ time_dict = {
|
|
|
|
+ 'start_time': conditions_dict['time']['minutes'] * 60,
|
|
|
|
+ 'repeat': conditions_dict['time']['repeat']
|
|
|
|
+ }
|
|
|
|
+ elif is_all_day == 1:
|
|
smart_scene_qs.update(effective_time_id=0, is_all_day=is_all_day)
|
|
smart_scene_qs.update(effective_time_id=0, is_all_day=is_all_day)
|
|
|
|
+ time_dict = {
|
|
|
|
+ 'is_all_day': is_all_day
|
|
|
|
+ }
|
|
else:
|
|
else:
|
|
start_time = int(request_dict.get('startTime', None))
|
|
start_time = int(request_dict.get('startTime', None))
|
|
end_time = int(request_dict.get('endTime', None))
|
|
end_time = int(request_dict.get('endTime', None))
|
|
@@ -572,12 +588,25 @@ class SmartSceneView(View):
|
|
effective_time_id = EffectiveTime.objects.create(start_time=start_time, end_time=end_time,
|
|
effective_time_id = EffectiveTime.objects.create(start_time=start_time, end_time=end_time,
|
|
repeat=repeat).id
|
|
repeat=repeat).id
|
|
smart_scene_qs.update(effective_time_id=effective_time_id, is_all_day=is_all_day)
|
|
smart_scene_qs.update(effective_time_id=effective_time_id, is_all_day=is_all_day)
|
|
|
|
+ time_dict = {
|
|
|
|
+ 'is_all_day': is_all_day,
|
|
|
|
+ 'start_time': start_time * 60,
|
|
|
|
+ 'end_time': end_time * 60,
|
|
|
|
+ 'repeat': repeat
|
|
|
|
+ }
|
|
effective_time = {
|
|
effective_time = {
|
|
'isAllDay': is_all_day,
|
|
'isAllDay': is_all_day,
|
|
'startTime': start_time,
|
|
'startTime': start_time,
|
|
'endTime': end_time,
|
|
'endTime': end_time,
|
|
'repeat': repeat
|
|
'repeat': repeat
|
|
}
|
|
}
|
|
|
|
+ msg['time'] = time_dict
|
|
|
|
+
|
|
|
|
+ # 通过mqtt发送设备数据
|
|
|
|
+ thing_name = serial_number
|
|
|
|
+ topic_name = 'loocam/gateway_sensor/smart_scene/{}'.format(serial_number)
|
|
|
|
+ success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
|
|
|
|
+
|
|
res['effectiveTime'] = effective_time
|
|
res['effectiveTime'] = effective_time
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
|
|
|