private void EscapeListener(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { HaClientContext.RemoveStateChangeListener(this); Close(); } }
public override bool ToggleIfPossible(Dispatcher dispatcher) { if (IsSupported(SupportedFeatures.TurnOn, SupportedFeatures.TurnOff)) { HaClientContext.CallService(dispatcher, this, "toggle"); return(true); } return(false); }
protected override MenuItem ToMenuItem(Dispatcher dispatcher, string name) { var root = new MenuItem { Header = GetName(name), StaysOpenOnClick = true, IsEnabled = IsAvailable() }; if (IsOn()) { root.Icon = new PackIcon { Kind = PackIconKind.Tick }; } var features = GetSupportedFeatures(); if (new HashSet <int> { SupportedFeatures.Open, SupportedFeatures.Close }.SetEquals(features)) { root.Click += (sender, args) => { HaClientContext.CallService(dispatcher, this, "toggle"); }; } else if (new HashSet <int> { SupportedFeatures.OpenTilt, SupportedFeatures.CloseTilt }.SetEquals(features)) { root.Click += (sender, args) => { HaClientContext.CallService(dispatcher, this, "toggle_cover_tilt"); }; } else { root.PreviewMouseDown += (sender, args) => { if (args.ChangedButton == MouseButton.Right) { args.Handled = ToggleIfPossible(dispatcher); } }; AddMenuItemIfSupported(dispatcher, root, SupportedFeatures.Open); AddMenuItemIfSupported(dispatcher, root, SupportedFeatures.Close); AddMenuItemIfSupported(dispatcher, root, SupportedFeatures.Stop); AddSliderIfSupported(dispatcher, root, SupportedFeatures.SetPosition, 0, 100, GetDoubleAttribute("current_position"), "position"); AddMenuItemIfSupported(dispatcher, root, SupportedFeatures.OpenTilt); AddMenuItemIfSupported(dispatcher, root, SupportedFeatures.CloseTilt); AddMenuItemIfSupported(dispatcher, root, SupportedFeatures.StopTilt); AddSliderIfSupported(dispatcher, root, SupportedFeatures.SetTiltPosition, 0, 100, GetDoubleAttribute("current_tilt_position"), "tilt_position"); } return(root); }
protected override MenuItem ToMenuItem(Dispatcher dispatcher, string name) { var root = new MenuItem { Header = GetName(name), StaysOpenOnClick = true, IsEnabled = IsAvailable() }; if (IsOn()) { root.Icon = new PackIcon { Kind = PackIconKind.Tick }; } if (GetSupportedFeatures().Count == 0) { root.Click += (sender, args) => HaClientContext.CallService(dispatcher, this, "toggle"); } else { root.PreviewMouseDown += (sender, args) => { if (args.ChangedButton == MouseButton.Right) { args.Handled = ToggleIfPossible(dispatcher); } }; root.Items.Add(CreateMenuItem(dispatcher, "turn_on", "Turn On")); root.Items.Add(CreateMenuItem(dispatcher, "turn_off", "Turn Off")); AddSliderIfSupported(dispatcher, root, SupportedFeatures.Brightness, 0, 255, GetIntAttribute("brightness"), "brightness"); AddSliderIfSupported(dispatcher, root, SupportedFeatures.ColorTemp, GetIntAttribute("min_mireds"), GetIntAttribute("max_mireds"), GetIntAttribute("color_temp", GetIntAttribute("min_mireds")), "color_temp"); AddSliderIfSupported(dispatcher, root, SupportedFeatures.WhiteValue, 0, 255, GetIntAttribute("white_value"), "white_value"); } return(root); }
public SearchWindow(string s, List <Entity> entities) { _entities = new List <Entity>(entities); InitializeComponent(); HaClientContext.AddStateChangeListener(this, updatedEntity => { var index = _entities.FindIndex(e => e.EntityId == updatedEntity.EntityId); if (index >= 0) { _entities[index] = updatedEntity; Dispatcher.Invoke(() => UpdateFoundList(null, null)); } }); if (s.Length == 1) { SearchBox.Text = s; } SearchBox.CaretIndex = int.MaxValue; SearchBox.Focus(); }
public override bool ToggleIfPossible(Dispatcher dispatcher) { HaClientContext.CallService(dispatcher, this, "toggle"); return(true); }
private void CloseButton(object sender, RoutedEventArgs e) { HaClientContext.RemoveStateChangeListener(this); Close(); }
protected override MenuItem ToMenuItem(Dispatcher dispatcher, string name) { var root = new MenuItem { Header = GetName(name), StaysOpenOnClick = true, IsEnabled = IsAvailable() }; if (IsOn()) { root.Icon = new PackIcon { Kind = PackIconKind.Tick }; } if (GetSupportedFeatures().Count == 0 || GetSupportedModes().Equals(new HashSet <string> { SupportedColorModes.OnOff })) { root.Click += (sender, args) => HaClientContext.CallService(dispatcher, this, "toggle"); } else { root.PreviewMouseDown += (sender, args) => { if (args.ChangedButton == MouseButton.Right) { args.Handled = ToggleIfPossible(dispatcher); } }; root.Items.Add(CreateMenuItem(dispatcher, "turn_on", "Turn On")); root.Items.Add(CreateMenuItem(dispatcher, "turn_off", "Turn Off")); AddSliderIfSupported(dispatcher, root, SupportedFeatures.Brightness, 0, 255, GetIntAttribute("brightness"), "brightness"); AddSliderIfSupported(dispatcher, root, SupportedFeatures.ColorTemp, GetIntAttribute("min_mireds"), GetIntAttribute("max_mireds"), GetIntAttribute("color_temp", GetIntAttribute("min_mireds")), "color_temp", changer: (slider, value) => slider.Foreground = new SolidColorBrush(FromMireds(slider, value))); AddSliderIfSupported(dispatcher, root, SupportedFeatures.WhiteValue, 0, 255, GetIntAttribute("white_value"), "white_value"); AddSliderIfSupported(dispatcher, root, SupportedFeatures.Color, 0, 360, ParseDouble(GetListAttribute("hs_color", 0)), "hs_color", 1, (slider, value) => slider.Foreground = new SolidColorBrush(FromHue(value)), converter: value => new[] { (int)value, 100 }); if (IsSupported(SupportedFeatures.Effect)) { var effectItem = new MenuItem { Header = "Effect", StaysOpenOnClick = true }; var currentEffect = GetAttribute("effect"); GetListAttribute("effect_list").ForEach(effect => { effectItem.Items.Add(CreateMenuItem(dispatcher, "turn_on", effect, effect == currentEffect, data: Tuple.Create <string, object>("effect", effect))); }); root.Items.Add(effectItem); } } return(root); }
protected override MenuItem ToMenuItem(Dispatcher dispatcher, string name) { var root = new MenuItem { Header = GetName(name), StaysOpenOnClick = true, IsEnabled = IsAvailable() }; if (IsOn()) { root.Icon = new PackIcon { Kind = PackIconKind.Tick }; } var features = GetSupportedFeatures(); if (features.Count == 0) { root.Click += (sender, args) => { HaClientContext.CallService(dispatcher, this, "toggle"); }; } else { root.PreviewMouseDown += (sender, args) => { if (args.ChangedButton == MouseButton.Right) { args.Handled = ToggleIfPossible(dispatcher); } }; root.Items.Add(CreateMenuItem(dispatcher, "turn_on", "Turn On")); root.Items.Add(CreateMenuItem(dispatcher, "turn_off", "Turn Off")); if (features.Contains(SupportedFeatures.SetSpeed)) { var currentSpeed = GetAttribute("speed"); var speedRootItem = new MenuItem { Header = "Set Speed", StaysOpenOnClick = true }; GetListAttribute("speed_list") .ForEach(speedValue => speedRootItem.Items.Add( CreateMenuItem(dispatcher, "set_speed", speedValue, speedValue == currentSpeed, data: Tuple.Create <string, object>("speed", speedValue)))); root.Items.Add(speedRootItem); } if (features.Contains(SupportedFeatures.Oscillate)) { var oscillating = GetBoolAttribute("oscillating"); root.Items.Add(CreateMenuItem(dispatcher, "oscillate", "Oscillating", oscillating, data: Tuple.Create <string, object>("oscillating", !oscillating))); } if (features.Contains(SupportedFeatures.Direction)) { var currentDirection = GetAttribute("speed"); var directionsItem = new MenuItem { Header = "Set Direction", StaysOpenOnClick = true }; new List <Tuple <string, string> > { Tuple.Create("forward", "Forward"), Tuple.Create("reverse", "Reverse") } .ForEach(t => directionsItem.Items.Add( CreateMenuItem(dispatcher, "set_direction", t.Item2, t.Item1 == currentDirection, data: Tuple.Create <string, object>("direction", t.Item1)))); root.Items.Add(directionsItem); } } return(root); }