studioimaginaire / phue

A Python library for the Philips Hue system
Other
1.52k stars 267 forks source link

Add scene properties 'type' and 'group' #143

Closed Cazfri closed 5 years ago

Cazfri commented 5 years ago

Noticed tonight that the Bridge.load_scene function was working, complaining with the error message:

Traceback (most recent call last):
  File "/Users/noah/code/viki/app/hue/hue.py", line 35, in <module>
    h.load_scene('Relax')
  File "/Users/noah/code/viki/app/hue/hue.py", line 17, in load_scene
    self.bridge.run_scene('Noah Bedroom', scene_name)
  File "/Users/noah/code/viki/venv/lib/python3.7/site-packages/phue.py", line 1166, in run_scene
    scenes = [x for x in self.scenes if x.name == scene_name]
  File "/Users/noah/code/viki/venv/lib/python3.7/site-packages/phue.py", line 1138, in scenes
    return [Scene(k, **v) for k, v in self.get_scene().items()]
  File "/Users/noah/code/viki/venv/lib/python3.7/site-packages/phue.py", line 1138, in <listcomp>
    return [Scene(k, **v) for k, v in self.get_scene().items()]
TypeError: __init__() got an unexpected keyword argument 'type'

When I tested on the Hue API debugging tool at /api/<username>/scenes, I got responses such as

{
    "KL2XQKROiKfvwQU": {
        "name": "Savanna sunset",
        "type": "GroupScene",
        "group": "1",
        "lights": [
            "1",
            "2"
        ],
        "owner": "Z6JmooCHGmbrg65weMUH5dPnTPtP1ryQ5kTwnS2x",
        "recycle": false,
        "locked": false,
        "appdata": {
            "version": 1,
            "data": "XqVVT_r01_d15"
        },
        "picture": "",
        "lastupdated": "2018-09-07T02:28:38",
        "version": 2
    },
        ...
}

The type and group properties must have been causing the error. My fix just adds the two new properties, and adds *args and *kwargs to catch any future unexpected property additions.

Passes unit tests, though there didn't seem to be any tests that specifically tested this function.

Tested manually with the following software versions: Bridge: Version 1810251352 Lights: Version 1.29.0_r21169

blacklight commented 5 years ago

Please update the pip package as well as the current version on PyPI still has the issue with changing scenes.