|
@@ -10,14 +10,15 @@ import time
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
from AnsjerPush.Config.gatewaySensorConfig import SENSOR_TYPE, EVENT_TYPE
|
|
|
+from AnsjerPush.config import LOGGER
|
|
|
from Model.models import SensorRecord, GatewaySubDevice, GatewayPush, Device_Info, SceneLog, SmartScene, CountryModel
|
|
|
+from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.utils import LocalDateTimeUtil
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
|
from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
|
|
|
from Service.PushService import PushObject
|
|
|
-from AnsjerPush.config import LOGGER
|
|
|
|
|
|
|
|
|
class GatewayView(View):
|
|
@@ -75,7 +76,7 @@ class GatewayView(View):
|
|
|
|
|
|
# 查询子设备表id
|
|
|
gateway_sub_device_qs = GatewaySubDevice.objects.filter(device__serial_number=serial_number,
|
|
|
- device_type=sensor_type, ieee_addr=ieee_addr).\
|
|
|
+ device_type=sensor_type, ieee_addr=ieee_addr). \
|
|
|
values('id', 'nickname', 'device__userID__region_country')
|
|
|
if not gateway_sub_device_qs.exists():
|
|
|
return response.json(173)
|
|
@@ -197,69 +198,69 @@ class GatewayView(View):
|
|
|
@return: sensor_type, event_type_list
|
|
|
"""
|
|
|
sensor_type, event_type_list = 0, []
|
|
|
- if dev_class == 0: # 灯,待定
|
|
|
+ if dev_class == 0: # 灯,待定
|
|
|
sensor_type = 0
|
|
|
- elif dev_class == 1: # 网关
|
|
|
+ elif dev_class == 1: # 网关
|
|
|
sensor_type = 200
|
|
|
- elif dev_class == 2: # 开关类传感器
|
|
|
+ elif dev_class == 2: # 开关类传感器
|
|
|
if dev_type == 13: # 人体红外
|
|
|
sensor_type = 219
|
|
|
- elif dev_type == 22: # 门磁
|
|
|
+ elif dev_type == 22: # 门磁
|
|
|
sensor_type = 215
|
|
|
- elif dev_type == 42: # 水浸
|
|
|
+ elif dev_type == 42: # 水浸
|
|
|
sensor_type = 217
|
|
|
- elif dev_type == 44: # 智能按钮
|
|
|
+ elif dev_type == 44: # 智能按钮
|
|
|
sensor_type = 216
|
|
|
- elif dev_class == 3: # 测量类传感器
|
|
|
- if dev_type == 1: # 温湿度
|
|
|
+ elif dev_class == 3: # 测量类传感器
|
|
|
+ if dev_type == 1: # 温湿度
|
|
|
sensor_type = 220
|
|
|
- elif dev_type == 2: # 亮度,待定
|
|
|
+ elif dev_type == 2: # 亮度,待定
|
|
|
sensor_type = 0
|
|
|
elif dev_class == 5: # 智能锁
|
|
|
- if dev_type == 1: # 门锁,待定
|
|
|
+ if dev_type == 1: # 门锁,待定
|
|
|
sensor_type = 0
|
|
|
elif dev_class == 6: # 电机类设备
|
|
|
- if dev_type == 1: # 窗帘,待定
|
|
|
+ if dev_type == 1: # 窗帘,待定
|
|
|
sensor_type = 0
|
|
|
|
|
|
if sensor_type == 215: # 门磁
|
|
|
- if param['alarm'] == 1: # 门磁开
|
|
|
+ if param['alarm'] == 1: # 门磁开
|
|
|
event_type_list.append(2150)
|
|
|
- elif param['alarm'] == 0: # 门磁关
|
|
|
+ elif param['alarm'] == 0: # 门磁关
|
|
|
event_type_list.append(2151)
|
|
|
- if param['tamper'] == 1: # 拆动
|
|
|
+ if param['tamper'] == 1: # 拆动
|
|
|
event_type_list.append(2152)
|
|
|
- if param['tamper'] == 0: # 拆动恢复
|
|
|
+ if param['tamper'] == 0: # 拆动恢复
|
|
|
event_type_list.append(2156)
|
|
|
- if param['battery'] == 1: # 低电量
|
|
|
+ if param['battery'] == 1: # 低电量
|
|
|
event_type_list.append(2153)
|
|
|
|
|
|
- elif sensor_type == 216: # 智能按钮
|
|
|
- if param['alarm'] == 1: # 按下
|
|
|
+ elif sensor_type == 216: # 智能按钮
|
|
|
+ if param['alarm'] == 1: # 按下
|
|
|
event_type_list.append(2160)
|
|
|
- if param['smrt_btn'] == 1: # 单击
|
|
|
+ if param['smrt_btn'] == 1: # 单击
|
|
|
event_type_list.append(2161)
|
|
|
- elif param['smrt_btn'] == 2: # 双击
|
|
|
+ elif param['smrt_btn'] == 2: # 双击
|
|
|
event_type_list.append(2162)
|
|
|
- elif param['smrt_btn'] == 3: # 三击
|
|
|
+ elif param['smrt_btn'] == 3: # 三击
|
|
|
event_type_list.append(2163)
|
|
|
- if param['battery'] == 1: # 低电量
|
|
|
+ if param['battery'] == 1: # 低电量
|
|
|
event_type_list.append(2164)
|
|
|
|
|
|
- elif sensor_type == 217: # 水浸
|
|
|
- if param['alarm'] == 1: # 水浸触发
|
|
|
+ elif sensor_type == 217: # 水浸
|
|
|
+ if param['alarm'] == 1: # 水浸触发
|
|
|
event_type_list.append(2170)
|
|
|
- elif param['alarm'] == 0: # 水浸恢复
|
|
|
+ elif param['alarm'] == 0: # 水浸恢复
|
|
|
event_type_list.append(2171)
|
|
|
- if param['battery'] == 1: # 低电量
|
|
|
+ if param['battery'] == 1: # 低电量
|
|
|
event_type_list.append(2172)
|
|
|
|
|
|
- elif sensor_type == 219: # 人体红外
|
|
|
- if param['alarm'] == 1: # 有人移动
|
|
|
+ elif sensor_type == 219: # 人体红外
|
|
|
+ if param['alarm'] == 1: # 有人移动
|
|
|
event_type_list.append(2190)
|
|
|
- elif param['alarm'] == 0: # 无人移动
|
|
|
+ elif param['alarm'] == 0: # 无人移动
|
|
|
event_type_list.append(2191)
|
|
|
- if param['battery'] == 1: # 低电量
|
|
|
+ if param['battery'] == 1: # 低电量
|
|
|
event_type_list.append(2193)
|
|
|
|
|
|
return sensor_type, event_type_list
|
|
@@ -497,22 +498,27 @@ class GatewayView(View):
|
|
|
"""
|
|
|
logger = logging.getLogger('info')
|
|
|
try:
|
|
|
+ switch_key = 'LOOCAM:SOCKET:SERIAL:NUMBER:{}'
|
|
|
+ redis_obj = RedisObject(db=7)
|
|
|
serial_number = request_dict.get('serialNumber', None)
|
|
|
status = request_dict.get('status', None)
|
|
|
if not all([serial_number, status]):
|
|
|
return response.json(444)
|
|
|
+ status = int(status)
|
|
|
+ switch_key = switch_key.format(serial_number)
|
|
|
+ switch = redis_obj.get_data(switch_key)
|
|
|
+ if switch and int(switch) == status:
|
|
|
+ return response.json(0, "电源开关状态重复上报")
|
|
|
now_time = int(time.time())
|
|
|
LOGGER.info('已订阅成功接收:事件类型{},状态:{}'.format(serial_number, status))
|
|
|
- # socket_info_qs = SocketInfo.objects.filter(serial_number=serial_number).values('device_id')
|
|
|
- # if not socket_info_qs.exists():
|
|
|
- # return response.json(173)
|
|
|
# 获取主用户设备id
|
|
|
log_dict = {
|
|
|
- 'status': int(status),
|
|
|
+ 'status': status,
|
|
|
'device_id': serial_number,
|
|
|
'created_time': now_time,
|
|
|
}
|
|
|
SceneLog.objects.create(**log_dict)
|
|
|
+ redis_obj.set_data(switch_key, status, 60 * 3)
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
logger.info('---插座开关日志推送接口异常--- {}'.format(repr(e)))
|