PhilipsHue / HueSDK

Philips Hue Software Development Kit
98 stars 39 forks source link

Scene has no lightstates #25

Closed jeroenbeuz closed 6 years ago

jeroenbeuz commented 6 years ago

Scenes from the bridge state never have lights with a state. I noticed that every scene has the property storeLightstate on null. So I updated every scene to have storeLightstate on 'true', in the hope the lightstates would be saved so I can retrieve them. No luck. Also tried getting the scenes individually, like we had to in the PHHueSDK. Also no luck.

This is my code:

List<Scene> scenes = bridge.getBridgeState().getScenes();
for(Scene scene : scenes) {
            if (scene.getStoreLightState() == null || !scene.getStoreLightState()) {
                scene.setStoreLightState(true);
                bridge.updateResource(scene, bridgeResponseCallback);
            }
            // scene has no lightstates...
            Scene fullScene = bridge.getBridgeState().getScene(scene.getIdentifier());
            // even fullScene has no lightstates..
}

So how do I retrieve the lightstates of a scene from the bridge?

jhvdb87 commented 6 years ago

In order to get that information you have to explicitly call fetch() on the scene. Light states are not part of the full config or /api//scenes, but are only present in /api//scenes/.. that's why the fetch is required.

jeroenbeuz commented 6 years ago

I finally got this to work. Yes a fetch is required to get the full state of the scene. But the current way I fetch them makes no sense, so I hope theres a better way.

  1. Get all scenes from the bridge
  2. Call fetch(BridgeResponseCallback) on one of them
  3. This triggers the BridgeResponseCallback
  4. In that callback every scene with full state can be retreived.

In the callback you have no idea for which particular scene the callback fires. This does not make sense. I would expect this behavior for a method that fetches ALL scenes from the bridge. For fetching a single scene I would expect that scene to be available in the callback. Also, I would expect a fetchScenes to be available on the bridge. Now I first have to get the list of scenes on the bridge, fetch one of them, and then get the scenes with state in the callback.

jhvdb87 commented 6 years ago

The callback fires only for the scene were fetched is called on. It would be better to update the object itself where called fetch() on, so you don't need to get the fetched scene from the bridge state again. This improvement is on our backlog, but not planned for a release yet.