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)); }); }
public async Task <bool> GetOnOffAsync() { if (consumer != null) { // Get the current On/Off state of the lamp. LampStateGetOnOffResult onOffResult = await consumer.GetOnOffAsync(); if (onOffResult.Status == AllJoynStatus.Ok) { return(onOffResult.OnOff); } else { throw new Exception(string.Format("Error getting On/Off state - 0x{0:X}", onOffResult.Status)); } } else { throw new NullReferenceException("No lamp found."); } }
public IAsyncOperation <LampStateGetOnOffResult> GetOnOffAsync(AllJoynMessageInfo info) { return(Task.Run(() => LampStateGetOnOffResult.CreateSuccessResult(_isOn)).AsAsyncOperation()); }