HclX / WyzeSensePy

A python script communicating with WyzeSense gateway
MIT License
91 stars 15 forks source link

AssertionError in gateway.py #9

Closed raetha closed 3 years ago

raetha commented 4 years ago

Hi. I'm not positive if this is something you might be able to help with or not, but I have a project (https://github.com/raetha/wyzesense2mqtt) that uses this library as its base to talk to WyzeSense devices and integrate with HA.

Recently one of my users hit an error while pairing a sensor. I'm including the messages they got below, including debug logging from my code.

sensor_mac: 777E2715
Non-state event data: [2020-03-26 00:06:07][777E2715]RawEvent: type=raw_AB, data=b'020000030000000200000002003b00'
sensor_mac: 777E2715
Non-state event data: [2020-03-26 00:06:07][777E2715]RawEvent: type=raw_AB, data=b'020000030000000200000002003b00'
sensor_mac: 777E2715
Non-state event data: [2020-03-26 00:06:07][777E2715]RawEvent: type=raw_AB, data=b'020000030000000200000002003b00'
sensor_mac: 777E2715
Non-state event data: [2020-03-26 00:06:07][777E2715]RawEvent: type=raw_AB, data=b'020000030000000200000002003b00'
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.8/site-packages/wyzesense/gateway.py", line 357, in _Worker
    pkt = Packet.Parse(s)
  File "/usr/lib/python3.8/site-packages/wyzesense/gateway.py", line 129, in Parse
    assert len(s) >= b2 + 4
AssertionError

Wondering if you might have any ideas on if there's something I need to do to fix this, or if maybe it is a bad sensor/bridge, or if maybe something on your side.

Happy to help troubleshoot any way I can, though they did tell me they unpaired the sensor and then paired other sensors without issue. Waiting to hear back if they were able to repair the original sensor or not.

raetha commented 4 years ago

In looking a little more, and comparing to the similar GoSense library code, it looks like just changing the assert to an if statement might resolve this without having to actually handle the packet. From what I can tell (which isn't a ton on this hardware side of things), the sensors generating this seem to be fine, they are just occasionally generating a packet that the library can't handle.

I did hear follow up from my users that another one of their successfully paired sensors triggered this same error when they open and closed a door. But that after restarting my service things seemed to work again. So it is sporadic.