Browse Source

修复Alexa搜索多个设备返回错误序列号问题,Alexa mqtt消息兼容接收commandType参数

locky 3 tuần trước cách đây
mục cha
commit
5b18168896
2 tập tin đã thay đổi với 16 bổ sung5 xóa
  1. 14 3
      Controller/IotCoreController.py
  2. 2 2
      Controller/UserController.py

+ 14 - 3
Controller/IotCoreController.py

@@ -13,7 +13,7 @@ from django.views import View
 from Ansjer.config import AWS_IOT_GETS3_PULL_CHINA_ID, AWS_IOT_GETS3_PULL_CHINA_SECRET, \
     AWS_IOT_GETS3_PULL_FOREIGN_ID, AWS_IOT_GETS3_PULL_FOREIGN_SECRET, AWS_ARN, AWS_IOT_SES_ACCESS_CHINA_REGION, \
     AWS_IOT_SES_ACCESS_FOREIGN_REGION_ASIA, AWS_IOT_SES_ACCESS_FOREIGN_REGION_EUROPE, \
-    AWS_IOT_SES_ACCESS_FOREIGN_REGION_AMERICA, REGION_ID_LIST, ALEXA_DOMAIN
+    AWS_IOT_SES_ACCESS_FOREIGN_REGION_AMERICA, REGION_ID_LIST, ALEXA_DOMAIN, LOGGER
 from Model.models import Device_Info, iotdeviceInfoModel, SerialNumberModel, UidSetModel
 from Object.IOTCore.IotObject import IOTClient
 from Object.ResponseObject import ResponseObject
@@ -274,13 +274,24 @@ class IotCoreView(View):
         UID = request_dict.get('UID', None)
         rtsp = request_dict.get('rtsp', None)
         enable = request_dict.get('enable', '1')
-        if not all([UID, rtsp]):
+        command_type = request_dict.get('commandType', None)
+
+        LOGGER.info(
+            f"[request_publish_message] 收到请求: UID={UID}, rtsp={rtsp}, enable={enable}, commandType={command_type}")
+
+        if not UID:
+            return response.json(444)
+        if not any([rtsp, command_type]):
             return response.json(444)
 
         try:
             thing_name = CommonService.query_serial_with_uid(UID)  # 存在序列号则为使用序列号作为物品名
             topic_name = 'ansjer/generic/{}'.format(thing_name)
-            msg = OrderedDict(
+
+            if command_type:
+                msg = {'commandType': command_type}
+            else:
+                msg = OrderedDict(
                 [
                     ('alexaRtspCommand', rtsp),
                     ('enable', int(enable)),

+ 2 - 2
Controller/UserController.py

@@ -3813,14 +3813,13 @@ class alexaUidView(TemplateView):
         if sid != 'admin' or sst != 'admin':
             return response.json(107)
         uid_qs = Device_Info.objects.filter(userID_id=userID, isExist=1).values(
-            'UID', 'NickName', 'View_Password', 'userID__region_country', 'serial_number')
+            'UID', 'NickName', 'View_Password', 'userID__region_country')
         if not uid_qs.exists():
             return response.json(107)
         country_qs = CountryModel.objects.filter(id=uid_qs[0]['userID__region_country']).values(
             'region__continent_code')
 
         try:
-            serial_number = uid_qs[0]['serial_number']
             uid_dict = {}
             uid_list = []
             for uid_q in uid_qs:
@@ -3837,6 +3836,7 @@ class alexaUidView(TemplateView):
             uid_arr = []
             for us in us_qs:
                 uid = us['uid']
+                serial_number = CommonService.get_serial_number_by_uid(uid)
                 channel = us['channel']
                 # 设备alexa区域
                 region_alexa = country_qs[0]['region__continent_code'] if country_qs.exists() else 'EN'