ソースを参照

新增智能场景音频试听接口

locky 2 年 前
コミット
05a86bd449

+ 1 - 0
Ansjer/Config/gatewaySensorConfig.py

@@ -9,6 +9,7 @@
 SMART_SCENE_TOPIC = 'loocam/gateway_sensor/smart_scene/{}'
 GET_SCENE_TOPIC = 'loocam/gateway_sensor/get_scene/{}'
 SUB_DEVICE_TOPIC = 'loocam/gateway_sensor/sub_device/{}'
+VOICE_AUDITION_TOPIC = 'loocam/gateway_sensor/voice_audition/{}'
 
 # 智能场景事件
 SCENE_EVENT_CREATE = 1

+ 14 - 15
Controller/SensorGateway/SmartSceneController.py

@@ -13,7 +13,8 @@ from django.db.models import F, Q, Count
 from django.views import View
 
 from Ansjer.Config.gatewaySensorConfig import SMART_SCENE_TOPIC, SENSOR_TYPE, EVENT_TYPE, SCENE_EVENT_CREATE, \
-    SCENE_EVENT_EDIT, SCENE_EVENT_DELETE, SCENE_STATUS_ON, SCENE_STATUS_OFF, SCENE_EVENT_EDIT_STATUS
+    SCENE_EVENT_EDIT, SCENE_EVENT_DELETE, SCENE_STATUS_ON, SCENE_STATUS_OFF, SCENE_EVENT_EDIT_STATUS, \
+    VOICE_AUDITION_TOPIC
 from Model.models import FamilyRoomDevice, GatewaySubDevice, FamilyRoom, SmartScene, EffectiveTime, Device_Info, \
     SceneLog
 from Object.ResponseObject import ResponseObject
@@ -992,30 +993,28 @@ class SmartSceneView(View):
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
-    @classmethod
-    def voice_audition(cls, request_dict, response):
+    @staticmethod
+    def voice_audition(request_dict, response):
         """
         智能场景音频试听
         @param request_dict: 请求参数
-        @request_dict deviceId: 网关设备id
-        @request_dict subDeviceId: 子设备id
+        @request_dict serial_number: 序列号
         @request_dict voiceId: 音频id
         @param response: 响应对象
         @return: response
         """
-        device_id = request_dict.get('deviceId', None)
-        sub_device_id = request_dict.get('subDeviceId', None)
+        serial_number = request_dict.get('serial_number', None)
         voice_id = request_dict.get('voiceId', None)
-        if not any([device_id, sub_device_id]) or voice_id is None:
+        if not all([serial_number, voice_id]):
             return response.json(444)
         try:
-            if sub_device_id:
-                device_id = GatewaySubDevice.objects.get(id=sub_device_id).device_id
-            gateway_sub_device_qs = GatewaySubDevice.objects.filter(device_id=device_id)
-            if not gateway_sub_device_qs.exists():
-                return response.json(173)
-            # 查询序列号
-
+            topic_name = VOICE_AUDITION_TOPIC.format(serial_number)
+            msg = {'voice_id': int(voice_id)}
+            success = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
+            try:
+                assert success
+            except AssertionError:
+                return response.json(10044)
             return response.json(0)
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))