private async void LightPowerStateImage_Tapped(object sender, TappedRoutedEventArgs e) { if (((Image)sender).Tag.ToString() == LifxPowerState.Off.ToString()) { Helper.ShowProgressIndicator("Turning on..."); foreach (LifxBulb bulb in StorageHelper.SelectedBulbs) { LifxPowerStateMessage psm = await bulb.SetPowerStateCommand(LifxPowerState.On); await HandlePowerStateMessage(psm, bulb); } Helper.HideProgressIndicator(); } else { Helper.ShowProgressIndicator("Turning off..."); SetControlState(false); foreach (LifxBulb bulb in StorageHelper.SelectedBulbs) { LifxPowerStateMessage psm = await bulb.SetPowerStateCommand(LifxPowerState.Off); await HandlePowerStateMessage(psm, bulb); } Helper.HideProgressIndicator(); } }
/// <summary> /// Get current power state /// </summary> /// <returns></returns> public LifxPowerState GetPowerState() { LifxGetPowerStateCommand command = new LifxGetPowerStateCommand(); LifxCommunicator.Instance.SendCommand(command, this); LifxPowerStateMessage returnMessage = (LifxPowerStateMessage)command.ReturnMessage; return(returnMessage.PowerState); }
private async void PowerStateAppBarToggleButton_Checked(object sender, RoutedEventArgs e) { Helper.ShowProgressIndicator("Turning on..."); foreach (LifxBulb bulb in StorageHelper.SelectedBulbs) { LifxPowerStateMessage psm = await bulb.SetPowerStateCommand(LifxPowerState.On); await HandlePowerStateMessage(psm, bulb); } Helper.HideProgressIndicator(); }
private async Task HandlePowerStateMessage(LifxPowerStateMessage message, LifxBulb bulb) { if (message != null) { if (message.PowerState == LifxPowerState.On) { TogglePowerSwitch(true); SetControlState(true, true); LifxLightStatusMessage lightstatus = await bulb.GetLightStatusCommand(); HandleLightStatusMessage(lightstatus, bulb); } else if (message.PowerState == LifxPowerState.Off) { TogglePowerSwitch(false); //PowerToggleSwitch.IsEnabled = true; SetControlState(false); bulb.IsOn = LifxPowerState.Off; } } }