#pragma warning disable RCS1213 // Remove unused member declaration. private static async Task Test4(string[] args) #pragma warning restore RCS1213 // Remove unused member declaration. { SwitchState desiredState = Enum.Parse <SwitchState>(args[0], true); var bulb = new LightBulb(IPAddress.Parse("192.168.1.7")); //await bulb.FetchAsync(); await bulb.TransitionStateAsync(desiredState).ConfigureAwait(false); }
#pragma warning disable RCS1213 // Remove unused member declaration. private static async Task Test2() #pragma warning restore RCS1213 // Remove unused member declaration. { using (var client = new SmartHomeClient()) { client.Start(); await Task.Delay(1000).ConfigureAwait(false); System.Collections.Generic.IEnumerable <IDevice> devices = client .GetDevices(); LightBulb bulb = devices.OfType <LightBulb>().First(); while (true) { Console.Write($"Brightness ({bulb.State.Brightness}): "); string value = Console.ReadLine(); if (string.Equals(value, "exit", StringComparison.CurrentCultureIgnoreCase)) { break; } await bulb.TransitionStateAsync(new RequestedBulbState() { PowerState = SwitchState.On, Brightness = int.Parse(value) }).ConfigureAwait(false); Console.Clear(); } await bulb.TransitionStateAsync(SwitchState.Off).ConfigureAwait(false); Console.WriteLine("Press any key to exit..."); Console.Read(); } }
public async Task <int> OnExecuteAsync(IConsole console) { var address = IPAddress.Parse(TargetDevice); if (ShowJson) { var bulb = new LightBulb(address); await bulb.FetchAsync().ConfigureAwait(false); console.WriteLine(_jsonService.Serialize(bulb)); } else { var desiredState = new RequestedBulbState(); SwitchState desiredSwitchState = SwitchState.Off; bool shouldToggleState = false; if (string.Equals(DesiredState, "toggle", StringComparison.InvariantCultureIgnoreCase)) { shouldToggleState = true; } else if (Enum.TryParse(DesiredState, true, out desiredSwitchState)) { desiredState.PowerState = desiredSwitchState; } else { throw new Exception("Invalid value for parameter \"state\"."); } if (Brightness != null) { desiredState.Brightness = Brightness; } var bulb = new LightBulb(address); if (shouldToggleState) { await bulb.FetchAsync().ConfigureAwait(false); desiredState.PowerState = bulb.State.PowerState == SwitchState.Off ? SwitchState.On : SwitchState.Off; } await bulb.TransitionStateAsync(desiredState).ConfigureAwait(false); } return(0); }