for i1 in door_last_open["logDetails"]:
if door_last_open is not None and door_last_open!=STATE_UNAVAILABLE and door_last_open!=STATE_UNKNOWN:
content = i1["content"]
if i1['logType'] in ['自动上锁','门铃事件日志']:
continue
if i1["logType"] == '密码开门':
self._last_open_user = content.split(" ")[1].replace("开锁","")
elif i1["logType"] == '人脸识别开门':
self._last_open_user = content.split("【")[1].split("】")[0]
elif i1["logType"] == '指纹开门' :
self._last_open_user = content.split("【")[1].split("】")[0]
else:
self._last_open_user = content
self._last_open_mode = i1["logType"]
door_sensor_state = self.hass.states.get(self._door_sensor)
if (
door_sensor_state is not None
and door_sensor_state.state != STATE_UNKNOWN
):
if door_sensor_state.state == STATE_ON:
self._lock_status = STATE_LOCKED
else:
self._changed_by = None
self._lock_status = STATE_UNLOCKED
last_open_datetime = door_last_open["logDate"] + " " + i1["logTime"]
if self._changed_time is None:
self._changed_time = last_open_datetime # 首次填上次开门时间
elif (self._last_open_datetime != last_open_datetime) and (
last_open_datetime != self._changed_time):
# 如果上次开门时间有变更且跟change time不一致 修改changby属性和change time
self._changed_by = self._last_open_user
self._changed_time = last_open_datetime
_LOGGER.info('open door is _changed_by : [%s]', self._last_open_user)
self._last_open_datetime = last_open_datetime
break
上面的代码是我自己根据情况修改后的,
不同的锁好像是不一样的,这个得去APP看下,比如我的锁是带自动反锁的,因此如果按照原来代码,最近开门都会被识别为自动上锁,因此需要排除掉门铃和自动上锁事件,
if i1['logType'] in ['自动上锁','门铃事件日志']:
continue
密码开门是没有用【】来标示开门人员,因此不能使用split("【")[1].split("】")[0],我的锁如果是密码开锁,显示的消息格式是:有人使用密码开锁 某某某开锁,因此这里我采取的是split(" ")[1].replace("开锁","")
人脸识别开门和指纹识别开门则是用【】来标示开门的人员,因此可以使用split("【")[1].split("】")[0]获取开门人员
|