| 
					
				 | 
			
			
				@@ -25,8 +25,7 @@ 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 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    AWS_IOT_SES_ACCESS_FOREIGN_REGION_AMERICA, AWS_IOT_SES_ACCESS_FOREIGN_REGION_EUROPE, ALEXA_DOMAIN 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 LOGGER = logging.getLogger('info') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 SOCKET_TOPIC_NAME = 'loocam/smart-socket/{}'  # 插座发布消息主题(因设备当前版本只能订阅一个主题) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -226,10 +225,13 @@ class SmartSocketView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if not all([device_id, status]): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return response.json(444) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         serial_number = cls.get_serial_number_by_device_id(device_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        status = int(status) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         # 保存数据库并下发MQTT消息到插座设备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        result = cls.save_socket_switch(device_id, serial_number, int(status)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        result = cls.save_socket_switch(device_id, serial_number, status) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if not result: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return response.json(177) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        cause_type = 'APP_INTERACTION' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        cls.change_report_alexa_socket(serial_number, status, cause_type) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return response.json(0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @staticmethod 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -938,9 +940,30 @@ class SmartSocketView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             print(e) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @staticmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    def change_report_alexa_socket(serial_number, status, cause_type): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        请求修改插座状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        @param serial_number: 序列号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        @param status: 开关状态,1:开, 0:关 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        @param cause_type: 原因类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        @return: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        url = '{}deviceStatus/changeReportSwitch'.format(ALEXA_DOMAIN) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        value = 'ON' if status == 1 else 'OFF' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'serial_number': serial_number, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'value': value, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'cause_type': cause_type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            requests.post(url=url, data=data, timeout=5) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        except Exception as e: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            print(repr(e)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     def delete_alexa_socket(cls, serial_number): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        url = 'https://www.zositech.xyz/deviceStatus/deleteSwitch' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        url = '{}deviceStatus/deleteSwitch'.format(ALEXA_DOMAIN) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         data = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'serial_number': serial_number 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -969,6 +992,9 @@ class SmartSocketView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 'created_time': now_time, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             SceneLog.objects.create(**log_dict) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            cause_type = 'PHYSICAL_INTERACTION' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            cls.change_report_alexa_socket(serial_number, status, cause_type) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             LOGGER.info('成功接收并保存,插座序列号{},状态:{}'.format(serial_number, status)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return response.json(0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         except Exception as e: 
			 |