浏览代码

修改创建,编辑,删除场景下发数据格式

locky 2 年之前
父节点
当前提交
cbd6118265
共有 2 个文件被更改,包括 18 次插入5 次删除
  1. 9 0
      Ansjer/Config/gatewaySensorConfig.py
  2. 9 5
      Controller/SensorGateway/SmartSceneController.py

+ 9 - 0
Ansjer/Config/gatewaySensorConfig.py

@@ -9,6 +9,15 @@
 SMART_SCENE_TOPIC = 'loocam/gateway_sensor/smart_scene/{}'
 GET_SCENE_TOPIC = 'loocam/gateway_sensor/get_scene/{}'
 
+# 智能场景事件
+SCENE_EVENT_CREATE = 1
+SCENE_EVENT_EDIT = 2
+SCENE_EVENT_DELETE = 3
+
+# 智能场景状态
+SCENE_STATUS_ON = 1
+SCENE_STATUS_OFF = 0
+
 # 传感器类型
 SENSOR_TYPE = {
     'door_magnet': 215,

+ 9 - 5
Controller/SensorGateway/SmartSceneController.py

@@ -12,7 +12,8 @@ from django.db import transaction
 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
+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
 from Model.models import FamilyRoomDevice, GatewaySubDevice, FamilyRoom, SmartScene, EffectiveTime, Device_Info, \
     SceneLog
 from Object.ResponseObject import ResponseObject
@@ -222,7 +223,8 @@ class SmartSceneView(View):
                 'updated_time': now_time,
             }
             msg = {
-                'scene_status': 1
+                'scene_event': SCENE_EVENT_CREATE,
+                'scene_status': SCENE_STATUS_ON
             }
             # 处理设置时间
             if is_all_day is not None:
@@ -313,7 +315,7 @@ class SmartSceneView(View):
                     return response.json(444, {'error param': 'invalid isAllDay'})
 
                 msg['time'] = time_dict
-                msg['smart_scene_id'] = smart_scene_qs.id
+                msg['scene_id'] = smart_scene_qs.id
                 task_list = []
                 for task in tasks_list:
                     task_temp = {
@@ -466,8 +468,9 @@ class SmartSceneView(View):
             return response.json(444, {'error param': 'smartSceneId and status'})
         try:
             smart_scene_id = int(smart_scene_id)
-            scene_status = 1 if is_enable == 'True' else 0
+            scene_status = SCENE_STATUS_ON if is_enable == 'True' else SCENE_STATUS_OFF
             msg = {
+                'scene_event': SCENE_EVENT_EDIT,
                 'scene_id': smart_scene_id,
                 'scene_status': scene_status
             }
@@ -737,7 +740,8 @@ class SmartSceneView(View):
                 for smart_scene_id in smart_scene_id_list:
                     # 通知设备删除场景id
                     msg = {
-                        'smart_scene_delete': int(smart_scene_id)
+                        'scene_event': SCENE_EVENT_DELETE,
+                        'scene_id': int(smart_scene_id)
                     }
                     success = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
                     try: