@Override public @Nonnull Iterable<Lightbulb> listBulbs() throws CommunicationException { HueMethod method = new HueMethod(this); JSONObject list = method.get("lights"); if (list == null) { return Collections.emptyList(); } ArrayList<Lightbulb> matches = new ArrayList<Lightbulb>(); for (String id : JSONObject.getNames(list)) { try { JSONObject item = list.getJSONObject(id); String name = (item.has("name") ? item.getString("name") : id); matches.add(new HueBulb(this, id, name)); } catch (JSONException e) { throw new HueException(e); } } return matches; }