|
@@ -308,20 +308,20 @@ class GatewayView(View):
|
|
|
"""
|
|
|
智能插座开关状态推送
|
|
|
"""
|
|
|
- logger = logging.getLogger('info')
|
|
|
try:
|
|
|
- switch_key = 'LOOCAM:SOCKET:SERIAL:NUMBER:{}'
|
|
|
+ switch_key = 'LOOCAM:SOCKET:SERIAL:NUMBER:{}:{}:{}'
|
|
|
redis_obj = RedisObject(db=7)
|
|
|
serial_number = request_dict.get('serialNumber', None)
|
|
|
+ device_time = request_dict.get('deviceTime', None)
|
|
|
status = request_dict.get('status', None)
|
|
|
- if not all([serial_number, status]):
|
|
|
+ if not all([serial_number, status, device_time]):
|
|
|
return response.json(444)
|
|
|
status = int(status)
|
|
|
- switch_key = switch_key.format(serial_number)
|
|
|
+ switch_key = switch_key.format(serial_number, status, device_time)
|
|
|
switch = redis_obj.get_data(switch_key)
|
|
|
if switch and int(switch) == status:
|
|
|
return response.json(0, "电源开关状态重复上报")
|
|
|
- now_time = int(time.time())
|
|
|
+ now_time = int(device_time) if device_time else int(time.time())
|
|
|
LOGGER.info('已订阅成功接收:事件类型{},状态:{}'.format(serial_number, status))
|
|
|
# 获取主用户设备id
|
|
|
log_dict = {
|
|
@@ -330,8 +330,8 @@ class GatewayView(View):
|
|
|
'created_time': now_time,
|
|
|
}
|
|
|
SceneLog.objects.create(**log_dict)
|
|
|
- redis_obj.set_data(switch_key, status, 60 * 3)
|
|
|
+ redis_obj.set_data(switch_key, status, 60 * 10)
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
- logger.info('---插座开关日志推送接口异常--- {}'.format(repr(e)))
|
|
|
+ LOGGER.info('---插座开关日志推送接口异常--- {}'.format(repr(e)))
|
|
|
return response.json(500, repr(e))
|