예제 #1
0
  public Bridge getSavedBridge() {
    Bridge bridge;
    File file = new File(BRIDGEFILE);
    StringBuilder json = new StringBuilder();
    try {
      if (!file.exists()) {
        return null;
      }
      FileReader fr = new FileReader(file.getAbsolutePath());
      BufferedReader br = new BufferedReader(fr);
      String currentLine = null;

      while ((currentLine = br.readLine()) != null) {
        json.append(currentLine);
      }
    } catch (IOException e) {
      e.printStackTrace();
      return null;
    }
    try {
      JSONObject jo = new JSONObject(json.toString());
      bridge =
          new Bridge(jo.getString("id"), jo.getString("internalip"), jo.getString("macaddres"));
      bridge.setUsername(jo.getString("username"));
    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }
    return bridge;
  }
예제 #2
0
  /**
   * Start authenticating with the chosen Hue Bridge, and save it to disk if everything is ok
   *
   * @param id Hue Bridge ID
   * @param ip Internal ip address of the local Hue Bridge
   * @param mac Mac address of the local Hue Bridge
   */
  public String setChosenBridge(String id, String ip, String mac)
      throws MalformedURLException, UnsupportedEncodingException, JSONException,
          URISyntaxException {
    Bridge chosenBridge = new Bridge(id, ip, mac);

    String username = authWithBridge(ip);
    if (username != "") {
      chosenBridge.setUsername(username);
      saveUsernameToDisk(chosenBridge);
    } else {
      logger.info("Username is empty, not saving to disk");
    }
    return username;
  }