Danielhiversen / PyXiaomiGateway

PyXiaomiGateway
MIT License
153 stars 55 forks source link

The Aqara Air Conditioning Companion (lumi.acpartner.v3) can not work with Button 1st generation. #99

Open yinjiong opened 6 years ago

yinjiong commented 6 years ago

If the button is hosted under the lumi.acpartner.v3: The button is showed in the homeassistant. But no event is reported when you click it.

syssi commented 6 years ago

Please update HA and try again.

miguelangel-nubla commented 5 years ago

Can confirm.

It is expecting a data key on the report object but lumi.acpartner.v3 sends the report message differently without the data key.

2019-01-10 02:20:47 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'sensor_switch', 'sid': '158d0001e6446b', 'params': [{'button_0': 'click'}]}
2019-01-10 02:20:47 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/xiaomi_gateway/__init__.py", line 376, in push_data
    jdata = json.loads(data['data']) if int(self.proto[0:1]) == 1 else _list2map(data['params'])
KeyError: 'data'

Everything is working as expected if the button is paired with my other regular gateway v3.

2019-01-10 02:26:30 DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'switch', 'sid': '158d0001e6446b', 'short_id': 36082, 'data': '{"status":"click"}'}
syssi commented 5 years ago

@miguelangel-nubla Could you provide a complete log (debug output of xiaomi_gateway enabled)? I'm interested in some early response:

https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L201-L204

Because this condition

https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L376

doesn't work for you. The key params should be accessed instead of data for your device / protocol version.

miguelangel-nubla commented 5 years ago

Spot-on, found the issue. The problem was I had the same mac setup for both devices with each respective IPs. As I share the same key across both gateways to simplify things, no errors were given other than this unexpected behaviour.

I guess a check on gateway initialization would be nice to catch this kind of mistakes early on.

syssi commented 5 years ago

How did you set the same encryption key for both devices?

miguelangel-nubla commented 5 years ago

I used this to capture the messages sent from the app while changing the key from the app. https://github.com/aholstenson/miio/blob/master/docs/protocol.md

There is a specific method to set the key but I can't find it or remember right now. It is self descriptive. The key is generated on the app and then set using that call.

Send the raw command to the other gateway and its done.