public SwitchSetting(SwitchView sView, Light lSwitch) { this.DisplayName = lSwitch.Name; this.Id = lSwitch.Id; this.Left = sView.Left; this.Top = sView.Top; this.width = sView.Width; this.height = sView.Height; }
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"); } }
private async void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (CurrentBridge == null) { return; } SwitchView currentSwitchWindow = ((SwitchView)((Viewbox)((Grid)((CheckBox)sender).Parent).Parent).Parent); if ((bool)currentSwitchWindow.CheckBox_LINKS.IsChecked) { return; } try { double bri = Brightness; if (bri % 10 == 0) { //if (bri == 0 && isOn) //{ // isOn = false; // lights off // await toggleSwitch(currentSwitchWindow.pbar_switch); //} //else if (bri > 0 && !isOn) //{ // isOn = true; // lights on // await toggleSwitch(currentSwitchWindow.pbar_switch); //} //if (bri > 0) //{ if (bri == 250) { bri = 254; } //string state = "lights/" + LSwitch.Id + "/state"; //await LREST.Put(base_url + state, "{\"bri\":" + bri + "}", "", ".json"); var command = new LightCommand(); command.On = LSwitch.State.On; //command.On = true; command.Brightness = (byte)bri; command.TransitionTime = TimeSpan.FromSeconds(9); HueResults retVal = null; retVal = await CurrentBridge.Client.SendCommandAsync(command, new List <string> { LSwitch.Id }); if (retVal.Count > 0 && retVal[0].Success != null && !string.IsNullOrEmpty(retVal[0].Success.Id)) { //LSwitch.State.On =retVal[0].Success.Id } else if (retVal.Count == 0) { isOn = (bool)command.On; //AnimateProperty(currentSwitchWindow.pbar_switch); } //} } } catch (Exception error) { MessageBox.Show(error.Message); } }