|
@@ -11,7 +11,7 @@ from django.db import transaction
|
|
from django.db.models import Count
|
|
from django.db.models import Count
|
|
from django.views import View
|
|
from django.views import View
|
|
|
|
|
|
-from Model.models import Device_Info, GatewaySubDevice, FamilyRoomDevice, SensorRecord
|
|
|
|
|
|
+from Model.models import Device_Info, GatewaySubDevice, FamilyRoomDevice, SensorRecord, SmartScene
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
|
|
|
|
|
|
|
|
@@ -44,6 +44,8 @@ class GatewaySubDeviceView(View):
|
|
return self.records(request_dict, response)
|
|
return self.records(request_dict, response)
|
|
elif operation == 'records-date': # 查询传感器记录日期
|
|
elif operation == 'records-date': # 查询传感器记录日期
|
|
return self.records_date(request_dict, response)
|
|
return self.records_date(request_dict, response)
|
|
|
|
+ elif operation == 'home':
|
|
|
|
+ return self.sensor_home_info(request_dict, response)
|
|
else:
|
|
else:
|
|
return response.json(414)
|
|
return response.json(414)
|
|
|
|
|
|
@@ -354,3 +356,30 @@ class GatewaySubDeviceView(View):
|
|
return response.json(0, record_date_list)
|
|
return response.json(0, record_date_list)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(500, repr(e))
|
|
return response.json(500, repr(e))
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def sensor_home_info(request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ 查询子设备首页信息
|
|
|
|
+ @param request_dict: 请求参数
|
|
|
|
+ @request_dict gatewaySubId: 子设备id
|
|
|
|
+ @param response: 响应对象
|
|
|
|
+ @return: response
|
|
|
|
+ """
|
|
|
|
+ sub_device_id = request_dict.get('gatewaySubId', None)
|
|
|
|
+ if not sub_device_id:
|
|
|
|
+ return response.json(444, {'error param': 'gatewaySubId'})
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('status', 'is_tampered').first()
|
|
|
|
+ if not sub_device_qs:
|
|
|
|
+ return response.json(173)
|
|
|
|
+ smart_scene_num = SmartScene.objects.filter(sub_device_id=sub_device_id).count()
|
|
|
|
+ res = {
|
|
|
|
+ 'smart_scene_num': smart_scene_num,
|
|
|
|
+ 'status': sub_device_qs['status'],
|
|
|
|
+ 'is_tampered': sub_device_qs['is_tampered']
|
|
|
|
+ }
|
|
|
|
+ return response.json(0, res)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(500, repr(e))
|