public MuteStateObserver(HueConnector hueConnector, Config config) { _hueConnector = hueConnector; _lights = config.Hue.Lights; _muted = new RGBColor(config.Colors.Muted); _unmuted = new RGBColor(config.Colors.Unmuted); _notInSession = new RGBColor(config.Colors.NotInSession); }
public static async Task Lights(Config config, HueConnector hueConnector) { var lights = await hueConnector.GetLights(); var selectedlights = AnsiConsole.Prompt( new MultiSelectionPrompt <string>() .Title("Select the [green]lights[/] that you wish to be updated when mute state changes.") .Required() .PageSize(10) .AddChoices(lights.Select(x => $"{x.Id}: {x.Name} in {x.GroupString}"))); config.Hue.Lights = selectedlights.Select(x => x.Split(':').First()).ToList(); }
private static void ObserveDevice(IDevice device, HueConnector hueConnector, Config config) { AnsiConsole.MarkupLine($":microphone: [grey]Device:[/] [lightslategrey]{device.Name}[/]"); var muteObserver = new MuteStateObserver(hueConnector, config); var sessionController = device.GetCapability <IAudioSessionController>(); foreach (var session in sessionController.All()) { if (session.ProcessId == 0) { continue; } muteObserver.SubscribeToSession(session); } sessionController.SessionCreated.Subscribe(muteObserver); sessionController.SessionDisconnected.Subscribe(muteObserver); }
public static async Task <bool> HueConnection(Config config) { var ips = await HueConnector.GetBridgeIps(); if (!ips.Any()) { Console.WriteLine(":bridge_at_night: No Hue bridge was found"); return(false); } var ip = AnsiConsole.Prompt( new SelectionPrompt <string>() .Title(":bridge_at_night: Select the ip of the [green]Hue bridge[/] you want to connect to.") .PageSize(5) .AddChoices(ips) ); config.Hue.Ip = ip; AnsiConsole.MarkupLine($":bridge_at_night: Added [green]{ip}[/]"); return(true); }
private static async Task <(Config config, HueConnector hueConnector)> SetupConfig(string[] args) { if (args.Length > 0 && args.First() == "--reset") { Config.ResetConfig(); } Config.EnsureConfig(); var config = Config.ReadConfig(); if (string.IsNullOrEmpty(config.Hue.Ip)) { if (!await Setup.HueConnection(config)) { Environment.Exit(1); } Config.WriteConfig(config); } if (string.IsNullOrEmpty(config.Hue.Key)) { await Setup.HueKey(config); Config.WriteConfig(config); } var hueConnector = new HueConnector(config); if (!config.Hue.Lights.Any()) { await Setup.Lights(config, hueConnector); Config.WriteConfig(config); } return(config, hueConnector); }