public void signalLight(String lightName) { if (lightName.equals("None")) { return; } HashMap<String, PHLightState> lightModes = new HashMap<>(); if (lightName.equals("All")) { for (int i = 1; i < frame.lightSelection.getItemCount() - 1; i++) { String name = frame.lightSelection.getItemAt(i); PHLight light = hue.getLight(name); PHLightState oldState = light.getLastKnownLightState(); PHLightState lightState = new PHLightState(); lightState.setHue(oldState.getHue()); lightState.setSaturation(oldState.getSaturation()); lightState.setBrightness(oldState.getBrightness()); lightState.setTransitionTime(oldState.getTransitionTime()); lightState.setOn(oldState.isOn()); lightModes.put(name, lightState); } } else { PHLight light = hue.getLight(lightName); if (light != null) { PHLightState oldState = light.getLastKnownLightState(); PHLightState lightState = new PHLightState(); lightState.setHue(oldState.getHue()); lightState.setSaturation(oldState.getSaturation()); lightState.setBrightness(oldState.getBrightness()); lightModes.put(lightName, lightState); } } try { hue.setLight(lightName, HueController.MAX_HUE / 2, 254, 254, 0); Thread.sleep(750); turnCurrLight(false); Thread.sleep(750); } catch (InterruptedException ie) { ie.printStackTrace(); } for (String name : lightModes.keySet()) { PHLightState state = lightModes.get(name); hue.setLight(name, state.getHue(), state.getSaturation(), state.getBrightness(), 0); } }
public void randomLights() { PHBridge bridge = phHueSDK.getSelectedBridge(); List<PHLight> allLights = bridge.getResourceCache().getAllLights(); Random rand = new Random(); for (PHLight light : allLights) { PHLightState lightState = new PHLightState(); lightState.setHue(rand.nextInt(MAX_HUE)); // To validate your lightstate is valid (before sending to the bridge) you can use: // String validState = lightState.validateState(); bridge.updateLightState(light, lightState, listener); // bridge.updateLightState(light, lightState); // If no bridge response is required then use // this simpler form. } }