private async Task <List <Device> > GetDevicesAsync() { // Await the asynchronous call to the static API List <Device> discoveredDevices = (await DeviceLocator.DiscoverAsync()).ToList(); return(discoveredDevices); }
protected override IEnumerable <IRGBDevice> LoadDevices() { IEnumerable <Device> yeeLightDevices = null; Task.Run(async() => { yeeLightDevices = await DeviceLocator.DiscoverAsync(); }).GetAwaiter().GetResult(); if (yeeLightDevices != null) { foreach (Device device in yeeLightDevices) { bool add = false; try { device.Connect().Wait(); add = true; //TODO: Log } catch { //TODO: Log } if (add) { yield return(new YeeLightRGBRGBDevice(new YeeLightRGBDeviceInfo(RGBDeviceType.LedStripe, string.Format("YeeLight {0} ({1})", device.Model, device.Hostname), device.Hostname), new YeeLightUpdateQueue(GetUpdateTrigger(), device))); } } } }
public async Task <List <Device> > ObterDispositivos() { DeviceLocator.UseAllAvailableMulticastAddresses = true; List <Device> discoveredDevices = (await DeviceLocator.Discover()).ToList(); return(discoveredDevices); }
private async void InitAsync() { //Lights Console.WriteLine("Searching for Yeelight devices..."); _lights = await DeviceLocator.Discover(); Console.WriteLine($"Found {_lights.Count()} device{(_lights.Count() != 1 ? "s" : string.Empty)}: {string.Join(", ", _lights.Select(x => x.Id))}"); //Cameras var videoDevicesInfo = new FilterInfoCollection(FilterCategory.VideoInputDevice); LayoutRoot.Columns = videoDevicesInfo.Count; LayoutRoot.Rows = 1; foreach (FilterInfo deviceInfo in videoDevicesInfo) { var device = new VideoCaptureDevice(deviceInfo.MonikerString); var hash = SHA256(deviceInfo.MonikerString); var view = new MotionView(device, hash); Console.WriteLine($"Initialized camera {hash}"); view.MotionDetected += async(sender, args) => { var view = sender as MotionView; /*var message = $"{view.DeviceID.Substring(0, 4)}: {args.Direction.X}, {args.Direction.Y}"; * Console.WriteLine(message);*/ await HandleCameraMovementAsync(view.DeviceID, args.Direction.X, args.Direction.Y); }; LayoutRoot.Children.Insert(0, view); } //Action }
public async Task Discovery_should_find_devices() { int expectedDevicesCount = GetConfig <int>("discovery_devices_expected"); var devices = (await DeviceLocator.DiscoverAsync()).ToList(); Assert.Equal(expectedDevicesCount, devices?.Count); }
private async Task Loader() { _lightsMainNode.Nodes.Clear(); DeviceLocator.UseAllAvailableMulticastAddresses = _settings.AppSettings.MulticastLookup; var devices = await DeviceLocator.DiscoverAsync(); foreach (Device device in devices.OrderBy(m => m.Name)) { Guid pageGuid = Guid.NewGuid(); Aside.Invoke((MethodInvoker) delegate() { Aside.CreateChildNode(_lightsMainNode, AddPage(new LightPage( new DeviceViewModel { Device = device, Hostname = device.Hostname, Name = device.Name, IsOn = device.Properties.FirstOrDefault(m => m.Key == "power").Value.ToString(), PageGuid = pageGuid }), pageGuid)); }); } Aside.Invoke((MethodInvoker) delegate() { Aside.SelectFirst(); }); _lightsMainNode.Expand(); }
public static async Task InitializeYeelights() { DeviceLocator.MaxRetryCount = 2; // notify on discovered bulbs var progressReporter = new Progress <Device>(device => Console.WriteLine($"[Yeelight] Device found: {device}")); // find bulbs on the network var devices = await DeviceLocator.DiscoverAsync(progressReporter); // once we collect devices on the network, add them to bulbs list, // connect to them, turn them on, set their brightness to max foreach (var device in devices) { Console.WriteLine($"[Yeelight] Trying to connect to device: {device}"); bulbs.Add(device); // device.OnNotificationReceived += DeviceOnOnNotificationReceived; device.OnError += DeviceOnError; device.Connect(); device.TurnOn(); device.SetBrightness(100); } }
static void Main() { int SSDPTimeOut = 10000; int SSDPRequestCount = 1; Console.WriteLine("Beware that these devices usually have rate limits on SSDP requests with very long wait times. You might have to power cycle your device to zero the rate limit delay."); Console.WriteLine("Press any key start a SSDP search request..."); Console.ReadKey(); Console.WriteLine($"Sending SSDP search request with {SSDPTimeOut}ms timeout and request count of {SSDPRequestCount} ..."); Console.WriteLine(); List <YeeLightDevice> devices = DeviceLocator.DiscoverDevices(SSDPTimeOut, SSDPRequestCount); if (devices.Count > 0) { Console.WriteLine($"Found {devices.Count} device(s): "); foreach (YeeLightDevice device in devices) { var(ipAddress, port) = device.GetLightIPAddressAndPort(); Console.WriteLine($"IP: {ipAddress} | Port: {port}"); } } else { Console.WriteLine("No devices have been found."); } Console.WriteLine(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public void Subscribe() { this.deviceLocator = new DeviceLocator(); IObservable <IReceiver> observable = deviceLocator.FindReceiversContinuous(); this.subscription = observable.Subscribe(this.OnNext); }
public async Task <bool> Start() { if (_config.EnableDiscovery) { var sender = new Sender(); var deviceLocator = new DeviceLocator(); var receivers = await deviceLocator.FindReceiversAsync(); receivers.ToList().ForEach(c => { _ioTService.InsertEvent(new ChromecastEd() { DeviceId = c.Id, Address = c.IPEndPoint.Address.ToString(), EntityName = c.Id, FriendlyName = c.FriendlyName }); }); //await sender.ConnectAsync(chrome); //var mediaChannel = sender.GetChannel<IMediaChannel>(); //await sender.LaunchAsync(mediaChannel); //// Load and play Big Buck Bunny video //var mediaStatus = await mediaChannel.LoadAsync( // new MediaInformation() { ContentId = "https://open.spotify.com/track/2iGcN8KNk58rsXLo1yubR7?si=MJ7RReqUQBWa03AfQ2UI2w" }); } return(true); }
private async Task GetDevicesAsync() { var progressReporter = new Progress <Device>(OnDeviceFound); await DeviceLocator.DiscoverAsync(progressReporter); IEnumerable <Device> discoveredDevices = await DeviceLocator.DiscoverAsync(progressReporter); }
public async Task Discovery_should_find_devices_on_all_multicast_addresses() { int expectedDevicesCount = GetConfig <int>("discovery_devices_expected"); DeviceLocator.UseAllAvailableMulticastAddresses = true; var devices = (await DeviceLocator.DiscoverAsync()).ToList(); Assert.Equal(expectedDevicesCount, devices?.Count); }
public override bool Initialize() { if (!IsInitialized) { try { lights.Clear(); var IPListString = Global.Configuration.VarRegistry.GetVariable <string>($"{DeviceName}_IP"); var lightIPList = new List <IPAddress>(); //Auto discover a device if the IP is empty and auto-discovery is enabled if (string.IsNullOrWhiteSpace(IPListString) && Global.Configuration.VarRegistry.GetVariable <bool>($"{DeviceName}_auto_discovery")) { var devices = DeviceLocator.DiscoverDevices(10000, 2); if (!devices.Any()) { throw new Exception("Auto-discovery is enabled but no devices have been located."); } lightIPList.AddRange(devices.Select(v => v.GetLightIPAddressAndPort().ipAddress)); } else { lightIPList = IPListString.Split(new[] { ',' }).Select(x => IPAddress.Parse(x.Replace(" ", ""))).ToList(); if (lightIPList.Count == 0) { throw new Exception("Device IP list is empty."); } } for (int i = 0; i < lightIPList.Count; i++) { IPAddress ipaddr = lightIPList[i]; try { ConnectNewDevice(ipaddr); } catch (Exception exc) { LogError($"Encountered an error while connecting to the {i}. light. Exception: {exc}"); } } IsInitialized = lights.All(x => x.IsConnected()); } catch (Exception exc) { LogError($"Encountered an error while initializing. Exception: {exc}"); IsInitialized = false; return(false); } } return(IsInitialized); }
public async Task Discovery_should_not_last_long() { Stopwatch sw = Stopwatch.StartNew(); _ = await DeviceLocator.DiscoverAsync(); sw.Stop(); Assert.InRange(sw.ElapsedMilliseconds, 0, 1500); }
private async Task RefreshAsync() { await DispatcherHelper.RunAsync(async() => { IsLoaded = false; Receivers = await DeviceLocator.FindReceiversAsync(); SelectedReceiver = Receivers.FirstOrDefault(); IsLoaded = true; }); }
public async Task Discovery_should_find_devices_with_multiple_tries() { int expectedDevicesCount = GetConfig <int>("discovery_devices_expected"); DeviceLocator.MaxRetryCount = 3; var devices = (await DeviceLocator.DiscoverAsync()).ToList(); DeviceLocator.MaxRetryCount = 1; Assert.Equal(expectedDevicesCount, devices?.Count); }
public override async Task Initialize() { DeviceLocator.OnDeviceFound += OnDeviceFound; await DeviceLocator.Discover(); var keyboard = Service.Get <Keyboard>(); keyboard.KeyPress += OnKeyPress; _lightsTimer = new QueuedTimer(async x => await OnLightsTimer(), TimerInterval); }
public async Task <IEnumerable <IReceiver> > FindReceiversAsync() { try { return(await DeviceLocator.FindReceiversAsync()); } catch (Exception) { return(new List <IReceiver>()); } }
public async Task Discovery_enumerate_async_should_find_devices() { int expectedDevicesCount = GetConfig <int>("discovery_devices_expected"); int count = 0; await foreach (var device in DeviceLocator.DiscoverAndEnumerateAsync()) { ++count; } Assert.Equal(expectedDevicesCount, count); }
private async Task GetDevicesAsync() { // Initialize the instance of Progress<T> with a callback to handle a discovered device var progressReporter = new Progress <Device>(OnDeviceFound); // Await the asynchronous call to the static API await DeviceLocator.DiscoverAsync(progressReporter); // Alternatively: although each device is handled as soon as it is discovered by the callback registered with the progress reporter, // you still can await the result collection IEnumerable <Device> discoveredDevices = await DeviceLocator.DiscoverAsync(progressReporter); }
public async Task Discover(CancellationToken ct, int timeout) { Log.Debug("Yeelight: Discovery started..."); // Await the asynchronous call to the static API try { await DeviceLocator.DiscoverAsync(_reporter, ct); } catch (Exception) { // Ignore error thrown on cancellation. } Log.Debug("Yeelight: Discovery complete."); }
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); } } }
static async Task <Device> Connect() { List <Device> devices = await DeviceLocator.Discover(); if (devices.Count > 0) { await devices[0].Connect(); return(devices[0]); } return(null); }
public async Task <DeviceGroup> FindLights() { try { IEnumerable <Device> devices = await DeviceLocator.DiscoverAsync(); this.deviceGroup = new DeviceGroup(devices); return(this.deviceGroup); } catch { return(null); } }
protected override void OnExecuteCommand() { if (ControlGroup.DeviceOrSession == "Master") { KeyboardHelpers.SendKeyPress(KeyCode.VOLUME_MUTE); } else { foreach (var volumeTarget in DeviceLocator.FindVolumeOutTargetsBySubstring(ControlGroup.DeviceOrSession)) { volumeTarget.SetMute(IsMuted); } } }
private async Task <Device> GetRandomConnectedDevice(METHODS?supportedMethod = null) { List <Device> devices = (await DeviceLocator.DiscoverAsync()).Where(d => !supportedMethod.HasValue || d.SupportedOperations.Contains(supportedMethod.Value)).ToList(); Assert.NotEmpty(devices); int randomIndex = new Random().Next(0, devices.Count); Device d = devices.ElementAt(randomIndex); _output.WriteLine($"Used device : {d}"); await d.Connect(); return(d); }
public int GetHashCodeWithMembers() { unchecked { var hashCode = 397; hashCode = (hashCode * 397) ^ Capacity.GetHashCode(); hashCode = (hashCode * 397) ^ ((int)Type).GetHashCode(); hashCode = (hashCode * 397) ^ Ghz.GetHashCode(); hashCode = (hashCode * 397) ^ (BankLabel?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (DeviceLocator?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ Generation.GetHashCode(); return(hashCode); } }
public async Task <DeviceGroup> FindLights() { try { IEnumerable <Device> devices = await DeviceLocator.DiscoverAsync(); this.deviceGroup = new DeviceGroup(devices); return(this.deviceGroup); } catch (Exception e) { _logger.LogError(e, "Error Occured Finding Lights"); throw; } }
public async Task Discovery_should_throw_when_using_wrong_multicast_address() { int expectedDevicesCount = GetConfig <int>("discovery_devices_expected"); string initialMulticastAddress = DeviceLocator.DefaultMulticastIPAddress; DeviceLocator.DefaultMulticastIPAddress = "foo"; _ = await Assert.ThrowsAsync <FormatException>(async() => { _ = (await DeviceLocator.DiscoverAsync()).ToList(); }); //reset to default to ensure next tests don't crash DeviceLocator.DefaultMulticastIPAddress = initialMulticastAddress; }
private async Task SearchDevices() { var deviceFinder = new DeviceLocator(); Logger.LogInformation("Starting search devices"); var devices = await deviceFinder.FindReceiversAsync(); if (devices != null) { devices = devices.ToList(); Logger.LogInformation($"Found {devices.Count()} found!"); foreach (var receiver in devices.ToList()) { AddDevice(receiver.Id, receiver.IPEndPoint.ToString(), receiver.FriendlyName); } } }
public ChromecastService() { DeviceLocator = new DeviceLocator(); ChromeCastClient = new ChromeCastClient(); }