// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package com.philips.lighting.hue.sdk.clip; import com.philips.lighting.hue.sdk.utilities.PHUtilities; import com.philips.lighting.hue.sdk.utilities.impl.PHLog; import com.philips.lighting.model.PHBridgeConfiguration; import com.philips.lighting.model.PHBridgeResource; import com.philips.lighting.model.PHGroup; import com.philips.lighting.model.PHHueError; import com.philips.lighting.model.PHLight; import com.philips.lighting.model.PHLightState; import com.philips.lighting.model.PHSchedule; import com.philips.lighting.model.PHSoftwareUpdateStatus; import java.util.ArrayList; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; // Referenced classes of package com.philips.lighting.hue.sdk.clip: // PHCLIPParser public class PHCLIPParser1_0 implements PHCLIPParser { public static final int LOCAL_KEY = 4626; public static final int PORTAL_KEY = 13364; private static final String TAG = "PHCLIPParser1_0"; public String errorMassage; public PHCLIPParser1_0() { } private com.philips.lighting.model.PHLight.PHLightAlertMode chooseAlertMode(String s) { if (s != null && s.length() != 0) { if (s.equalsIgnoreCase("select")) { return com.philips.lighting.model.PHLight.PHLightAlertMode.ALERT_SELECT; } if (s.equalsIgnoreCase("lselect")) { return com.philips.lighting.model.PHLight.PHLightAlertMode.ALERT_LSELECT; } if (s.equalsIgnoreCase("none")) { return com.philips.lighting.model.PHLight.PHLightAlertMode.ALERT_NONE; } else { return com.philips.lighting.model.PHLight.PHLightAlertMode.ALERT_UNKNOWN; } } else { return null; } } private com.philips.lighting.model.PHLight.PHLightColorMode chooseColorMode(String s) { if (s != null && s.length() != 0) { if (s.equalsIgnoreCase("ct")) { return com.philips.lighting.model.PHLight.PHLightColorMode.COLORMODE_CT; } if (s.equalsIgnoreCase("hs")) { return com.philips.lighting.model.PHLight.PHLightColorMode.COLORMODE_HUE_SATURATION; } if (s.equalsIgnoreCase("xy")) { return com.philips.lighting.model.PHLight.PHLightColorMode.COLORMODE_XY; } if (s.equalsIgnoreCase("none")) { return com.philips.lighting.model.PHLight.PHLightColorMode.COLORMODE_NONE; } else { return com.philips.lighting.model.PHLight.PHLightColorMode.COLORMODE_UNKNOWN; } } else { return null; } } private com.philips.lighting.model.PHLight.PHLightEffectMode chooseEffectMode(String s) { if (s != null && s.length() != 0) { if (s.equalsIgnoreCase("colorloop")) { return com.philips.lighting.model.PHLight.PHLightEffectMode.EFFECT_COLORLOOP; } if (s.equalsIgnoreCase("none")) { return com.philips.lighting.model.PHLight.PHLightEffectMode.EFFECT_NONE; } else { return com.philips.lighting.model.PHLight.PHLightEffectMode.EFFECT_UNKNOWN; } } else { return null; } } public static PHCLIPParser1_0 getInstance(int i) { if (i == 4626 || i == 13364) { return new PHCLIPParser1_0(); } else { return null; } } public String getErrorMassage() { return errorMassage; } public PHBridgeConfiguration parseBridgeConfiguration(JSONObject jsonobject) { PHBridgeConfiguration phbridgeconfiguration = new PHBridgeConfiguration(); JSONObject jsonobject2 = jsonobject.optJSONObject("config"); JSONObject jsonobject1 = jsonobject2; if (jsonobject2 == null) { jsonobject1 = jsonobject; } if (jsonobject1 != null) { String s = jsonobject1.optString("ipaddress"); String s1 = jsonobject1.optString("mac"); String s2 = jsonobject1.optString("name"); String s3 = jsonobject1.optString("proxyaddress"); String s4 = jsonobject1.optString("netmask"); String s5 = jsonobject1.optString("gateway"); int i = jsonobject1.optInt("proxyport"); Boolean boolean1; String s6; String s7; PHSoftwareUpdateStatus phsoftwareupdatestatus; if (jsonobject1.isNull("dhcp")) { jsonobject = null; } else { jsonobject = Boolean.valueOf(jsonobject1.optBoolean("dhcp")); } s6 = jsonobject1.optString("swversion"); if (jsonobject1.isNull("portalservices")) { boolean1 = null; } else { boolean1 = Boolean.valueOf(jsonobject1.optBoolean("portalservices")); } s7 = jsonobject1.optString("UTC"); phsoftwareupdatestatus = new PHSoftwareUpdateStatus(); jsonobject1 = jsonobject1.optJSONObject("swupdate"); if (jsonobject1 != null) { if (jsonobject1.optBoolean("notify")) { phsoftwareupdatestatus.setState(com.philips.lighting.model.PHSoftwareUpdateStatus.PHStateType.UPDATE_INSTALLED); phsoftwareupdatestatus.setNotify(true); } else { phsoftwareupdatestatus.setState(jsonobject1.optInt("updatestate")); phsoftwareupdatestatus.setNotify(false); } phsoftwareupdatestatus.setReleaseNotesUrl(jsonobject1.optString("url")); phsoftwareupdatestatus.setUpdateText(jsonobject1.optString("text")); } else { phsoftwareupdatestatus.setNotify(false); } if (phbridgeconfiguration != null) { phbridgeconfiguration.setIpAddress(s); phbridgeconfiguration.setName(s2); phbridgeconfiguration.setProxy(s3); phbridgeconfiguration.setProxyPort(Integer.valueOf(i).intValue()); phbridgeconfiguration.setNetmask(s4); phbridgeconfiguration.setGateway(s5); phbridgeconfiguration.setDhcpEnabled(jsonobject); phbridgeconfiguration.setSoftwareVersion(s6); phbridgeconfiguration.setPortalServicesEnabled(boolean1); phbridgeconfiguration.setSoftwareStatus(phsoftwareupdatestatus); phbridgeconfiguration.setTime(s7); phbridgeconfiguration.setMacAddress(s1); } } return phbridgeconfiguration; } public List parseError(String s) { ArrayList arraylist = new ArrayList(); JSONObject jsonobject; int i; try { s = new JSONArray(s); } // Misplaced declaration of an exception variable catch (String s) { if (PHLog.isLoggable()) { PHLog.e("PHCLIPParser1_0", (new StringBuilder("JSONException: ")).append(s).toString()); } return arraylist; } i = 0; if (i >= s.length()) { return arraylist; } jsonobject = s.optJSONObject(i); if (jsonobject == null) { break MISSING_BLOCK_LABEL_89; } jsonobject = jsonobject.optJSONObject("error"); if (jsonobject == null) { break MISSING_BLOCK_LABEL_89; } arraylist.add(new PHHueError(jsonobject.optInt("type"), jsonobject.optString("description"), jsonobject.optString("address"))); i++; if (false) { } else { break MISSING_BLOCK_LABEL_20; } } public List parseGetAllGroup(String s) { ArrayList arraylist = new ArrayList(); JSONObject jsonobject = new JSONObject(s); s = arraylist; if (jsonobject == null) { break MISSING_BLOCK_LABEL_133; } JSONArray jsonarray = jsonobject.names(); int i; s = arraylist; if (jsonarray == null) { break MISSING_BLOCK_LABEL_133; } i = 0; _L1: if (i >= jsonarray.length()) { return arraylist; } JSONObject jsonobject1; s = jsonarray.optString(i); jsonobject1 = jsonobject.optJSONObject(s); if (jsonobject1 == null) { break MISSING_BLOCK_LABEL_93; } arraylist.add(new PHBridgeResource(jsonobject1.optString("name"), s)); i++; goto _L1 s; if (PHLog.isLoggable()) { PHLog.e("PHCLIPParser1_0", (new StringBuilder("JSONException: ")).append(s).toString()); } s = null; return s; } public List parseGetAllLightHeaders(String s) { ArrayList arraylist = new ArrayList(); s = new JSONObject(s); if (s == null) goto _L2; else goto _L1 _L1: JSONArray jsonarray; jsonarray = s.names(); arraylist.clear(); if (jsonarray == null) goto _L2; else goto _L3 _L3: int i = 0; _L4: if (i >= jsonarray.length()) { break; /* Loop/switch isn't completed */ } String s1; JSONObject jsonobject; s1 = jsonarray.optString(i); jsonobject = s.optJSONObject(s1); if (jsonobject == null) { break MISSING_BLOCK_LABEL_95; } arraylist.add(new PHBridgeResource(jsonobject.optString("name"), s1)); i++; if (true) goto _L4; else goto _L2 s; _L5: if (PHLog.isLoggable()) { PHLog.e("PHCLIPParser1_0", (new StringBuilder("JSONException: ")).append(s).toString()); } return null; s; if (true) goto _L5; else goto _L2 _L2: return arraylist; } public PHGroup parseGetGroupDetails(String s, String s1) { JSONObject jsonobject = new JSONObject(s); if (jsonobject == null) goto _L2; else goto _L1 _L1: String as[]; JSONArray jsonarray; s = jsonobject.optString("name"); jsonarray = jsonobject.optJSONArray("lights"); as = new String[jsonarray.length()]; int i = 0; _L4: if (i < jsonarray.length()) { break MISSING_BLOCK_LABEL_68; } s = new PHGroup(s, s1); s.setLightIdentifiers(as); return s; as[i] = jsonarray.optString(i); i++; if (true) goto _L4; else goto _L3 _L3: s; _L6: if (PHLog.isLoggable()) { PHLog.e("PHCLIPParser1_0", (new StringBuilder("JSONException: ")).append(s).toString()); } _L2: return null; s; if (true) goto _L6; else goto _L5 _L5: } public List parseGroups(JSONObject jsonobject) { JSONObject jsonobject1; ArrayList arraylist; arraylist = new ArrayList(); JSONObject jsonobject2 = jsonobject.optJSONObject("groups"); jsonobject1 = jsonobject2; if (jsonobject2 == null) { jsonobject1 = jsonobject; } if (jsonobject1 == null) goto _L2; else goto _L1 _L1: jsonobject = jsonobject1.names(); if (jsonobject == null) goto _L2; else goto _L3 _L3: int i = 0; _L9: if (i < jsonobject.length()) goto _L4; else goto _L2 _L2: return arraylist; _L4: Object obj; JSONObject jsonobject3; obj = jsonobject.optString(i); jsonobject3 = jsonobject1.optJSONObject(((String) (obj))); if (jsonobject3 == null) goto _L6; else goto _L5 _L5: JSONArray jsonarray; jsonarray = jsonobject3.optJSONArray("lights"); obj = new PHGroup(jsonobject3.optString("name"), ((String) (obj))); if (jsonarray == null) goto _L8; else goto _L7 _L7: String as[]; int j; as = new String[jsonarray.length()]; j = 0; _L10: if (j < as.length) { break MISSING_BLOCK_LABEL_151; } ((PHGroup) (obj)).setLightIdentifiers(as); _L8: arraylist.add(obj); _L6: i++; goto _L9 as[j] = jsonarray.optString(j); j++; goto _L10 } public boolean parseIsSuccess(String s) { boolean flag1 = false; s = (new JSONArray(s)).optJSONObject(0); boolean flag; flag = flag1; if (s == null) { break MISSING_BLOCK_LABEL_37; } s = s.optString("success"); flag = flag1; if (s != null) { flag = true; } _L2: return flag; s; flag = flag1; if (PHLog.isLoggable()) { PHLog.e("PHCLIPParser1_0", (new StringBuilder("JSONException: ")).append(s).toString()); return false; } if (true) goto _L2; else goto _L1 _L1: } public PHLight parseLightDetails(String s, String s1) { JSONObject jsonobject = new JSONObject(s); if (jsonobject == null) goto _L2; else goto _L1 _L1: String s2 = jsonobject.optString("name"); s = jsonobject.optString("type"); String s3 = jsonobject.optString("modelid"); String s4 = jsonobject.optString("swversion"); boolean flag = jsonobject.optBoolean("reachable"); s1 = new PHLight(s2, s1, s4, s3); s1.setLightType(s); s1.setReachable(flag); return s1; s; _L4: if (PHLog.isLoggable()) { PHLog.e("PHCLIPParser1_0", (new StringBuilder("JSONException: ")).append(s).toString()); } _L2: return null; s; if (true) goto _L4; else goto _L3 _L3: } PHLightState parseLightState(JSONObject jsonobject) { PHLightState phlightstate = new PHLightState(); Boolean boolean1; Float float1; Object obj; String s; String s1; int i; int j; int k; int l; if (jsonobject.isNull("on")) { boolean1 = null; } else { boolean1 = Boolean.valueOf(jsonobject.optBoolean("on")); } i = jsonobject.optInt("bri"); j = jsonobject.optInt("hue"); k = jsonobject.optInt("sat"); obj = jsonobject.optJSONArray("xy"); if (obj != null) { float1 = Float.valueOf((float)((JSONArray) (obj)).optDouble(0)); obj = Float.valueOf((float)((JSONArray) (obj)).optDouble(1)); } else { float1 = Float.valueOf(0.0F); obj = Float.valueOf(0.0F); } l = jsonobject.optInt("ct"); s = jsonobject.optString("alert"); s1 = jsonobject.optString("effect"); jsonobject = jsonobject.optString("colormode"); phlightstate.setOn(boolean1); phlightstate.setBrightness(Integer.valueOf(i).intValue()); phlightstate.setHue(Integer.valueOf(j).intValue()); phlightstate.setSaturation(Integer.valueOf(k).intValue()); phlightstate.setX(float1.floatValue()); phlightstate.setY(((Float) (obj)).floatValue()); phlightstate.setCt(Integer.valueOf(l).intValue()); phlightstate.setAlertMode(chooseAlertMode(s)); phlightstate.setEffectMode(chooseEffectMode(s1)); phlightstate.setColorMode(chooseColorMode(jsonobject)); return phlightstate; } public List parseLights(JSONObject jsonobject) { JSONObject jsonobject1; ArrayList arraylist; arraylist = new ArrayList(); JSONObject jsonobject2 = jsonobject.optJSONObject("lights"); jsonobject1 = jsonobject2; if (jsonobject2 == null) { jsonobject1 = jsonobject; } if (jsonobject1 == null) goto _L2; else goto _L1 _L1: jsonobject = jsonobject1.names(); if (jsonobject == null) goto _L2; else goto _L3 _L3: int i = 0; _L6: if (i < jsonobject.length()) goto _L4; else goto _L2 _L2: return arraylist; _L4: Object obj = jsonobject.optString(i); JSONObject jsonobject3 = jsonobject1.optJSONObject(((String) (obj))); if (jsonobject3 != null) { String s = jsonobject3.optString("type"); String s1 = jsonobject3.optString("name"); String s2 = jsonobject3.optString("modelid"); String s3 = jsonobject3.optString("swversion"); jsonobject3 = jsonobject3.optJSONObject("state"); obj = new PHLight(s1, ((String) (obj)), s3, s2); ((PHLight) (obj)).setLightType(s); if (jsonobject3 != null) { ((PHLight) (obj)).setReachable(jsonobject3.optBoolean("reachable")); PHLightState phlightstate = parseLightState(jsonobject3); if (phlightstate != null) { ((PHLight) (obj)).setLastKnownLightState(phlightstate); } } else { ((PHLight) (obj)).setLastKnownLightState(null); } arraylist.add(obj); } i++; if (true) goto _L6; else goto _L5 _L5: } public List parseScene(JSONObject jsonobject) { return null; } public List parseSchedules(JSONObject jsonobject) { JSONObject jsonobject1; ArrayList arraylist; arraylist = new ArrayList(); JSONObject jsonobject2 = jsonobject.optJSONObject("schedules"); jsonobject1 = jsonobject2; if (jsonobject2 == null) { jsonobject1 = jsonobject; } if (jsonobject1 == null) goto _L2; else goto _L1 _L1: jsonobject = jsonobject1.names(); if (jsonobject == null) goto _L2; else goto _L3 _L3: int i = 0; _L10: if (i < jsonobject.length()) goto _L4; else goto _L2 _L2: return arraylist; _L4: Object obj; Object obj1; Object obj2; JSONObject jsonobject3; Iterator iterator; int j; obj2 = jsonobject.optString(i); obj = jsonobject1.optJSONObject(((String) (obj2))); if (obj == null) { break MISSING_BLOCK_LABEL_477; } obj1 = ((JSONObject) (obj)).optString("name"); if (obj1 == null || ((String) (obj1)).length() == 0) { errorMassage = "JSON is missing key: name"; return null; } obj1 = new PHSchedule(((String) (obj1))); ((PHSchedule) (obj1)).setIdentifier(((String) (obj2))); ((PHSchedule) (obj1)).setDescription(((JSONObject) (obj)).optString("description")); jsonobject3 = ((JSONObject) (obj)).optJSONObject("command"); if (jsonobject3 == null) { break MISSING_BLOCK_LABEL_446; } obj2 = new ArrayList(); ((List) (obj2)).add("address"); ((List) (obj2)).add("body"); ((List) (obj2)).add("method"); iterator = jsonobject3.keys(); j = 0; _L7: if (iterator.hasNext()) goto _L6; else goto _L5 _L5: if (j == 3) { break MISSING_BLOCK_LABEL_362; } jsonobject = ""; i = 0; _L8: if (i >= ((List) (obj2)).size()) { jsonobject = jsonobject.substring(0, jsonobject.length() - 1); errorMassage = (new StringBuilder("JSON is missing key : command(")).append(jsonobject).append(").").toString(); return null; } break MISSING_BLOCK_LABEL_317; _L6: String s = (String)iterator.next(); if (((List) (obj2)).contains(s)) { ((List) (obj2)).remove(s); j++; } goto _L7 jsonobject = (new StringBuilder(String.valueOf(jsonobject))).append((String)((List) (obj2)).get(i)).append(",").toString(); i++; goto _L8 Object obj3 = jsonobject3.optString("address"); jsonobject3 = jsonobject3.optJSONObject("body"); obj3 = ((String) (obj3)).split("/"); if (obj3.length > 4) { if (obj3[3].equals("groups")) { ((PHSchedule) (obj1)).setGroupIdentifier(obj3[4]); } else if (obj3[3].equals("lights")) { ((PHSchedule) (obj1)).setLightIdentifier(obj3[4]); } } if (jsonobject3 != null) { obj3 = parseLightState(jsonobject3); if (obj3 != null) { ((PHSchedule) (obj1)).setLightState(((PHLightState) (obj3))); } } obj = ((JSONObject) (obj)).optString("time"); if (obj != null) { ((PHSchedule) (obj1)).setDate(PHUtilities.stringToDate(((String) (obj)))); } arraylist.add(obj1); i++; if (true) goto _L10; else goto _L9 _L9: } public Hashtable parseSuccess(String s) { int i; Hashtable hashtable = new Hashtable(); JSONObject jsonobject; Iterator iterator; String s1; try { s = new JSONArray(s); } // Misplaced declaration of an exception variable catch (String s) { if (PHLog.isLoggable()) { PHLog.e("PHCLIPParser1_0", (new StringBuilder("JSONException: ")).append(s).toString()); } return hashtable; } i = 0; _L4: if (i >= s.length()) { return hashtable; } jsonobject = s.optJSONObject(i); if (jsonobject == null) { break MISSING_BLOCK_LABEL_132; } jsonobject = jsonobject.optJSONObject("success"); if (jsonobject == null) { break MISSING_BLOCK_LABEL_132; } iterator = jsonobject.keys(); _L2: if (!iterator.hasNext()) { break MISSING_BLOCK_LABEL_132; } s1 = (String)iterator.next(); hashtable.put(s1, jsonobject.optString(s1)); if (true) goto _L2; else goto _L1 _L1: i++; if (true) goto _L4; else goto _L3 _L3: } }