|
@@ -11,8 +11,6 @@ from django.db.models import F
|
|
|
from django.views import View
|
|
|
|
|
|
from Model.models import FamilyRoomDevice, GatewaySubDevice, FamilyRoom, SmartScene, EffectiveTime, Device_Info
|
|
|
-from Object.ResponseObject import ResponseObject
|
|
|
-from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
|
|
|
|
|
@@ -28,16 +26,12 @@ class SmartSceneView(View):
|
|
|
return self.validation(request.POST, request, operation)
|
|
|
|
|
|
def validation(self, request_dict, request, operation):
|
|
|
- token_obj = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
- lang = request_dict.get('lang', None)
|
|
|
- response = ResponseObject(lang if lang else token_obj.lang)
|
|
|
-
|
|
|
- if token_obj.code != 0:
|
|
|
- return response.json(token_obj.code)
|
|
|
- user_id = token_obj.userID
|
|
|
+ token_code, user_id, response = CommonService.verify_token_get_user_id(request_dict, request)
|
|
|
+ if token_code != 0:
|
|
|
+ return response.json(token_code)
|
|
|
if operation == 'condition-devices': # 添加条件-查询设备
|
|
|
return self.condition_devices(request_dict, response)
|
|
|
- if operation == 'task-devices': # 添加任务-查询设备
|
|
|
+ elif operation == 'task-devices': # 添加任务-查询设备
|
|
|
return self.task_devices(request_dict, response)
|
|
|
elif operation == 'create': # 创建智能场景
|
|
|
return self.create_smart_scene(request_dict, user_id, response)
|
|
@@ -75,21 +69,21 @@ class SmartSceneView(View):
|
|
|
if not gateway_sub_device_qs.exists():
|
|
|
return response.json(173)
|
|
|
gateway_sub_device_qs = gateway_sub_device_qs.annotate(gatewaySubId=F('id'), deviceType=F('device_type'),
|
|
|
- deviceNickName=F('nickname')).\
|
|
|
+ deviceNickName=F('nickname')). \
|
|
|
values('gatewaySubId', 'deviceType', 'deviceNickName', 'status')
|
|
|
sub_device_list = []
|
|
|
- for gateway_sub_device in gateway_sub_device_qs:
|
|
|
- family_room_device_qs = FamilyRoomDevice.objects.filter(sub_device=gateway_sub_device['gatewaySubId']).\
|
|
|
+ for sub_device in gateway_sub_device_qs:
|
|
|
+ family_room_device_qs = FamilyRoomDevice.objects.filter(sub_device=sub_device['gatewaySubId']). \
|
|
|
values('room_id')
|
|
|
if not family_room_device_qs.exists():
|
|
|
- gateway_sub_device['roomName'] = ''
|
|
|
+ sub_device['roomName'] = ''
|
|
|
else:
|
|
|
room_id = family_room_device_qs[0]['room_id']
|
|
|
try:
|
|
|
- gateway_sub_device['roomName'] = FamilyRoom.objects.get(id=room_id).name
|
|
|
+ sub_device['roomName'] = FamilyRoom.objects.get(id=room_id).name
|
|
|
except ObjectDoesNotExist:
|
|
|
- gateway_sub_device['roomName'] = ''
|
|
|
- sub_device_list.append(gateway_sub_device)
|
|
|
+ sub_device['roomName'] = ''
|
|
|
+ sub_device_list.append(sub_device)
|
|
|
return response.json(0, sub_device_list)
|
|
|
except Exception as e:
|
|
|
return response.json(500, repr(e))
|
|
@@ -351,7 +345,7 @@ class SmartSceneView(View):
|
|
|
except ObjectDoesNotExist:
|
|
|
return response.json(0, res)
|
|
|
|
|
|
- if effective_time_qs.is_all_day: # 全天
|
|
|
+ if effective_time_qs.is_all_day: # 全天
|
|
|
time_dict = {'all_day': 1}
|
|
|
else:
|
|
|
time_dict = {
|