private async void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (userId == string.Empty) { return; } //Stopwatch sw = new Stopwatch(); //sw.Start(); try { string base_url = "http://" + ip + "/api/" + userId + "/"; double bri = ((Slider)sender).Value / 100 * 254; await LREST.Put(base_url + textBox_URL.Text, "{\"bri\":" + bri + "}", "", ".json"); //await lRest.Put("http://73.251.151.39/api/lz3nFIcGOelQlsxsDJYqrXGuxivjFmWswZ9fIGcw/lights/1/state", "{\"bri\":" + bri + "}", "", ".json"); //System.Threading.Thread.Sleep(50); //sw.Stop(); Console.WriteLine(bri); //Console.WriteLine("Get Request Completed in " + sw.Elapsed); } catch (Exception error) { MessageBox.Show(error.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Hand); } }
public async Task <bool> DeleteUser(string userId) { bool retVal = false; string webResponse = string.Empty; try { if (Debugger.IsAttached) { // Emulate response while debugging //webResponse = "[{\"id\":\"test\",\"internalipaddress\":\"73.251.151.39\"}]"; //webResponse = "[{\"id\":\"test\",\"internalipaddress\":\"wrightsew.ddns.net:6543\"}]"; } else { ///api/jbaNdiVb8TUJeyOPrS3SlKFgQmP62nMOOyPpTgAU/config/whitelist/jbaNdiVb8TUJeyOPrS3SlKFgQmP62nMOOyPpTgAU string url = string.Format("{0}/{1}/config/whitelist/{1}", getBaseUrl(ip), userId); webResponse = await LREST.Delete(url); } if (!webResponse.StartsWith("Error:")) { JArray jResponse = (JArray)JsonConvert.DeserializeObject(webResponse); if (jResponse.Count > 0) { if (jResponse[0]["success"].ToString().ToUpper().Contains(userId.ToUpper() + " DELETED")) { retVal = true; } //retVal = jResponse[0]["internalipaddress"].ToString(); } } //else //{ // MessageBox.Show("Can not find Philips Hue SmartHub.\r\nPlease plugin your hue hub and click connect again or type the IP manually.", "Failed to Find Hub", MessageBoxButton.OK, MessageBoxImage.Exclamation); // ip = "127.0.0.1"; //} } catch (Exception error) { System.Windows.MessageBox.Show("Error 01: " + error.Message); } return(retVal); }
public async Task <Response> GetResponse(bool refresh = false) { if (webResponse == null) { webResponse = new Response(); refresh = true; } if (refresh) { string base_url = "http://" + Ip + "/api/" + UserId + "/"; webResponse.Lights = (JObject)JsonConvert.DeserializeObject(await LREST.Get(base_url + "lights")); webResponse.Groups = (JObject)JsonConvert.DeserializeObject(await LREST.Get(base_url + "groups")); //await lRest.Put("http://73.251.151.39/api/lz3nFIcGOelQlsxsDJYqrXGuxivjFmWswZ9fIGcw/lights/1/state", "{\"bri\":" + bri + "}", "", ".json"); //System.Threading.Thread.Sleep(50); } return(webResponse); }
private async Task <string> CreateUserID() { string retVal = string.Empty; string createUser = "******"devicetype\":\"LINKS#PC-" + Environment.UserName.ToUpper() + "\"}"; if (Debugger.IsAttached) { // Emulate response while debugging createUser = "******"success\":{\"username\":\"7ngKxvpo5fuLWLmCZfb42KzvKSYlA6gGgX4CYFtN\"}}]"; } else { //"http://73.251.151.39/api/createUser createUser = await LREST.Post("http://" + ip + "/api", createUser, "", ".json"); } try { try { JArray jResponseO = (JArray)JsonConvert.DeserializeObject(createUser); retVal = jResponseO[0]["success"]["username"].ToString(); } catch { JArray jResponse = (JArray)JsonConvert.DeserializeObject(createUser); if (jResponse.Count > 0) { //MessageBox.Show(jResponse[0]["error"]["description"] + "\r\n Please press the button on the hue bridge and try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); //return; } } } catch (Exception error) { retVal = "Error: " + error.Message; } return(retVal); }
public async void SwitchDimmer(object sender, int value = -1) { SwitchView currentSwitchWindow = (SwitchView)sender; double bri = (value * (100.0 / 21)) / 100.0 * 254; float X, x1, x2, y1, y2; X = (float)bri; x1 = 0; // Range 1 x2 = 254; // Range 1 y1 = newMin; // Range 2 y2 = newMax; // Range 2 int res = Convert.ToInt16(RangeConv(X, x1, x2, y1, y2)); bri = Convert.ToInt32(res); Brightness = bri; if (bri == 0 && isOn) { //isOn = false; // lights off await SwitchState(false); } else if (bri > 0 && !isOn) { //isOn = true; // lights on await SwitchState(true); } if (bri > 0) { if (bri == 250) { bri = 254; } string state = "lights/" + LSwitch.Id + "/state"; await LREST.Put(base_url + state, "{\"bri\":" + bri + "}", "", ".json"); } }
public async Task <string> TryGetIP() { string retVal = string.Empty; string webResponse = string.Empty; try { if (Debugger.IsAttached) { // Emulate response while debugging webResponse = "[{\"id\":\"test\",\"internalipaddress\":\"73.251.151.39\"}]"; //webResponse = "[{\"id\":\"test\",\"internalipaddress\":\"wrightsew.ddns.net:6543\"}]"; } else { webResponse = await LREST.Get("https://www.meethue.com/api/nupnp"); } if (!webResponse.StartsWith("Error:")) { JArray jResponse = (JArray)JsonConvert.DeserializeObject(webResponse); if (jResponse.Count > 0) { retVal = jResponse[0]["internalipaddress"].ToString(); } } //else //{ // MessageBox.Show("Can not find Philips Hue SmartHub.\r\nPlease plugin your hue hub and click connect again or type the IP manually.", "Failed to Find Hub", MessageBoxButton.OK, MessageBoxImage.Exclamation); // ip = "127.0.0.1"; //} } catch (Exception error) { System.Windows.MessageBox.Show("Error 01: " + error.Message); } return(retVal); }