mirror of
https://github.com/home-assistant/core.git
synced 2025-07-07 13:27:09 +00:00
Fix motion sensor in Aqara LAN protocol V2 (#17240)
This commit is contained in:
parent
6df3c480b3
commit
0ea5a73e8d
@ -4,6 +4,8 @@ import logging
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.components.xiaomi_aqara import (PY_XIAOMI_GATEWAY,
|
||||
XiaomiDevice)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -153,6 +155,7 @@ class XiaomiMotionSensor(XiaomiBinarySensor):
|
||||
"""Initialize the XiaomiMotionSensor."""
|
||||
self._hass = hass
|
||||
self._no_motion_since = 0
|
||||
self._unsub_set_no_motion = None
|
||||
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
||||
data_key = 'status'
|
||||
else:
|
||||
@ -167,6 +170,13 @@ class XiaomiMotionSensor(XiaomiBinarySensor):
|
||||
attrs.update(super().device_state_attributes)
|
||||
return attrs
|
||||
|
||||
@callback
|
||||
def _async_set_no_motion(self, now):
|
||||
"""Set state to False."""
|
||||
self._unsub_set_no_motion = None
|
||||
self._state = False
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
def parse_data(self, data, raw_data):
|
||||
"""Parse data sent by gateway."""
|
||||
if raw_data['cmd'] == 'heartbeat':
|
||||
@ -188,11 +198,20 @@ class XiaomiMotionSensor(XiaomiBinarySensor):
|
||||
return False
|
||||
|
||||
if value == MOTION:
|
||||
self._should_poll = True
|
||||
if self.entity_id is not None:
|
||||
self._hass.bus.fire('motion', {
|
||||
'entity_id': self.entity_id
|
||||
})
|
||||
if self._data_key == 'motion_status':
|
||||
if self._unsub_set_no_motion:
|
||||
self._unsub_set_no_motion()
|
||||
self._unsub_set_no_motion = async_call_later(
|
||||
self._hass,
|
||||
180,
|
||||
self._async_set_no_motion
|
||||
)
|
||||
else:
|
||||
self._should_poll = True
|
||||
if self.entity_id is not None:
|
||||
self._hass.bus.fire('motion', {
|
||||
'entity_id': self.entity_id
|
||||
})
|
||||
|
||||
self._no_motion_since = 0
|
||||
if self._state:
|
||||
|
Loading…
x
Reference in New Issue
Block a user