cnk700i 发表于 2018-7-5 22:18:30

踩个使用Aqara人体传感器的小坑


## 环境 ##
Ubuntu18.04 + HA 0.71.0

## 现象 ##
Aqara人体传感器会在HA中生成一个binary_sensor.motion_sensor_xxxxxxxxxxxxxx的人体传感器,但其触发/未触发状态一直有点迷,通常是一长串

## 解决办法 ##
{HA安装目录}/components/binary_sensor/xiaomi_aqara.py中XiaomiMotionSensor类的init方法增加一行代码即可
   
    ……省略……
    class XiaomiMotionSensor(XiaomiBinarySensor):
    ……省略……
    def __init__(self, device, hass, xiaomi_hub):
      """Initialize the XiaomiMotionSensor."""
      self._hass = hass
      self._no_motion_since = 0
      if 'proto' not in device or int(device['proto']) == 1:
            data_key = 'status'
      else:
            data_key = 'motion_status'
      XiaomiBinarySensor.__init__(self, device, 'Motion Sensor', xiaomi_hub,
                                    data_key, 'motion')
      self._should_poll = True      #增加的

> 注释:HA启动过程会为binary_sensor.xiaomi_aqara这个platform注册一个更新数据的周期性任务(任务中通过should_poll属性判断该设备是否调用update方法去更新数据),前提是该platform下的设备的should_poll属性不能全为False。而代码中默认的should_poll属性都是False,所以导致无法正常更新数据,所以在设备初始化的时候给设置一下should_poll的值即可。

## 关于Aqara人体传感器工作方式 ##
最后说一下调试中总结的Aqara人体传感器工作方式

**** Hidden Message *****

花蟋蟀 发表于 2018-7-5 22:24:10

支持一下

apple4105 发表于 2018-7-5 23:00:48

资瓷一下。

nice2943 发表于 2018-7-5 23:16:39

大神~~~
裡害了

paochu_2007 发表于 2018-7-5 23:40:44

学习一下

norman_lu 发表于 2018-7-5 23:52:04

感谢分享,太强了。

zxjack 发表于 2018-7-6 00:53:00

看看怎么回事

lawsongsong 发表于 2018-7-6 01:16:06

踩个使用Aqara人体传感器的小坑

saber0524 发表于 2018-7-6 01:24:54

感謝分享,學習了

aobolee 发表于 2018-7-6 08:39:03

学习一下
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: 踩个使用Aqara人体传感器的小坑