private async void Brightness_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
        {
            Slider sl1 = sender as Slider;
            var    vm  = sl1.DataContext as ViewModels.AJViewBulb;

            if (vm == null)
            {
                return;
            }
            try
            {
                if (vm != null)
                {
                    foreach (DisplayLamp d in bulbs)
                    {
                        if (vm.ID.Equals(d.about.DeviceId) && vm.Name.Equals(d.about.DeviceName))
                        {
                            if (brightnesswait)
                            {
                                return;
                            }

                            brightnesswait = true;
                            uint brightness = DisplayLamp.PercentToHex((uint)e.NewValue);
                            LampStateSetBrightnessResult res = (LampStateSetBrightnessResult)await d.consumer.SetBrightnessAsync(brightness);

                            setTimerIfPhilips(d);
                            brightnesswait = false;
                            return;
                        }
                    }
                }
            }
            catch (Exception ex) { }
        }
        private async void FoundLight(LampStateConsumer consumer, AllJoynAboutDataView about)
        {
            //     consumer.Signals.LampStateChanged()

            foreach (DisplayLamp d in bulbs)
            {
                if (about.DeviceId.Equals(d.about.DeviceId) && about.DeviceName.Equals(d.about.DeviceId))
                {
                    return;
                }
            }

            consumer.Signals.LampStateChangedReceived += Signals_LampStateChangedReceived;

            DisplayLamp dl = new DisplayLamp(consumer, about);

            bulbs.Add(dl);

            bool ret = await updateLamp(dl);

            await updateLamp(dl);

            var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                var vm = this.DataContext as ViewModels.MainPageViewModel;
                vm.AddBulb(about.DeviceName, about.DeviceId);

                updateBulbDisplay(dl);
            });
        }
 private void setTimerIfPhilips(DisplayLamp d)
 {
     // 'cause we don't have an automatical update callback from our alljoyn emulation at the moment
     if (d.about.Manufacturer.Equals("MatchboxMobile"))
     {
         TimerForPhilipsBuldUpdate.Interval = UpdateTime;
         TimerForPhilipsBuldUpdate.Start();
         d.IsWaiting = true;
     }
 }
        private async void updateBulbDisplay(DisplayLamp b)
        {
            var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, async() =>
            {
                var vm = this.DataContext as ViewModels.MainPageViewModel;
                ViewModels.AJViewBulb ajb = vm.Update(b.about.DeviceId, b.about.DeviceName);
                if (ajb != null)
                {
                    ajb.Brightness       = (byte)DisplayLamp.hexToPercent(b.Brightness.Brightness);
                    ajb.UintBrush        = b.Hue.Hue;
                    ajb.Saturation       = (uint)DisplayLamp.hexToPercent(b.Saturation.Saturation);
                    ajb.ColorTemperature = b.ColorTemp.ColorTemp;

                    ajb.IsBulbOn = b.OnOff.OnOff;
                }
            });
        }
        private async Task <bool> updateLamp(DisplayLamp dl)
        {
            try
            {
                dl.OnOff = await dl.consumer.GetOnOffAsync();

                dl.Hue = await dl.consumer.GetHueAsync();

                dl.Brightness = await dl.consumer.GetBrightnessAsync();

                dl.Saturation = await dl.consumer.GetSaturationAsync();

                dl.ColorTemp = await dl.consumer.GetColorTempAsync();
            }
            catch (Exception ex)
            {
                Debug.Write("updateLamp " + ex.Message);
            }
            return(true);
        }