public async Task <Result> OkButton() { var sb = new StringBuilder(); var powerStatus = await YamahaService.PowerStatus(); if (powerStatus == PowerStatusEnum.On) { var state = await SmartHouseService.GetCurrentState(); if (state == SmartHouseState.Pandora) { if (await PlayerService.IsPlaying()) { PlayerService.Pause(); } else { PlayerService.Play(); } sb.AppendLine("Starting to play/pause Pandora"); } else if (state == SmartHouseState.Music) { if (MpdService.GetStatus().State == MpdState.Play) { MpdService.Pause(); } else if (MpdService.GetStatus().State == MpdState.Pause) { MpdService.Play(); } } else if (state == SmartHouseState.TV) { await TVService.Ok(); } } else { sb.AppendLine("Yamaha is turned off. Operation canceled"); PushNotification("Yamaha is turned off. Operation canceled"); } return(new Result() { ErrorCode = 0, Message = sb.ToString(), Ok = true }); }
public Result Play() { var result = _playerService.Play(); PushNotification("Play"); return(result); }
public async Task <Result> TurnOn() { var sb = new StringBuilder(); var powerStatus = await _yamahaService.PowerStatus(); if (powerStatus == PowerStatusEnum.StandBy) { PushNotification("Please wait..."); await _tvService.Power(); sb.AppendLine("Turning on TV"); await _yamahaService.TurnOn(); sb.AppendLine("Yamaha Turn on"); if (await _sunriseSunsetService.IsNight()) { await _smartBulbService.Initialize(); await _smartBulbService.TurnOn(); sb.AppendLine("Smart blub turn on"); } await Task.Delay(TimeSpan.FromSeconds(8)); } if (!DefaultVolumeSetterState.IsDefaultVolumeSetted()) { await _smartHouseService.SetMode(ModeEnum.Normal, VolumeChangeNotify); sb.AppendLine("Setting Normal mode"); DefaultVolumeSetterState.DefaultVolumeSetted(); } var state = await _smartHouseService.GetCurrentState(); if (state == SmartHouseState.Music && _mpdService.GetStatus().State != Libmpc.MpdState.Play) { if (await _playerService.IsPlaying()) { _playerService.Pause(); } await _yamahaService.SetInput("HDMI1"); sb.AppendLine("Setting HDMI1 input"); _mpdService.Play(); sb.AppendLine("Playing MPD"); } else if (state == SmartHouseState.Pandora) { await _yamahaService.SetInput(_playerService.GetAmplifierInput()); sb.AppendLine("Setting HDMI1 input"); if (!await _playerService.IsPlaying()) { await _playerService.StartTcp(); _playerService.Play(); sb.AppendLine("Playing radio"); } } else if (state == SmartHouseState.TV) { await Task.Delay(TimeSpan.FromSeconds(2)); await _tvService.Home(); sb.AppendLine("TV Home IR button"); await _yamahaService.SetInput("AUDIO1"); sb.AppendLine("Setting AUDIO1 input"); } NotifyClients(); PushNotification("Smart house is turn on"); return(new Result() { ErrorCode = 0, Message = sb.ToString(), Ok = true }); }