private async void onBrightness_ValueChanged(object sender, MouseEventArgs e) { int lightIDX = lightIndices[dgvLights.CurrentCell.RowIndex]; RESTRequests r = new RESTRequests(theHueBridge.bridgeURLBase.Replace("http://", "").Replace(@":80/", "")); string singleLight = await r.GET("/api/" + APIKey + "/lights/" + (lightIDX)); JObject singleLightObj = JObject.Parse(singleLight); HueLight selectedLight = JsonConvert.DeserializeObject <HueLight>(singleLightObj.ToString()); if (tbBrightness.Value == tbBrightness.Minimum) { await r.PUT("/api/" + APIKey + "/lights/" + (lightIDX) + "/state", "{\"on\":false}", Encoding.UTF8, Resources.BODY_TYPE_JSON); return; } if (!selectedLight.state.on) { await r.PUT("/api/" + APIKey + "/lights/" + (lightIDX) + "/state", "{\"on\":true, \"bri\":" + tbBrightness.Value + "}", Encoding.UTF8, Resources.BODY_TYPE_JSON); } else { await r.PUT("/api/" + APIKey + "/lights/" + (lightIDX) + "/state", "{\"bri\":" + tbBrightness.Value + "}", Encoding.UTF8, Resources.BODY_TYPE_JSON); } }
private async void btnAllOff_Click(object sender, EventArgs e) { RESTRequests r = new RESTRequests(theHueBridge.bridgeURLBase.Replace("http://", "").Replace(@":80/", "")); int i = 0; foreach (HueLight hl in allLights) { string result = await r.PUT("/api/" + APIKey + "/lights/" + lightIndices[i] + "/state", "{\"on\":false}", Encoding.UTF8, Resources.BODY_TYPE_JSON); i++; } }
private async void btnColorChange_Click(object sender, EventArgs e) { colorPicker.Color = pnlCurrentColor.BackColor; if (colorPicker.ShowDialog() == DialogResult.OK) { Color c = colorPicker.Color; pnlCurrentColor.BackColor = c; double r = c.R; double g = c.G; double b = c.B; double X, Y; ColorConverter.colorToXY(r, g, b, out X, out Y); logger.Info("Setting color ==> " + X + "," + Y); int lightIDX = lightIndices[dgvLights.CurrentCell.RowIndex]; RESTRequests rest = new RESTRequests(theHueBridge.bridgeURLBase.Replace("http://", "").Replace(@":80/", "")); string singleLight = await rest.GET("/api/" + APIKey + "/lights/" + (lightIDX)); JObject singleLightObj = JObject.Parse(singleLight); HueLight selectedLight = JsonConvert.DeserializeObject <HueLight>(singleLightObj.ToString()); rest = new RESTRequests(theHueBridge.bridgeURLBase.Replace("http://", "").Replace(@":80/", "")); if (!selectedLight.state.on) { await rest.PUT("/api/" + APIKey + "/lights/" + (lightIDX) + "/state", "{\"on\":true, \"xy\":[" + X + "," + Y + "]}", Encoding.UTF8, Resources.BODY_TYPE_JSON); } else { await rest.PUT("/api/" + APIKey + "/lights/" + (lightIDX) + "/state", "{\"xy\":[" + X + "," + Y + "]}", Encoding.UTF8, Resources.BODY_TYPE_JSON); } tbBrightness.Value = selectedLight.state.bri; } }
private async void onCellText_Changed(object sender, DataGridViewCellEventArgs e) { int rowIdx = e.RowIndex + 1; string newLightName = dgvLights.Rows[e.RowIndex].Cells["name"].Value.ToString(); RESTRequests r = new RESTRequests(theHueBridge.bridgeURLBase.Replace("http://", "").Replace(@":80/", "")); string result = await r.PUT("/api/" + APIKey + "/lights/" + rowIdx, "{\"name\":\"" + newLightName + "\"}", Encoding.UTF8, Resources.BODY_TYPE_JSON); if (result == null || result.Contains("error") || result == "") { MessageBox.Show(Resources.ERROR03, "Name-change Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } populateBridgeLights(); }