Exemplo n.º 1
0
 private async void UpdateDeviceList()
 {
     try
     {
         var lights = (await _client.GetLightsAsync()).ToList();
         //Report all lost lights
         HueBulbDevice[] devices;
         lock (_devicesLock)
             devices = _devices.ToArray();
         foreach (var device in devices)
         {
             if (!lights.Where(l => l.UniqueId == device.Light.UniqueId).Any())
             {
                 //Light no longer available
                 lock (_devicesLock)
                     _devices.Remove(device);
                 NotifyDeviceRemoval?.Invoke(this, device);
             }
         }
         var serial = (_client as LocalHueClient2).BridgeSerial;
         //Report all newly found lights
         lock (_devicesLock)
             devices = _devices.ToArray();
         foreach (var light in lights)
         {
             if (!devices.Where(l => l.Light.UniqueId == light.UniqueId).Any())
             {
                 var device = new HueBulbDevice(_client, light, serial);
                 lock (_devicesLock)
                     _devices.Add(device);
                 NotifyDeviceArrival?.Invoke(this, device);
             }
         }
     }
     catch { }
     if (CheckForLightsTimer == null)
     {
         CheckForLightsTimer = new System.Threading.Timer((s) => UpdateDeviceList(), null,
                                                          (int)TimeSpan.FromMinutes(1).TotalMilliseconds,
                                                          (int)TimeSpan.FromMinutes(1).TotalMilliseconds);
     }
 }
 private async void UpdateDeviceList()
 {
     try
     {
         var lights = (await _client.GetLightsAsync()).ToList();
         //Report all lost lights
         HueBulbDevice[] devices;
         lock(_devicesLock)
             devices = _devices.ToArray();
         foreach (var device in devices)
         {
             if (!lights.Where(l => l.UniqueId == device.Light.UniqueId).Any())
             {
                 //Light no longer available
                 lock(_devicesLock)
                     _devices.Remove(device);
                 NotifyDeviceRemoval?.Invoke(this, device);
             }
         }
         var serial = (_client as LocalHueClient2).BridgeSerial;
         //Report all newly found lights
         lock (_devicesLock)
             devices = _devices.ToArray();
         foreach (var light in lights)
         {
             if (!devices.Where(l => l.Light.UniqueId == light.UniqueId).Any())
             {
                 var device = new HueBulbDevice(_client, light, serial);
                 lock (_devicesLock)
                     _devices.Add(device);
                 NotifyDeviceArrival?.Invoke(this, device);
             }
         }
     }
     catch { }
     if(CheckForLightsTimer == null)
         CheckForLightsTimer = new System.Threading.Timer((s) => UpdateDeviceList(), null,
             (int)TimeSpan.FromMinutes(1).TotalMilliseconds,
             (int)TimeSpan.FromMinutes(1).TotalMilliseconds);
 }
Exemplo n.º 3
0
 private void BridgeDevice_NotifyDeviceArrival(object sender, HueBulbDevice device)
 {
     //Called when a bridge finds a new device it owns
     this.devices.Add(device);
     this.NotifyDeviceArrival(device);
 }
Exemplo n.º 4
0
 private void BridgeDevice_NotifyDeviceArrival(object sender, HueBulbDevice device)
 {
     //Called when a bridge finds a new device it owns
     this.devices.Add(device);
     this.NotifyDeviceArrival(device);
 }