Example #1
0
        async Task <bool> OnStatus(string information, int requestId, string body)
        {
            string replyBody;
            bool   rc = true;

            switch (information)
            {
            case RoonApi.ServiceStatus + "/subscribe_status":
                _subscriptionHandler.AddSubscription(body, requestId);
                replyBody = JsonConvert.SerializeObject(_currentStatus);
                rc        = await _api.Reply("Subscribed", requestId, true, replyBody);

                break;

            case RoonApi.ServiceStatus + "/unsubscribe_controls":
                _subscriptionHandler.RemoveSubscription(body);
                rc = await _api.Reply("Unsubscribed", requestId);

                break;

            case RoonApi.ServiceStatus + "/get_Status":
                replyBody = JsonConvert.SerializeObject(_currentStatus);
                rc        = await _api.Reply("Success", requestId, false, replyBody);

                break;
            }

            return(rc);
        }
Example #2
0
        async Task <bool> OnSettings(string information, int requestId, string body)
        {
            string replyBody;
            bool   rc = true;

            switch (information)
            {
            case RoonApi.ServiceSettings + "/subscribe_settings":
                _subscriptionHandler.AddSubscription(body, requestId);
                replyBody = JsonConvert.SerializeObject(new SettingsAll {
                    Settings = new LayoutAndSettings {
                        Layout = _layout.ToArray(), Values = _values, HasError = false
                    }
                });
                rc = await _api.Reply("Subscribed", requestId, true, replyBody);

                break;

            case RoonApi.ServiceSettings + "/unsubscribe_settings":
                _subscriptionHandler.RemoveSubscription(body);
                rc = await _api.Reply("Unsubscribed", requestId);

                break;

            case RoonApi.ServiceSettings + "/get_settings":
                replyBody = JsonConvert.SerializeObject(new SettingsAll {
                    Settings = new LayoutAndSettings {
                        Layout = _layout.ToArray(), Values = _values, HasError = false
                    }
                });
                rc = await _api.Reply("Success", requestId, false, replyBody);

                break;

            case RoonApi.ServiceSettings + "/save_settings":
                var settings = JsonConvert.DeserializeObject <SaveSettings>(body);
                rc = await _functions[0].SaveSettings?.Invoke(settings);
                var settingsAll = new SettingsAll {
                    Settings = new LayoutAndSettings {
                        Layout = _layout.ToArray(), Values = _values, HasError = !rc
                    }
                };
                replyBody = JsonConvert.SerializeObject(settingsAll);
                rc        = await _api.Reply(rc? "Success" : "NotValid", requestId, false, replyBody);

                // rc = await UpdateSettings();
                break;

            case RoonApi.ServiceSettings + "/button_pressed":
                var button = JsonConvert.DeserializeObject <ButtonPressed>(body);
                rc = await _api.Reply("Success", requestId, false);

                rc = await _functions[0].ButtonPressed?.Invoke(button);
                break;
            }
            return(rc);
        }
Example #3
0
        async Task <bool> OnVolumeControl(string information, int requestId, string body)
        {
            string replyBody;
            bool   rc = true;

            switch (information)
            {
            case RoonApi.ControlVolume + "/subscribe_controls":
                _subscriptionHandler.AddSubscription(body, requestId);
                replyBody = JsonConvert.SerializeObject(new VolumeControls {
                    Controls = _controls.ToArray()
                });
                rc = await _api.Reply("Subscribed", requestId, true, replyBody);

                break;

            case RoonApi.ControlVolume + "/unsubscribe_controls":
                _subscriptionHandler.RemoveSubscription(body);
                rc = await _api.Reply("Unsubscribed", requestId);

                break;

            case RoonApi.ControlVolume + "/get_all":
                replyBody = JsonConvert.SerializeObject(new VolumeControls {
                    Controls = _controls.ToArray()
                });
                rc = await _api.Reply("Success", requestId, false, replyBody);

                break;

            case RoonApi.ControlVolume + "/set_volume":
                var volume = JsonConvert.DeserializeObject <SetVolume>(body);
                if (volume.ControlKey >= _controls.Count)
                {
                    rc = await _api.Reply("Failure", requestId);
                }
                else
                {
                    rc = await _functions[volume.ControlKey].SetVolume?.Invoke(volume);
                    _controls[volume.ControlKey].VolumeValue = volume.Value;
                    rc = await _api.Reply("Success", requestId);

                    if (_simulateFeedback)
                    {
                        rc = await UpdateState(_controls[volume.ControlKey]);
                    }
                }
                break;

            case RoonApi.ControlVolume + "/set_mute":
                var mute = JsonConvert.DeserializeObject <SetMute>(body);
                if (mute.ControlKey >= _controls.Count)
                {
                    rc = await _api.Reply("Failure", requestId);
                }
                else
                {
                    rc = await _functions[mute.ControlKey].Mute?.Invoke(mute);
                    _controls[mute.ControlKey].IsMuted = mute.Mute == RoonApiTransport.EMute.mute;
                    rc = await _api.Reply("Success", requestId);

                    if (_simulateFeedback)
                    {
                        rc = await UpdateState(_controls[mute.ControlKey]);
                    }
                }
                break;
            }

            return(rc);
        }
Example #4
0
        async Task <bool> OnSourceControl(string information, int requestId, string body)
        {
            string replyBody;
            bool   rc = true;

            switch (information)
            {
            case RoonApi.ControlSource + "/subscribe_controls":
                _subscriptionHandler.AddSubscription(body, requestId);
                replyBody = JsonConvert.SerializeObject(new SourceControls {
                    Controls = _controls.ToArray()
                });
                rc = await _api.Reply("Subscribed", requestId, true, replyBody);

                break;

            case RoonApi.ControlSource + "/unsubscribe_controls":
                _subscriptionHandler.RemoveSubscription(body);
                rc = await _api.Reply("Unsubscribed", requestId);

                break;

            case RoonApi.ControlSource + "/get_all":
                replyBody = JsonConvert.SerializeObject(new SourceControls {
                    Controls = _controls.ToArray()
                });
                rc = await _api.Reply("Success", requestId, false, replyBody);

                break;

            case RoonApi.ControlSource + "/standby":
                var state = JsonConvert.DeserializeObject <SetState>(body);
                if (state.ControlKey >= _controls.Count)
                {
                    rc = await _api.Reply("Failure", requestId);
                }
                else
                {
                    rc = await _functions[state.ControlKey].SetStandby?.Invoke(state);
                    _controls[state.ControlKey].Status = state.Status;
                    rc = await _api.Reply("Success", requestId);

                    if (_simulateFeedback)
                    {
                        rc = await UpdateState(_controls[state.ControlKey]);
                    }
                }
                break;

            case RoonApi.ControlSource + "/convenience_switch":
                var convenience = JsonConvert.DeserializeObject <SetConvenience>(body);
                if (convenience.ControlKey >= _controls.Count)
                {
                    rc = await _api.Reply("Failure", requestId);
                }
                else
                {
                    rc = await _functions[convenience.ControlKey].SetConvenience?.Invoke(convenience);
                    rc = await _api.Reply("Success", requestId);

                    if (_simulateFeedback)
                    {
                        rc = await UpdateState(_controls[convenience.ControlKey]);
                    }
                }
                break;
            }

            return(rc);
        }