Ejemplo n.º 1
0
        public async Task Update()
        {
            if (lamp == null)
            {
                return;
            }

            if (lamp.consumer == null)
            {
                return;
            }

            LampStateGetHueResult hueResult = await this.lamp.consumer.GetHueAsync();

            LampStateGetSaturationResult saturationResult = await this.lamp.consumer.GetSaturationAsync();

            LampStateGetBrightnessResult brigtnessResult = await this.lamp.consumer.GetBrightnessAsync();

            LampStateGetColorTempResult tempResult = await this.lamp.consumer.GetColorTempAsync();

            LampStateGetOnOffResult onOffResult = await this.lamp.consumer.GetOnOffAsync();

            var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                this.hue = HexHelper.ConvertHue(hueResult.Hue);
                this.OnPropertyChanged(HUE_PROPERTY);

                this.saturation = (byte)HexHelper.hexToPercent(saturationResult.Saturation);

                this.onOffState = onOffResult.OnOff;
                this.OnPropertyChanged(ON_OFF_PROPERTY);

                var brightness = (byte)HexHelper.hexToPercent(brigtnessResult.Brightness);
                if (this.brightness != brightness)
                {
                    this.brightness = brightness;
                    this.OnPropertyChanged(BRIGHT_PROPERTY);
                }
                this.temperature = tempResult.ColorTemp;
                this.OnPropertyChanged(TEMP_PROPERTY);

                this.DisplayColour = new SolidColorBrush(ColourHelper.ColorFromHSV(this.Hue, this.saturation, this.brightness));
            });
        }