quentinsf/qhue

Support groups' "class" attribute

Closed this issue · 2 comments

Recent versions of the Hue API support a "class" attribute for groups. However, in this Python API, a statement like

b.groups(http_method="POST", name="WC", type="Room", class="Toilet", lights=[23,42])

is not valid, since "class" is a Python language keyword. We need some kind of a workaround here.

You could pack up the parameters in a dict and then do “b.groups(**parms)”, which would allow you to include “class” as a keyword argument. Recent versions of Python 3, I believe, will accept inline syntax like:

b.groups(http_method="POST", name="WC", type="Room", **{'class': "Toilet"}, lights=[23,42])

which is a bit ugly but should work.

On the other hand, if the Hue API were to introduce an attribute called “http_method”, that would be a bigger problem, as qhue always takes that parameter for itself.

Perhaps qhue could interpret keyword arguments ending in underscores as an escaping mechanism, always sending them to the bridge as attribute names with one trailing underscore removed. For instance, “class_” would get sent to the bridge as attribute name “class”, “class__” as “class_”, “http_method_” as “http_method”, and so forth.

Sorry for my slow response on this! Yes, I like the underscore convention. I'll implement that when I get a moment, unless someone gets to it first and sends a pull request!

Thanks all,
Q