@PUT
  @Timed
  @Path("{sceneId}/recall")
  public void recallSceneStates(
      @PathParam("groupId") long groupId, @PathParam("sceneId") long sceneId) {

    Group group = groups.getGroupById(groupId);
    if (group == null) {
      throw new WebApplicationException(404);
    }

    Scene scene = group.getScenes().getSceneById(sceneId);
    if (scene == null) {
      throw new WebApplicationException(404);
    }

    serialComm.writeCommand(
        "recallScene -g "
            + group.getGroupAddress()
            + " "
            + Constants.DUMMY_ENDPOINT
            + " "
            + group.getGroupAddress()
            + " "
            + scene.getId());
  }
  @POST
  @Timed
  public Scene createNewScene(
      @PathParam("groupId") long groupId, @QueryParam("name") Optional<String> name) {

    Group group = groups.getGroupById(groupId);
    if (group == null) {
      throw new WebApplicationException(404);
    }

    Scenes scenes = group.getScenes();
    Scene newScene = scenes.createNewScene();

    if (name.isPresent()) {
      newScene.setName(name.get());
    }

    List<Long> lightIds = group.getLights();
    for (Long lightId : lightIds) {

      long prevStateLastUpdated = newScene.getStateLastUpdated();
      Light light = lights.getLightById(lightId);
      serialComm.writeCommand(
          "storeScene -s "
              + light.getShortNwkAddress()
              + " "
              + light.getEndpointId()
              + " "
              + group.getGroupAddress()
              + " "
              + newScene.getId());

      long timeout = System.currentTimeMillis() + Config.WAIT_ATTR_TIMEOUT_MS;
      while (newScene.getStateLastUpdated() <= prevStateLastUpdated) {
        if (System.currentTimeMillis() >= timeout) break;
      }
    }

    return newScene;
  }
  @PUT
  @Timed
  @Path("{sceneId}/store")
  public Scene storeSceneStates(
      @PathParam("groupId") long groupId, @PathParam("sceneId") long sceneId) {

    Group group = groups.getGroupById(groupId);
    if (group == null) {
      throw new WebApplicationException(404);
    }

    Scene scene = group.getScenes().getSceneById(sceneId);
    if (scene == null) {
      throw new WebApplicationException(404);
    }

    List<Long> lightIds = group.getLights();
    for (Long lightId : lightIds) {

      long prevStateLastUpdated = scene.getStateLastUpdated();
      Light light = lights.getLightById(lightId);
      serialComm.writeCommand(
          "storeScene -s "
              + light.getShortNwkAddress()
              + " "
              + light.getEndpointId()
              + " "
              + group.getGroupAddress()
              + " "
              + scene.getId());

      long timeout = System.currentTimeMillis() + Config.WAIT_ATTR_TIMEOUT_MS;
      while (scene.getStateLastUpdated() <= prevStateLastUpdated) {
        if (System.currentTimeMillis() >= timeout) break;
      }
    }

    return scene;
  }