public async Task Initialize() { if (_deviceGroup == null) { var devices = await DeviceLocator.Discover().ConfigureAwait(false); if (devices.Count > 0) { _deviceGroup = new DeviceGroup(devices); await _deviceGroup.Connect().ConfigureAwait(false); } } }
private async void MainForm_Load(object sender, EventArgs e) { toolStripStatusLabel1.Text = "YeeControl " + GlobalVariables.VERSION + " | www.yeecontrol.com"; this.Size = defaultSize; foreach (YeeControlDevice ycd in YeeControlDeviceHelper.GetYeeControlDevices()) { allDevices.Add(new Device(ycd.Hostname)); } await allDevices.Connect(); RefreshPresets(); RefreshCheckedListBox(); RefreshLightState(); listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged; RT(() => RefreshLightState(), 7, cts.Token); }
public static async Task Main(string[] args) { try { Console.WriteLine("Choose a test mode, type 'd' for discovery mode, 's' for a static IP adress : "); ConsoleKeyInfo keyInfo = Console.ReadKey(); Console.WriteLine(); while (keyInfo.Key != ConsoleKey.D && keyInfo.Key != ConsoleKey.S) { Console.WriteLine($"'{keyInfo.KeyChar}' is not a valid key !"); Console.WriteLine("Choose a test mode, type 'd' for discovery mode, 's' for a static IP adress : "); keyInfo = Console.ReadKey(); Console.WriteLine(); } if (keyInfo.Key == ConsoleKey.D) { DeviceLocator.OnDeviceFound += (sender, arg) => { WriteLineWithColor($"Device found : {arg.Device}", ConsoleColor.Blue); }; List <Device> devices = await DeviceLocator.Discover(); if (devices != null && devices.Count >= 1) { Console.WriteLine($"{devices.Count} device(s) found !"); using (DeviceGroup group = new DeviceGroup(devices)) { await group.Connect(); foreach (Device device in group) { device.OnNotificationReceived += Device_OnNotificationReceived; device.OnError += Device_OnError; } bool success = true; //without smooth value (sudden) WriteLineWithColor("Processing tests", ConsoleColor.Cyan); success &= await ExecuteTests(group, null); //with smooth value WriteLineWithColor("Processing tests with smooth effect", ConsoleColor.Cyan); success &= await ExecuteTests(group, 1000); if (success) { WriteLineWithColor("All Tests are successfull", ConsoleColor.Green); } else { WriteLineWithColor("Some tests have failed", ConsoleColor.Red); } } } else { WriteLineWithColor("No devices Found via SSDP !", ConsoleColor.Red); } } else { string hostname; Console.Write("Give a hostname or IP adress to connect to the device : "); hostname = Console.ReadLine(); Console.WriteLine(); Console.Write("Give a port number (or leave empty to use default port) : "); Console.WriteLine(); if (!int.TryParse(Console.ReadLine(), out int port)) { port = 55443; } using (Device device = new Device(hostname, port)) { bool success = true; Console.WriteLine("connecting device ..."); success &= await device.Connect(); device.OnNotificationReceived += Device_OnNotificationReceived; device.OnError += Device_OnError; //without smooth value (sudden) WriteLineWithColor("Processing tests", ConsoleColor.Cyan); success &= await ExecuteTests(device, null); //with smooth value WriteLineWithColor("Processing tests with smooth effect", ConsoleColor.Cyan); success &= await ExecuteTests(device, 1000); if (success) { WriteLineWithColor("All Tests are successfull", ConsoleColor.Green); } else { WriteLineWithColor("Some tests have failed", ConsoleColor.Red); } } } } catch (Exception ex) { WriteLineWithColor($"An error has occurred : {ex.Message}", ConsoleColor.Red); } Console.WriteLine("Press Enter to continue ;)"); Console.ReadLine(); }
private static async Task Main(string[] args) { //NetworkDiscovery.PingAll(); DeviceLocator.UseAllAvailableMulticastAddresses = true; IEnumerable <Device> lights = await DeviceLocator.DiscoverAsync(); if (lights.Count() < 1) { Console.Out.WriteLine("No lights found."); return; } DeviceGroup deviceGroup = new DeviceGroup(); foreach (Device light in lights) { Console.Out.WriteLine($"Found Light: {light.Model} on {light.Hostname}"); deviceGroup.Add(light); } Console.Out.WriteLine($"Found {deviceGroup.Count} lights."); //YeelightAPI.Device device = new Device(IP); await deviceGroup.Connect(); await deviceGroup.SetRGBColor(255, 255, 255); await deviceGroup.SetBrightness(100); ConsoleKeyInfo input = new ConsoleKeyInfo(); do { input = Console.ReadKey(true); switch (input.Key) { case ConsoleKey.UpArrow: ColorFlow flow = new ColorFlow(0, ColorFlowEndAction.Restore); flow.Add(new ColorFlowRGBExpression(255, 0, 0, 1, 500)); flow.Add(new ColorFlowRGBExpression(0, 255, 0, 1, 500)); Console.Out.WriteLine("BLINK"); await deviceGroup.StartColorFlow(flow); break; case ConsoleKey.DownArrow: await deviceGroup.StopColorFlow(); Console.Out.WriteLine("STOP"); break; } Thread.Sleep(40); }while (input.Key != ConsoleKey.Escape); }
public static async Task Main(string[] args) { try { Console.WriteLine("Choose a test mode, type 'd' for discovery mode, 's' for a static IP adress : "); ConsoleKeyInfo keyInfo = Console.ReadKey(); Console.WriteLine(); while (keyInfo.Key != ConsoleKey.D && keyInfo.Key != ConsoleKey.S) { Console.WriteLine($"'{keyInfo.KeyChar}' is not a valid key !"); Console.WriteLine("Choose a test mode, type 'd' for discovery mode, 's' for a static IP adress : "); keyInfo = Console.ReadKey(); Console.WriteLine(); } if (keyInfo.Key == ConsoleKey.D) { List <Device> devices = await DeviceLocator.Discover(); if (devices != null && devices.Count >= 1) { Console.WriteLine($"{devices.Count} device(s) found !"); using (DeviceGroup group = new DeviceGroup(devices)) { await group.Connect(); foreach (Device device in group) { device.OnNotificationReceived += Device_OnNotificationReceived; device.OnCommandError += Device_OnCommandError; } bool success = true; //without smooth value (sudden) WriteLineWithColor("Processing tests", ConsoleColor.Cyan); success &= await ExecuteTests(group, null); //with smooth value WriteLineWithColor("Processing tests with smooth effect", ConsoleColor.Cyan); success &= await ExecuteTests(group, 1000); if (success) { WriteLineWithColor("All Tests are successfull", ConsoleColor.Green); } else { WriteLineWithColor("Some tests have failed", ConsoleColor.Red); } } } else { WriteLineWithColor("No devices Found via SSDP !", ConsoleColor.Red); } } else { string hostname; Console.Write("Give a hostname or IP adress to connect to the device : "); hostname = Console.ReadLine(); Console.WriteLine(); Console.Write("Give a port number (or leave empty to use default port) : "); Console.WriteLine(); if (!int.TryParse(Console.ReadLine(), out int port)) { port = 55443; } using (Device device = new Device(hostname, port)) { bool success = true; Console.WriteLine("connecting device ..."); success &= await device.Connect(); device.OnNotificationReceived += Device_OnNotificationReceived; device.OnCommandError += Device_OnCommandError; Console.WriteLine("getting current name ..."); string name = (await device.GetProp(PROPERTIES.name))?.ToString(); Console.WriteLine($"current name : {name}"); Console.WriteLine("setting name 'test' ..."); success &= await device.SetName("test"); WriteLineWithColor($"command success : {success}", ConsoleColor.DarkCyan); await Task.Delay(2000); Console.WriteLine("restoring name '{0}' ...", name); success &= await device.SetName(name); WriteLineWithColor($"command success : {success}", ConsoleColor.DarkCyan); await Task.Delay(2000); Console.WriteLine("getting all props ..."); Dictionary <PROPERTIES, object> result = await device.GetAllProps(); Console.WriteLine($"\tprops : {JsonConvert.SerializeObject(result)}"); await Task.Delay(2000); //without smooth value (sudden) WriteLineWithColor("Processing tests", ConsoleColor.Cyan); success &= await ExecuteTests(device, null); //with smooth value WriteLineWithColor("Processing tests with smooth effect", ConsoleColor.Cyan); success &= await ExecuteTests(device, 1000); if (success) { WriteLineWithColor("All Tests are successfull", ConsoleColor.Green); } else { WriteLineWithColor("Some tests have failed", ConsoleColor.Red); } } } } catch (Exception ex) { WriteLineWithColor($"An error has occurred : {ex.Message}", ConsoleColor.Red); } Console.WriteLine("Press Enter to continue ;)"); Console.ReadLine(); }