|
@@ -11,7 +11,7 @@ from django.db import transaction
|
|
from django.db.models import Count, Q
|
|
from django.db.models import Count, Q
|
|
from django.views import View
|
|
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_SOS
|
|
from Model.models import Device_Info, GatewaySubDevice, FamilyRoomDevice, SensorRecord, SmartScene, SceneLog, FamilyRoom
|
|
from Model.models import Device_Info, GatewaySubDevice, FamilyRoomDevice, SensorRecord, SmartScene, SceneLog, FamilyRoom
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
@@ -493,43 +493,22 @@ class GatewaySubDeviceView(View):
|
|
gateway_sub_device_qs = GatewaySubDevice.objects.filter(device_id=sub_device_qs[0]['device_id'],
|
|
gateway_sub_device_qs = GatewaySubDevice.objects.filter(device_id=sub_device_qs[0]['device_id'],
|
|
device_type=SENSOR_TYPE['smart_button']).values(
|
|
device_type=SENSOR_TYPE['smart_button']).values(
|
|
'ieee_addr')
|
|
'ieee_addr')
|
|
- sos_count = gateway_sub_device_qs.count()
|
|
|
|
- sos_num = 1
|
|
|
|
- for index, gateway_sub_device in enumerate(gateway_sub_device_qs):
|
|
|
|
- if sub_device_qs[0]['ieee_addr'] == gateway_sub_device['ieee_addr']:
|
|
|
|
- sos_num += index
|
|
|
|
|
|
+
|
|
# 通知设备修改sos状态
|
|
# 通知设备修改sos状态
|
|
msg = {
|
|
msg = {
|
|
- 'sos_count': sos_count, # 该网关下的智能按钮数量
|
|
|
|
- 'sos_num': sos_num, # 第几个按钮
|
|
|
|
- 'sensor_ieee_addr': sub_device_qs[0]['ieee_addr'],
|
|
|
|
- 'sos_select': emergency_status
|
|
|
|
|
|
+ 'scene_event': SCENE_EVENT_SOS,
|
|
|
|
+ 'ieee_addr': sub_device_qs[0]['ieee_addr'],
|
|
|
|
+ 'sos': emergency_status
|
|
}
|
|
}
|
|
success = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
|
|
success = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
|
|
try:
|
|
try:
|
|
assert success
|
|
assert success
|
|
except AssertionError:
|
|
except AssertionError:
|
|
return response.json(10044)
|
|
return response.json(10044)
|
|
- time.sleep(0.3)
|
|
|
|
|
|
+
|
|
# 如果打开紧急开关,关闭已开启的场景
|
|
# 如果打开紧急开关,关闭已开启的场景
|
|
if emergency_status == 1:
|
|
if emergency_status == 1:
|
|
- smart_scene_qs = SmartScene.objects.filter(sub_device_id=sub_device_id, is_enable=True)
|
|
|
|
- if not smart_scene_qs.exists():
|
|
|
|
- return response.json(0)
|
|
|
|
- for smart_scene in smart_scene_qs:
|
|
|
|
- # 通知设备关闭场景
|
|
|
|
- msg = {
|
|
|
|
- 'scene_id': smart_scene.id,
|
|
|
|
- 'scene_status': 0
|
|
|
|
- }
|
|
|
|
- success = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
|
|
|
|
- try:
|
|
|
|
- assert success
|
|
|
|
- except AssertionError:
|
|
|
|
- return response.json(10044)
|
|
|
|
- time.sleep(0.3)
|
|
|
|
- smart_scene_qs.update(is_enable=False)
|
|
|
|
-
|
|
|
|
|
|
+ SmartScene.objects.filter(sub_device_id=sub_device_id, is_enable=True).update(is_enable=False)
|
|
return response.json(0)
|
|
return response.json(0)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|