|
@@ -19,9 +19,14 @@ from django.http import QueryDict
|
|
|
from django.views import View
|
|
|
|
|
|
from Model.models import SocketInfo, SocketSchedule, Device_Info, SocketPowerStatistics, SceneLog, FamilyRoomDevice
|
|
|
+from Object.AWS.AWSIoTDataPlaneUtil import AWSIoTDataPlaneService
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.utils import LocalDateTimeUtil
|
|
|
from Service.CommonService import CommonService
|
|
|
+from Ansjer.config import CONFIG_INFO, AWS_IOT_SES_ACCESS_CHINA_ID, AWS_IOT_SES_ACCESS_CHINA_SECRET, \
|
|
|
+ AWS_IOT_SES_ACCESS_CHINA_REGION, AWS_IOT_SES_ACCESS_FOREIGN_ID, AWS_IOT_SES_ACCESS_FOREIGN_SECRET, \
|
|
|
+ AWS_IOT_SES_ACCESS_FOREIGN_REGION_AMERICA, AWS_IOT_SES_ACCESS_FOREIGN_REGION_EUROPE
|
|
|
+
|
|
|
|
|
|
LOGGER = logging.getLogger('info')
|
|
|
SOCKET_TOPIC_NAME = 'loocam/smart-socket/{}' # 插座发布消息主题(因设备当前版本只能订阅一个主题)
|
|
@@ -859,6 +864,26 @@ class SmartSocketView(View):
|
|
|
try:
|
|
|
socket_info_qs = SocketInfo.objects.get(serial_number=serialNumber, type_switch=0)
|
|
|
device_id = socket_info_qs.device_id
|
|
|
+ # 判断设备是否在线
|
|
|
+ thing_name = 'LC_' + serialNumber
|
|
|
+ if 'test' == CONFIG_INFO or CONFIG_INFO == 'cn':
|
|
|
+ iot_data_plane = AWSIoTDataPlaneService(AWS_IOT_SES_ACCESS_CHINA_ID,
|
|
|
+ AWS_IOT_SES_ACCESS_CHINA_SECRET,
|
|
|
+ AWS_IOT_SES_ACCESS_CHINA_REGION)
|
|
|
+
|
|
|
+ elif 'us' == CONFIG_INFO:
|
|
|
+ iot_data_plane = AWSIoTDataPlaneService(AWS_IOT_SES_ACCESS_FOREIGN_ID,
|
|
|
+ AWS_IOT_SES_ACCESS_FOREIGN_SECRET,
|
|
|
+ AWS_IOT_SES_ACCESS_FOREIGN_REGION_AMERICA)
|
|
|
+ else:
|
|
|
+ iot_data_plane = AWSIoTDataPlaneService(AWS_IOT_SES_ACCESS_FOREIGN_ID,
|
|
|
+ AWS_IOT_SES_ACCESS_FOREIGN_SECRET,
|
|
|
+ AWS_IOT_SES_ACCESS_FOREIGN_REGION_EUROPE)
|
|
|
+ res = iot_data_plane.get_thing_shadow(thing_name)
|
|
|
+ if not res:
|
|
|
+ return response.json(177)
|
|
|
+ if not res['state']['reported']['online']:
|
|
|
+ return response.json(177)
|
|
|
result = cls.save_socket_switch(device_id, serialNumber, int(status))
|
|
|
if not result:
|
|
|
return response.json(177)
|