|
@@ -41,7 +41,7 @@ class SmartSceneView(View):
|
|
|
if operation == 'condition-devices': # 添加条件-查询设备
|
|
|
return self.condition_devices(request_dict, response)
|
|
|
elif operation == 'task-devices': # 添加任务-查询设备
|
|
|
- return self.task_devices(request_dict, response)
|
|
|
+ return self.task_devices(request_dict, user_id, response)
|
|
|
elif operation == 'create': # 创建智能场景
|
|
|
return self.create_smart_scene(request_dict, user_id, response)
|
|
|
elif operation == 'scene-list': # 查询智能场景列表
|
|
@@ -91,11 +91,12 @@ class SmartSceneView(View):
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@classmethod
|
|
|
- def task_devices(cls, request_dict, response):
|
|
|
+ def task_devices(cls, request_dict, user_id, response):
|
|
|
"""
|
|
|
添加任务-查询设备
|
|
|
@param request_dict: 请求参数
|
|
|
@request_dict deviceId: 网关设备id
|
|
|
+ @param user_id: 用户id
|
|
|
@param response: 响应对象
|
|
|
@return: response
|
|
|
"""
|
|
@@ -125,7 +126,8 @@ class SmartSceneView(View):
|
|
|
res = cls.get_sub_device_room_name(sub_device_qs, gateway_data)
|
|
|
else:
|
|
|
res = [gateway_data]
|
|
|
-
|
|
|
+ # 添加插座和开关数据
|
|
|
+ res = cls.append_plug_and_switch_data(res, user_id)
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
@@ -182,6 +184,35 @@ class SmartSceneView(View):
|
|
|
}
|
|
|
return res
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def append_plug_and_switch_data(res, user_id):
|
|
|
+ """
|
|
|
+ 添加插座和开关数据
|
|
|
+ @param res: 网关等设备数据
|
|
|
+ @param user_id: 用户id
|
|
|
+ @return: res
|
|
|
+ """
|
|
|
+ device_info_qs = Device_Info.objects.filter(userID_id=user_id, Type__in=[201]).\
|
|
|
+ values('id', 'NickName', 'Type', 'serial_number')
|
|
|
+ if device_info_qs.exists():
|
|
|
+ for device_info in device_info_qs:
|
|
|
+ nickname = device_info['NickName']
|
|
|
+ device_type = device_info['Type']
|
|
|
+ serial_number = device_info['serial_number']
|
|
|
+ device_id = device_info['id']
|
|
|
+ room_id = FamilyRoomDevice.objects.filter(device_id=device_id).values('room_id')[0]['room_id']
|
|
|
+ room_id_qs = FamilyRoom.objects.filter(id=room_id).values('name')
|
|
|
+ room_name = room_id_qs.first()['name'] if room_id_qs.exists() else ''
|
|
|
+ data = {
|
|
|
+ 'serialNumber': serial_number,
|
|
|
+ 'deviceNickName': nickname,
|
|
|
+ 'deviceType': device_type,
|
|
|
+ 'roomName': room_name,
|
|
|
+ 'status': 1,
|
|
|
+ }
|
|
|
+ res.append(data)
|
|
|
+ return res
|
|
|
+
|
|
|
@classmethod
|
|
|
def create_smart_scene(cls, request_dict, user_id, response):
|
|
|
"""
|