maximvelichko / pyvera

A python library to control devices via the Vera hub
GNU General Public License v2.0
26 stars 30 forks source link

Poll hardening #87

Closed toggledbits closed 6 years ago

toggledbits commented 6 years ago

Harden the polling loop by checking the request Response object in some detail to detect various anomalies that can occur during Vera luup reloads. Since not all JSON implementations stick to de-factos for exception handling, and the requests module returns no error on disconnect with no data, widen the net for catching problems and handle them within a smaller subset of exceptions the polling thread and other callers can manage. Streamline the polling thread code itself just a bit, and add some logging in a few places where it may help to address future issues.

toggledbits commented 6 years ago

OK. I've now submitted a revision with exception handling on the Vera requests that seem to be quite stable, and without a broad-brush exception trap. I think this is a satisfactory middleground, because as I mentioned in my other comment, although various json parsers are giving mixed responses to errors (not always json.decoder.JSONDecodeError), they seem to all consistently follow the suggestion that they be derived from ValueError.

In addition, this version adds our own exception class for the above errors, and restructures the polling loop so that its exception trap only contains the code where those exceptions would be expected to be raised. There is also a blanket exception trap bracketing only the callback call, to trap any problem untrapped by the callback itself and log it, but not let it take down the polling thread.

pavoni commented 6 years ago

That looks great - now released 0.2.42.

Thanks for all your hard work on this - I think your solution to this is really well thought through.

Would you like to do the HA PR - or shall I?

toggledbits commented 6 years ago

Since HA has a process you've been through, if you don't mind, I'll leave it to you. Thanks for your support and discussions/recommendations on this.

pavoni commented 6 years ago

Looks like we made it into 65.3.

Thanks again.