|
@@ -37,7 +37,7 @@ class SmartSceneView(View):
|
|
if operation == 'condition-devices': # 添加条件-查询设备
|
|
if operation == 'condition-devices': # 添加条件-查询设备
|
|
return self.condition_devices(request_dict, response)
|
|
return self.condition_devices(request_dict, response)
|
|
if operation == 'task-devices': # 添加任务-查询设备
|
|
if operation == 'task-devices': # 添加任务-查询设备
|
|
- return self.task_devices(request_dict, user_id, response)
|
|
|
|
|
|
+ return self.task_devices(request_dict, response)
|
|
elif operation == 'create': # 创建智能场景
|
|
elif operation == 'create': # 创建智能场景
|
|
return self.create_smart_scene(request_dict, user_id, response)
|
|
return self.create_smart_scene(request_dict, user_id, response)
|
|
elif operation == 'scene-list': # 查询智能场景列表
|
|
elif operation == 'scene-list': # 查询智能场景列表
|
|
@@ -92,26 +92,84 @@ class SmartSceneView(View):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(500, repr(e))
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
- @staticmethod
|
|
|
|
- def task_devices(request_dict, user_id, response):
|
|
|
|
|
|
+ @classmethod
|
|
|
|
+ def task_devices(cls, request_dict, response):
|
|
"""
|
|
"""
|
|
添加任务-查询设备
|
|
添加任务-查询设备
|
|
@param request_dict: 请求参数
|
|
@param request_dict: 请求参数
|
|
- @param user_id: 用户id
|
|
|
|
@request_dict deviceId: 网关设备id
|
|
@request_dict deviceId: 网关设备id
|
|
@param response: 响应对象
|
|
@param response: 响应对象
|
|
@return: response
|
|
@return: response
|
|
"""
|
|
"""
|
|
|
|
+ sub_device_id = request_dict.get('subDeviceId', None)
|
|
device_id = request_dict.get('deviceId', None)
|
|
device_id = request_dict.get('deviceId', None)
|
|
|
|
|
|
- if not all([device_id]):
|
|
|
|
- return response.json(444)
|
|
|
|
|
|
+ if not any([device_id, sub_device_id]):
|
|
|
|
+ return response.json(444, {'error param': 'deviceId or subDeviceId'})
|
|
try:
|
|
try:
|
|
- device_info_qs = GatewaySubDevice.objects.filter(device__userID_id=user_id)
|
|
|
|
- return response.json(0)
|
|
|
|
|
|
+
|
|
|
|
+ if device_id:
|
|
|
|
+ res = cls.get_gateway_data(device_id)
|
|
|
|
+ else:
|
|
|
|
+ device_id_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('device_id', 'device_type')
|
|
|
|
+ device_id = device_id_qs[0]['device_id']
|
|
|
|
+ device_type = device_id_qs[0]['device_type']
|
|
|
|
+ if device_type != 216:
|
|
|
|
+ res = cls.get_gateway_data(device_id)
|
|
|
|
+ else:
|
|
|
|
+ sub_device_list = []
|
|
|
|
+ gateway_data = cls.get_gateway_data(device_id)
|
|
|
|
+ sub_device_list.append(gateway_data)
|
|
|
|
+
|
|
|
|
+ gate_way = GatewaySubDevice.objects.filter(device_id=device_id).values('id', 'nickname', 'status',
|
|
|
|
+ 'device_type')
|
|
|
|
+
|
|
|
|
+ for gateway_sub_device in gate_way:
|
|
|
|
+ device_type = gateway_sub_device['device_type']
|
|
|
|
+ if device_type == 216:
|
|
|
|
+ pass
|
|
|
|
+ else:
|
|
|
|
+ sub_device_id = gateway_sub_device['id']
|
|
|
|
+ room_qs = FamilyRoomDevice.objects.filter(sub_device=sub_device_id).values('room_id')
|
|
|
|
+ room_qs.exists()
|
|
|
|
+ room_qs = room_qs.first()
|
|
|
|
+ room_id = room_qs['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 ''
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ if gate_way.exists():
|
|
|
|
+ gateway_sub_device['room_name'] = FamilyRoom.objects.get(id=room_id).name
|
|
|
|
+ except ObjectDoesNotExist:
|
|
|
|
+ gateway_sub_device['room_name'] = room_name
|
|
|
|
+ gateway_sub_device.pop('id')
|
|
|
|
+ sub_device_list.append(gateway_sub_device)
|
|
|
|
+ res = {'sub_device_list': sub_device_list}
|
|
|
|
+
|
|
|
|
+ return response.json(0, res)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(500, repr(e))
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_gateway_data(device_id):
|
|
|
|
+ """
|
|
|
|
+ 获取网关数据
|
|
|
|
+ @param device_id: 网关设备id
|
|
|
|
+ @return: res
|
|
|
|
+ """
|
|
|
|
+ device_info_qs = Device_Info.objects.filter(id=device_id).values('NickName', 'Type')
|
|
|
|
+ nickname = device_info_qs[0]['NickName']
|
|
|
|
+ device_type = device_info_qs[0]['Type']
|
|
|
|
+ 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 ''
|
|
|
|
+ res = {
|
|
|
|
+ 'nickname': nickname,
|
|
|
|
+ 'device_type': device_type,
|
|
|
|
+ 'room_name': room_name,
|
|
|
|
+ }
|
|
|
|
+ return res
|
|
|
|
+
|
|
@staticmethod
|
|
@staticmethod
|
|
def create_smart_scene(request_dict, user_id, response):
|
|
def create_smart_scene(request_dict, user_id, response):
|
|
"""
|
|
"""
|