IEnumerator CreateUserEnumerator( string applicationName, string deviceName, Action <string> generatedUserName, Action <List <HueErrorInfo> > errorCallback = null ) { var body = new Dictionary <string, object>() { { HueKeys.DEVICE_TYPE, string.Format("{0}#{1}", applicationName, deviceName) } }; var www = new WWWWrapper(BaseURL, body); yield return(www.waitToFinish()); if (isValidJsonResponse(www, errorCallback)) { JSON response = www.responseJSON.getJsonArray("rootArray")[0].getJSON("success"); var userName = response.getString(HueKeys.USER_NAME, ""); if (userName != "") { generatedUserName(userName); } } }
IEnumerator DeleteEnumerator(string url, Action <List <HueErrorInfo> > errorCallback = null) { var www = new WWWWrapper(url, method: HTTPMethod.DELETE); yield return(www.waitToFinish()); isValidJsonResponse(www, errorCallback); // Just check for errors. }
IEnumerator SendRequestEnumerator(WWWWrapper www, Action <string> successCallback, Action <List <HueErrorInfo> > errorCallback = null) { yield return(www.waitToFinish()); if (isValidJsonResponse(www, errorCallback) && successCallback != null) { successCallback(www.responseText); } }
IEnumerator GetBridgesEnumerator(Action <List <HueBridgeInfo> > bridgesCallback, Action <List <HueErrorInfo> > errorCallback = null) { var www = new WWWWrapper(hueDiscoveryServer); yield return(www.waitToFinish()); if (isValidJsonResponse(www, errorCallback)) { ProcessBridges(www.responseJSON, bridgesCallback); } }
IEnumerator DiscoverGroupsEnumerator(Action <List <HueGroup> > groupsCallback, Action <List <HueErrorInfo> > errorCallback) { string url = string.Format("{0}/{1}/groups", BaseURL, currentBridge.userName); var www = new WWWWrapper(url); yield return(www.waitToFinish()); if (isValidJsonResponse(www, errorCallback)) { ProcessGroups(www.responseJSON, groupsCallback); } }
IEnumerator UpdateLightFromBridgeEnumerator(string id, HueLight lightToUpdate, Action <List <HueErrorInfo> > errorCallback = null) { string url = string.Format("{0}/lights/{1}", BaseURLWithUserName, id); var www = new WWWWrapper(url); yield return(www.waitToFinish()); if (isValidJsonResponse(www, errorCallback)) { ProcessLightUpdate(www.responseJSON, lightToUpdate); } }