// 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.model.PHBridgeConfiguration; import com.philips.lighting.model.PHScene; import com.philips.lighting.model.PHSchedule; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale; import java.util.TimeZone; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; // Referenced classes of package com.philips.lighting.hue.sdk.clip: // PHCLIPBuilder1_0, PHCLIPBuilder public class PHCLIPBuilder1_1 extends PHCLIPBuilder1_0 implements PHCLIPBuilder { public PHCLIPBuilder1_1() { } public static volatile PHCLIPBuilder1_0 getInstance(int i) { return getInstance(i); } public static PHCLIPBuilder1_1 getInstance(int i) { if (i == 4626 || i == 13364) { return new PHCLIPBuilder1_1(); } else { return null; } } public String createActivateScenePacket(String s) throws JSONException { JSONObject jsonobject = new JSONObject(); jsonobject.putOpt("scene", s); return jsonobject.toString(); } public String createFindLightSerialsPacket(List list) throws JSONException { JSONObject jsonobject = new JSONObject(); JSONArray jsonarray = new JSONArray(); int i = 0; do { if (i >= list.size()) { jsonobject.putOpt("deviceid", jsonarray); return jsonobject.toString(); } jsonarray.put(i, list.get(i)); i++; } while (true); } public JSONObject createSceneJSONPacket(String s, String as[]) throws JSONException { JSONObject jsonobject = new JSONObject(); JSONArray jsonarray = new JSONArray(); int i = 0; do { if (i >= as.length) { jsonobject.putOpt("name", s); jsonobject.putOpt("lights", jsonarray); return jsonobject; } jsonarray.put(i, as[i]); i++; } while (true); } public String createScenePacket(String s, String as[]) throws JSONException { return createSceneJSONPacket(s, as).toString(); } public String createScenePacket1_1_1(PHScene phscene) throws JSONException { JSONObject jsonobject = createSceneJSONPacket(phscene.getName(), phscene.getLightIdentifiers()); if (phscene.getTransitionTime() != 0) { jsonobject.put("transitiontime", phscene.getTransitionTime()); } return jsonobject.toString(); } public String createSchedulePacket(PHSchedule phschedule, String s, String s1) throws JSONException { return createSchedulePacket(phschedule, s, s1, "UTC"); } public String createSchedulePacket(PHSchedule phschedule, String s, String s1, String s2) throws JSONException { Object obj = new JSONObject(); if (s != null) { ((JSONObject) (obj)).putOpt("address", s); } if (s1 != null) { ((JSONObject) (obj)).putOpt("method", s1); } JSONObject jsonobject; if (phschedule.getLightIdentifier() != null || phschedule.getGroupIdentifier() != null && phschedule.getSceneIdentifier() == null) { if (phschedule.getLightState() != null) { ((JSONObject) (obj)).putOpt("body", lightStateForIdPacket(phschedule.getLightState())); } } else if (phschedule.getGroupIdentifier() != null && phschedule.getSceneIdentifier() != null) { s = new JSONObject(); s.putOpt("scene", phschedule.getSceneIdentifier()); ((JSONObject) (obj)).putOpt("body", s); } jsonobject = new JSONObject(); if (phschedule.getName() != null) { jsonobject.putOpt("name", phschedule.getName()); } if (phschedule.getDescription() != null && phschedule.getDescription().length() != 0) { jsonobject.putOpt("description", phschedule.getDescription()); } if (obj != null) { jsonobject.putOpt("command", obj); } obj = phschedule.getDate(); s = "time"; if (phschedule.getLocalTime() != null && phschedule.getLocalTime().booleanValue()) { s = "localtime"; } else { s2 = "UTC"; } s1 = ""; if (phschedule.getRandomTime() != 0) { s1 = String.format("A%02d:%02d:%02d", new Object[] { Integer.valueOf(phschedule.getRandomTime() / 3600), Integer.valueOf((phschedule.getRandomTime() % 3600) / 60), Integer.valueOf(phschedule.getRandomTime() % 3600 % 60) }); } if (obj != null) { if (phschedule.getRecurringDays() != 0) { SimpleDateFormat simpledateformat = new SimpleDateFormat("HH:mm:ss", new Locale("nl_NL")); simpledateformat.setTimeZone(TimeZone.getTimeZone(s2)); s2 = simpledateformat.format(((java.util.Date) (obj))); jsonobject.putOpt(s, "" + 'W' + phschedule.getRecurringDays() + "/T" + s2 + s1); } else { phschedule = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", new Locale("nl_NL")); phschedule.setTimeZone(TimeZone.getTimeZone(s2)); jsonobject.putOpt(s, String.format("%s%s", new Object[] { phschedule.format(((java.util.Date) (obj))), s1 })); } } else if (phschedule.getTimer() != 0) { int i = phschedule.getTimer(); s2 = String.format("%02d:%02d:%02d", new Object[] { Integer.valueOf(i / 3600), Integer.valueOf((i / 60) % 60), Integer.valueOf(i % 60) }); if (phschedule.getRecurringTimerInterval() == -1) { jsonobject.putOpt(s, String.format("R/PT%s%s", new Object[] { s2, s1 })); } else if (phschedule.getRecurringTimerInterval() > 0) { jsonobject.putOpt(s, String.format("R%02d/PT%s%s", new Object[] { Integer.valueOf(phschedule.getRecurringTimerInterval()), s2, s1 })); } else { jsonobject.putOpt(s, String.format("PT%s%s", new Object[] { s2, s1 })); } } return jsonobject.toString().replace("\\/", "/"); } public String createUpdateBridge(PHBridgeConfiguration phbridgeconfiguration) throws JSONException { JSONObject jsonobject = new JSONObject(super.createUpdateBridge(phbridgeconfiguration)); if (phbridgeconfiguration.getTimeZone() != null && phbridgeconfiguration.getTimeZone().length() > 0) { jsonobject.putOpt("timezone", phbridgeconfiguration.getTimeZone()); } if (phbridgeconfiguration.getLocalTime() != null && phbridgeconfiguration.getLocalTime().length() > 0) { jsonobject.putOpt("localtime", phbridgeconfiguration.getLocalTime()); } return jsonobject.toString(); } public String updateSchedulePacket(PHSchedule phschedule, String s, String s1) throws JSONException { return updateSchedulePacket(phschedule, s, s1, "UTC"); } public String updateSchedulePacket(PHSchedule phschedule, String s, String s1, String s2) throws JSONException { JSONObject jsonobject; Object obj; obj = new JSONObject(); if (s != null) { ((JSONObject) (obj)).putOpt("address", s); } if (s1 != null) { ((JSONObject) (obj)).putOpt("method", s1); } if (phschedule.getLightState() != null) { ((JSONObject) (obj)).putOpt("body", lightStateForIdPacket(phschedule.getLightState())); } jsonobject = new JSONObject(); if (phschedule.getName() != null) { jsonobject.putOpt("name", phschedule.getName()); } if (phschedule.getDescription() != null && phschedule.getDescription().length() != 0) { jsonobject.putOpt("description", phschedule.getDescription()); } if (obj != null) { jsonobject.putOpt("command", obj); } obj = phschedule.getDate(); s = "time"; SimpleDateFormat simpledateformat; if (phschedule.getLocalTime() != null && phschedule.getLocalTime().booleanValue()) { s = "localtime"; } else { s2 = "UTC"; } s1 = ""; if (phschedule.getRandomTime() != 0) { s1 = String.format("A%02d:%02d:%02d", new Object[] { Integer.valueOf(phschedule.getRandomTime() / 3600), Integer.valueOf((phschedule.getRandomTime() % 3600) / 60), Integer.valueOf(phschedule.getRandomTime() % 3600 % 60) }); } if (obj == null) goto _L2; else goto _L1 _L1: if (phschedule.getRecurringDays() != 0) { simpledateformat = new SimpleDateFormat("HH:mm:ss", new Locale("nl_NL")); simpledateformat.setTimeZone(TimeZone.getTimeZone(s2)); s2 = simpledateformat.format(((java.util.Date) (obj))); jsonobject.putOpt(s, String.format("W%03d/T%s%s", new Object[] { Integer.valueOf(phschedule.getRecurringDays()), s2, s1 })); } else { phschedule = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", new Locale("nl_NL")); phschedule.setTimeZone(TimeZone.getTimeZone(s2)); jsonobject.putOpt(s, String.format("%s%s", new Object[] { phschedule.format(((java.util.Date) (obj))), s1 })); } _L4: return jsonobject.toString().replace("\\/", "/"); _L2: if (phschedule.getTimer() != 0) { int i = phschedule.getTimer(); s2 = String.format("%02d:%02d:%02d", new Object[] { Integer.valueOf(i / 3600), Integer.valueOf((i / 60) % 60), Integer.valueOf(i % 60) }); if (phschedule.getRecurringTimerInterval() > 0) { jsonobject.putOpt(s, String.format("R%02d/PT%s%s", new Object[] { Integer.valueOf(phschedule.getRecurringTimerInterval()), s2, s1 })); } else { jsonobject.putOpt(s, String.format("PT%s%s", new Object[] { s2, s1 })); } } if (true) goto _L4; else goto _L3 _L3: } }