/// <summary>
        /// Forward position request to command station
        /// </summary>
        private void OnRequestedColorChanged(BlockSignalColor value)
        {
            var cs = commandStation;

            if (cs != null)
            {
                var pattern = GetPattern(value);
                foreach (var address in Addresses)
                {
                    cs.SendBinaryOutput(address, (pattern & 0x01) != 0);
                    pattern >>= 1;
                }
                color.Actual = color.Requested;
            }
        }
        /// <summary>
        /// Validate the given color with what is actually supported.
        /// </summary>
        private BlockSignalColor ValidateColor(BlockSignalColor c)
        {
            switch (c)
            {
            case BlockSignalColor.Yellow:
                if (!Entity.IsYellowAvailable)
                {
                    return(BlockSignalColor.Green);
                }
                break;

            case BlockSignalColor.White:
                if (!Entity.IsWhiteAvailable)
                {
                    return(ValidateColor(BlockSignalColor.Yellow));
                }
                break;
            }
            return(c);
        }
        /// <summary>
        /// Gets the bit pattern to use for the given color.
        /// </summary>
        private int GetPattern(BlockSignalColor color)
        {
            var entity = Entity;

            switch (color)
            {
            case BlockSignalColor.Red:
                return(entity.RedPattern);

            case BlockSignalColor.Green:
                return(entity.GreenPattern);

            case BlockSignalColor.Yellow:
                return(entity.IsYellowAvailable ? entity.YellowPattern : GetPattern(BlockSignalColor.Green));

            case BlockSignalColor.White:
                return(entity.IsWhiteAvailable ? entity.WhitePattern : GetPattern(BlockSignalColor.Yellow));

            default:
                throw new ArgumentException("Unknown color: " + color);
            }
        }
        /// <summary>
        /// Gets the next color that is supported by my entity.
        /// </summary>
        public BlockSignalColor GetNextColor(BlockSignalColor current)
        {
            var entity = Entity;

            switch (current)
            {
            case BlockSignalColor.Red:
                if (entity.IsYellowAvailable)
                {
                    return(BlockSignalColor.Yellow);
                }
                return(GetNextColor(BlockSignalColor.Yellow));

            case BlockSignalColor.Yellow:
                if (entity.IsGreenAvailable)
                {
                    return(BlockSignalColor.Green);
                }
                return(GetNextColor(BlockSignalColor.Green));

            case BlockSignalColor.Green:
                if (entity.IsWhiteAvailable)
                {
                    return(BlockSignalColor.White);
                }
                return(GetNextColor(BlockSignalColor.White));

            case BlockSignalColor.White:
                if (entity.IsRedAvailable)
                {
                    return(BlockSignalColor.Red);
                }
                return(GetNextColor(BlockSignalColor.Red));

            default:
                return(BlockSignalColor.Red);
            }
        }