/// <summary>
        /// Performs given action.
        /// </summary>
        /// <param name="action">Action to perform.</param>
        /// <param name="value">Optional value of the action.</param>
        /// <param name="writeByte">If true, changes will be written to the device.</param>
        /// <param name="index">Optional index of the action.</param>
        private void PerformAction(APA102Action action, int?value = null, bool writeByte = false, int?index = null)
        {
            // Get specified leds.
            List <APA102LED> specifiedLEDs;

            if (index is int ledIndex)
            {
                specifiedLEDs = new List <APA102LED> {
                    leds[ledIndex]
                };
            }
            else
            {
                specifiedLEDs = leds.ToList();
            }

            // Perform action.
            switch (action)
            {
            case APA102Action.TurnOn:
                specifiedLEDs.ForEach(p => p.TurnOn());
                break;

            case APA102Action.TurnOff:
                specifiedLEDs.ForEach(p => p.TurnOff());
                break;

            case APA102Action.ModifyBrightness:
                var brightnessValues = Convert.ToDecimal(value) / 100;
                specifiedLEDs.ForEach(p => p.SetBrightness(brightnessValues));
                break;

            case APA102Action.ModifyRed:
                var redValue = Convert.ToInt32(value);
                specifiedLEDs.ForEach(p => p.SetRed(redValue));
                break;

            case APA102Action.ModifyGreen:
                var greenValue = Convert.ToInt32(value);
                specifiedLEDs.ForEach(p => p.SetGreen(greenValue));
                break;

            case APA102Action.ModifyBlue:
                var blueValue = Convert.ToInt32(value);
                specifiedLEDs.ForEach(p => p.SetBlue(blueValue));
                break;

            case APA102Action.ShowColors:
                leds[0].SetRgbHex("#ee4035", 0.1m);
                leds[1].SetRgbHex("#ee4035", 0.1m);
                leds[2].SetRgbHex("#f37736", 0.1m);
                leds[3].SetRgbHex("#fdf498", 0.1m);
                leds[4].SetRgbHex("#7bc043", 0.1m);
                leds[5].SetRgbHex("#0392cf", 0.1m);
                leds[6].SetRgbHex("#0392cf", 0.1m);
                break;

            default:
                throw new NotImplementedException($"{action} is not implemented");
            }

            // Write bytes to GPIO if required.
            if (writeByte)
            {
                WriteLEDValues();
            }
        }