mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +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.binary_sensor import BinarySensorDevice
|
||||||
from homeassistant.components.xiaomi_aqara import (PY_XIAOMI_GATEWAY,
|
from homeassistant.components.xiaomi_aqara import (PY_XIAOMI_GATEWAY,
|
||||||
XiaomiDevice)
|
XiaomiDevice)
|
||||||
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.helpers.event import async_call_later
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -153,6 +155,7 @@ class XiaomiMotionSensor(XiaomiBinarySensor):
|
|||||||
"""Initialize the XiaomiMotionSensor."""
|
"""Initialize the XiaomiMotionSensor."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._no_motion_since = 0
|
self._no_motion_since = 0
|
||||||
|
self._unsub_set_no_motion = None
|
||||||
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
||||||
data_key = 'status'
|
data_key = 'status'
|
||||||
else:
|
else:
|
||||||
@ -167,6 +170,13 @@ class XiaomiMotionSensor(XiaomiBinarySensor):
|
|||||||
attrs.update(super().device_state_attributes)
|
attrs.update(super().device_state_attributes)
|
||||||
return attrs
|
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):
|
def parse_data(self, data, raw_data):
|
||||||
"""Parse data sent by gateway."""
|
"""Parse data sent by gateway."""
|
||||||
if raw_data['cmd'] == 'heartbeat':
|
if raw_data['cmd'] == 'heartbeat':
|
||||||
@ -188,6 +198,15 @@ class XiaomiMotionSensor(XiaomiBinarySensor):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if value == MOTION:
|
if value == MOTION:
|
||||||
|
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
|
self._should_poll = True
|
||||||
if self.entity_id is not None:
|
if self.entity_id is not None:
|
||||||
self._hass.bus.fire('motion', {
|
self._hass.bus.fire('motion', {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user