async Task ProcessLocalBuildingCommandAsync( VoiceCommandServiceConnection voiceConnection, BuildingCommandDetails commandDetails) { if (string.IsNullOrEmpty(commandDetails.Room)) { commandDetails.Room = await this.DisambiguateRoomAsync( voiceConnection, BuildingPersistence.Instance.Rooms); } // Local building, relatively easy. if (string.IsNullOrEmpty(commandDetails.Room)) { BuildingPersistence.Instance.SwitchAllLights(commandDetails.OnOff.Value); } else { var room = BuildingPersistence.Instance.GetRoomByName(commandDetails.Room); if (room != null) { room.SwitchLights(commandDetails.OnOff.Value); } } await BuildingPersistence.SaveAsync(BuildingPersistence.Instance); }
async void OnDone(object sender, RoutedEventArgs e) { BuildingPersistence.Instance.Rooms = new List <Room>(); int gpioPin = 0; foreach (var room in this.Rooms) { BuildingPersistence.Instance.Rooms.Add( new Room() { RoomType = room.RoomType, Lights = Enumerable .Range(1, room.Count) .Select( (c, i) => new Light() { Id = i, GpioPinNumber = GpioPinLookup.GetGpioPinIndexForOrdinal(gpioPin++), Room = room.RoomType } ).ToList() } ); } await BuildingPersistence.SaveAsync(BuildingPersistence.Instance); Navigator.Navigate(typeof(MonitorPage), null); }
async Task <LightControlSwitchBuildingResult> SwitchBuildingAsync(bool interfaceMemberOnOff) { BuildingPersistence.Instance?.SwitchAllLights(interfaceMemberOnOff); await BuildingPersistence.SaveAsync(BuildingPersistence.Instance); return(LightControlSwitchBuildingResult.CreateSuccessResult()); }
async void OnSuspending(object sender, SuspendingEventArgs e) { var deferral = e.SuspendingOperation.GetDeferral(); await BuildingPersistence.SaveAsync(BuildingPersistence.Instance); deferral.Complete(); }
async void OnNameBuildingAndContinue(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(this.txtBuildingName.Text)) { BuildingPersistence.Instance = new Model.Building(); BuildingPersistence.Instance.Name = this.txtBuildingName.Text; await BuildingPersistence.SaveAsync(BuildingPersistence.Instance); Navigator.Navigate(typeof(SetupRoomsPage), null); } }
async Task <LightControlToggleRoomLightResult> InternalToggleRoomLightAsync( string interfaceMemberRoomName, int interfaceMemberLightIndex) { var room = BuildingPersistence.Instance?.GetRoomByName(interfaceMemberRoomName); room?.ToggleLight(interfaceMemberLightIndex); await BuildingPersistence.SaveAsync(BuildingPersistence.Instance); return(LightControlToggleRoomLightResult.CreateSuccessResult()); }
async Task <LightControlSwitchRoomResult> InternalSwitchRoomAsync( string interfaceMemberRoomName, bool interfaceMemberOnOff) { var room = BuildingPersistence.Instance?.GetRoomByName(interfaceMemberRoomName); room?.SwitchLights(interfaceMemberOnOff); await BuildingPersistence.SaveAsync(BuildingPersistence.Instance); return(LightControlSwitchRoomResult.CreateSuccessResult()); }
async Task SwitchLightsInRoomAsync(Room room, bool onOff) { room.SwitchLights(onOff); if (this.isLocalBuilding) { await BuildingPersistence.SaveAsync(BuildingPersistence.Instance); } else { await this.currentConsumer?.SwitchRoomAsync( room.RoomType.ToString(), onOff); } }
async void OnUILightBulbPressed(object sender, PointerRoutedEventArgs e) { // Sorry about this, really should have bitten the bullet and written // viewmodels. var bulb = (LightBulb)sender; var light = (Light)bulb.Tag; light.IsOn = !light.IsOn; if (this.isLocalBuilding) { await BuildingPersistence.SaveAsync(BuildingPersistence.Instance); } else { await this.currentConsumer?.ToggleRoomLightAsync( light.Room.ToString(), light.Id); } e.Handled = true; }