示例#1
0
        private void Client_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e)
        {
            var bulb = e.Device as LightBulb;

            LogUtil.Write("Bulb discovered?");
            bulbs.Add(bulb);
        }
示例#2
0
        // 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);
        }
示例#3
0
        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}");
                }
            }
        }
示例#4
0
        // 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);
            }
        }
示例#5
0
        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);
                    }
                }
            });
        }
示例#9
0
        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);
        }
示例#10
0
    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);
            }
        }
示例#12
0
        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}");
                }
            }
        }
示例#13
0
 private static void Client_DeviceLost(object sender, LifxClient.DeviceDiscoveryEventArgs e)
 {
     LightBulbs.Remove((LightBulb)e.Device);
 }
示例#14
0
 private static IEnumerator LogDeviceName(LifxClient.DeviceDiscoveryEventArgs e)
 {
     Debug.Log("Light: " + Client.GetDeviceLabelAsync(e.Device).Id);
     yield return(null);
 }
示例#15
0
 private static void Client_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e)
 {
     Threading.RunOnMain(LogDeviceName(e));
     LightBulbs.Add((LightBulb)e.Device);
 }
示例#16
0
 private static void Client_DeviceLost(object sender, LifxClient.DeviceDiscoveryEventArgs e)
 {
     Console.WriteLine("Device lost");
 }