private void Client_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e) { var bulb = e.Device as LightBulb; LogUtil.Write("Bulb discovered?"); bulbs.Add(bulb); }
// Save device in memory at discovery private async void Client_DeviceDiscoveredAsync(object sender, LifxClient.DeviceDiscoveryEventArgs e) { var bulb = e.Device as LightBulb; var label = await client.GetDeviceLabelAsync(e.Device); await context.Bulbs.AddAsync(bulb); }
private static void Client_DeviceLost(object sender, LifxClient.DeviceDiscoveryEventArgs e) { lock (Bulbs) { var bulb = e.Device as LightBulb; if (IsNullOrEmpty(bulb?.State?.Label) || !Labels.Contains(bulb.State.Label)) { return; } if (bulb.LastSeen.AddMinutes(10) > DateTime.Now) { return; } Log.Bulb($"Removing bulb {bulb.State.Label}"); try { Bulbs.Remove(bulb); } catch (Exception ex) { Log.Error($"Removing bulb {bulb.State.Label} exception {ex.Message}"); } } }
// TODO: Mark device as lost? // Remove device from memory private void Client_DeviceLost(object sender, LifxClient.DeviceDiscoveryEventArgs e) { var bulb = context.Bulbs.Where(b => b.MacAddress == e.Device.MacAddress).FirstOrDefault(); if (bulb != null) { context.Bulbs.Remove(bulb); } }
private static async void Client_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e) { Console.WriteLine($"Device {e.Device.MacAddressName} found @ {e.Device.HostName}"); var version = await client.GetDeviceVersionAsync(e.Device); //var label = await client.GetDeviceLabelAsync(e.Device); var state = await client.GetLightStateAsync(e.Device as LightBulb); Console.WriteLine($"{state.Label}\n\tIs on: {state.IsOn}\n\tHue: {state.Hue}\n\tSaturation: {state.Saturation}\n\tBrightness: {state.Brightness}\n\tTemperature: {state.Kelvin}"); }
private async void LifxClient_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e) { await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (e.Device is LightBulb bulb) { LifxItem lifxBulb = new LifxItem(this.LifxClient, bulb); if (!this.Items.Contains(lifxBulb)) { this.Items.Add(lifxBulb); } } }); }
void _client_DeviceLost(object sender, LifxClient.DeviceDiscoveryEventArgs e) { LightBulb bulb = e.Device as LightBulb; if (_bulbs.Contains(bulb)) { _devices.RemoveAll(x => x.MacAddressName == bulb.MacAddressName); if (bulb.MacAddressName == _selected.MacAddressName) { _selected = null; } _bulbs.Remove(bulb); } }
private async void LifxClient_DeviceLost(object sender, LifxClient.DeviceDiscoveryEventArgs e) { await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (e.Device is LightBulb bulb) { LifxItem item = this.Items.Where(t => t.HostName == bulb.HostName).SingleOrDefault(); if (item != null) { item.Dispose(); this.Items.Remove(item); } } }); }
private async void Client_DeviceDiscovered(object?sender, LifxClient.DeviceDiscoveryEventArgs e) { var bulb = e.Device; if (bulb == null) { return; } //Log.Debug("Device found: " + JsonConvert.SerializeObject(bulb)); var ld = await GetBulbInfo(bulb); if (ld == null) { return; } Log.Debug("Adding device: " + JsonConvert.SerializeObject(ld)); await _controlService.AddDevice(ld); }
private async void Client_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e) { var bulb = e.Device as LightBulb; await client.SetDevicePowerStateAsync(bulb, true); //Turn bulb on // await client.SetColorAsync(bulb, red, 2700); //Set color to Red and 2700K Temperature // LightBulb bulb, // UInt16 hue, // UInt16 saturation, // UInt16 brightness, // UInt16 kelvin, // TimeSpan transitionDuration await client.SetColorAsync(bulb, (ushort)hue, (ushort)sat, (ushort)brightness, 2700, new System.TimeSpan(0, 0, (int)duration) ); }
async void _client_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e) { LightBulb bulb = e.Device as LightBulb; if (!_bulbs.Contains(bulb)) { _bulbs.Add(bulb); LifxDevice device = new LifxDevice { MacAddressName = bulb.MacAddressName }; device.Label = await _client.GetDeviceLabelAsync(bulb); if (device.Label == _initLabel && _selected == null) { _selected = device; } _devices.Add(device); } }
private static void Client_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e) { lock (Bulbs) { var bulb = e.Device as LightBulb; if (IsNullOrEmpty(bulb?.State?.Label) || Labels.Contains(bulb.State.Label)) { return; } Log.Bulb($"Adding bulb {bulb.State.Label}"); try { Bulbs.Add(bulb); } catch (Exception ex) { Log.Error($"Adding bulb {bulb.State.Label} exception {ex.Message}"); } } }
private static void Client_DeviceLost(object sender, LifxClient.DeviceDiscoveryEventArgs e) { LightBulbs.Remove((LightBulb)e.Device); }
private static IEnumerator LogDeviceName(LifxClient.DeviceDiscoveryEventArgs e) { Debug.Log("Light: " + Client.GetDeviceLabelAsync(e.Device).Id); yield return(null); }
private static void Client_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e) { Threading.RunOnMain(LogDeviceName(e)); LightBulbs.Add((LightBulb)e.Device); }
private static void Client_DeviceLost(object sender, LifxClient.DeviceDiscoveryEventArgs e) { Console.WriteLine("Device lost"); }