maximvelichko / pyvera

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

Rationalise `get_value` & `get_complex_value` and refactor. #91

Open pavoni opened 6 years ago

pavoni commented 6 years ago

I added this to continue the discussion here https://github.com/pavoni/pyvera/pull/88

get_value is a confusing name for a function that gets the summary state from the vera sdata call, and contains a .lower call to attempt (unsuccessfully) to unify the data that comes via the service calls and the sdata call.

get_complex_value gets data from the service calls - but via a rather ugly caching structure that should probably be rationalised, along the lines of what we;'ve done for the set data calls.

As a starting point we could rationalise the two function names, remove the .lower - fix the calls to get_value to have the correct case, and make sure the set calls all still work. And if we merged https://github.com/pavoni/pyvera/pull/88 we can also remove get_strict_value. Thoughts, feedback (and PRs) welcome.

jwater7 commented 6 years ago

Maybe this is obvious, but I can't seem to easily find the answer - is it even possible to use the "complex" service calls using a similar polling mechanism that is used for the get_value sdata call?

pavoni commented 6 years ago

I think @toggledbits had an idea about how to do this - although the current code (based on a vera sample of how to use long_poll) won't do this.

toggledbits commented 6 years ago

Sorry, just saw your question, @jwater7 . Yes, you can pass DataVersion to a status request (the one that returns UPnP state values rather than just shortcodes) as you do for lu_sdata, although note the capitalization used (different from the lu_sdata request). The loadtime parameter also used with lu_sdata does not need to be passed, however. But yes, everything that the polling loop is doing with shortcodes can be done with full UPnP service variable (aka complex) names.

@pavoni et al, I also spotted something in the Vera Wiki that I have not seen before, and it gave me pause: there's a callout that as of UI7, the lu_sdata (and lu_status) requests are deprecated, and status should be used instead (here under the heading "user_data" right before the "lu_status" heading). This could be cause for concern for pyvera, as the current subscription code uses lu_sdata (short data aka shortcodes). No mention is made that sdata is a replacement for lu_sdata, only status is named. I'll look into this and contact Vera devs. I hope this is just an omission.