예제 #1
0
        public async Task <Result> Start()
        {
            var result = await _playerService.StartTcp();

            await Task.Delay(1000);

            PushNotification("Start Tcp");

            return(result);
        }
예제 #2
0
        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
            });
        }