|
@@ -8,6 +8,7 @@ import datetime
|
|
|
import json
|
|
|
import time
|
|
|
|
|
|
+from django.db.models import Count
|
|
|
from django.views import View
|
|
|
|
|
|
from Model.models import SwitchDimmingSettings, SwitchScheduler, Device_Info, SceneLog, FamilyRoomDevice
|
|
@@ -45,6 +46,10 @@ class SmartSwitchView(View):
|
|
|
return response.json(token_code)
|
|
|
if operation == 'get-dimming-setting': # 获取智能开关调光设置
|
|
|
return self.get_dimming_setting(request_dict, response)
|
|
|
+ elif operation == 'edit-dimming-correction': # 设置调光校正
|
|
|
+ return self.edit_dimming_correction(request_dict, response)
|
|
|
+ elif operation == 'edit-dimming-setting': # 修改智能开关调光设置
|
|
|
+ return self.edit_dimming_setting(request_dict, response)
|
|
|
elif operation == 'get-scheduler-setting': # 获取排程计划
|
|
|
return self.get_scheduler_setting(request_dict, response)
|
|
|
elif operation == 'add-or-edit-scheduler': # 添加/编辑排程计划
|
|
@@ -57,12 +62,10 @@ class SmartSwitchView(View):
|
|
|
return self.get_timer_setting(request_dict, response)
|
|
|
elif operation == 'add-or-edit-timer': # 添加/编辑计时器
|
|
|
return self.add_or_edit_timer(request_dict, response)
|
|
|
- elif operation == 'edit-dimming-correction': # 设置调光校正
|
|
|
- return self.edit_dimming_correction(request_dict, response)
|
|
|
- elif operation == 'edit-dimming-setting': # 修改智能开关调光设置
|
|
|
- return self.edit_dimming_setting(request_dict, response)
|
|
|
elif operation == 'get-scheduler-log': # 查询排程日志
|
|
|
return self.get_scheduler_log(request_dict, response)
|
|
|
+ elif operation == 'get-scheduler-date': # 查询排程日志日期
|
|
|
+ return self.get_scheduler_date(request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -578,7 +581,8 @@ class SmartSwitchView(View):
|
|
|
if not device_id:
|
|
|
return response.json(444, {'error param': 'deviceId'})
|
|
|
try:
|
|
|
- scene_qs = SceneLog.objects.filter(device_id=device_id).values('tasks', 'status', 'created_time', 'id')
|
|
|
+ scene_qs = SceneLog.objects.filter(device_id=device_id).values('tasks', 'status', 'created_time',
|
|
|
+ 'id').order_by('-created_time')
|
|
|
res = []
|
|
|
for item in scene_qs:
|
|
|
res.append({
|
|
@@ -592,6 +596,34 @@ class SmartSwitchView(View):
|
|
|
print(e)
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def get_scheduler_date(request_dict, response):
|
|
|
+ """
|
|
|
+ 查询排程执行日志日期
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @request_dict deviceId: 设备id
|
|
|
+ @param response: 响应对象
|
|
|
+ @return: response
|
|
|
+ """
|
|
|
+ device_id = request_dict.get('deviceId', None)
|
|
|
+ if not device_id:
|
|
|
+ return response.json(444, {'error param': 'deviceId'})
|
|
|
+ try:
|
|
|
+ scene_log_qs = SceneLog.objects.extra(
|
|
|
+ select={'date': "FROM_UNIXTIME(created_time,'%%Y-%%m-%%d')"}).values('date').filter(
|
|
|
+ device_id=device_id).annotate(count=Count('created_time')).order_by('-date')[:31]
|
|
|
+ date_list = []
|
|
|
+ for scene_log in scene_log_qs:
|
|
|
+ date_list.append({
|
|
|
+ 'timestamp': CommonService.str_to_timestamp(scene_log['date'], '%Y-%m-%d'),
|
|
|
+ 'count': scene_log['count'],
|
|
|
+ 'format': scene_log['date']
|
|
|
+ })
|
|
|
+ return response.json(0, date_list)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
@staticmethod
|
|
|
def reset(request_dict, response):
|
|
|
"""
|