public LightingState(LightingState lightingState)
 {
     timePeriod           = new TimePeriod(lightingState.timePeriod);
     type                 = lightingState.type;
     startingDimmingLevel = lightingState.startingDimmingLevel;
     endingDimmingLevel   = lightingState.endingDimmingLevel;
 }
        public LightingState[] Read(JObject jobj, string[] keys)
        {
            var lightingStates = new List <LightingState> ();
            var jaEvents       = jobj["events"] as JArray;

            foreach (var jtEvent in jaEvents)
            {
                JObject joEvent = jtEvent as JObject;

                var startTimeDescriptor = (string)joEvent["startTimeDescriptor"];
                var endTimeDescriptor   = (string)joEvent["endTimeDescriptor"];

                var type = LightingStateType.Off;
                var text = (string)joEvent["type"];
                if (text.IsNotEmpty())
                {
                    try {
                        type = (LightingStateType)Enum.Parse(typeof(LightingStateType), text);
                    } catch {
                        //
                    }
                }

                LightingState state;
                if (joEvent.ContainsKey("startingDimmingLevel"))
                {
                    var startingDimmingLevel = 0.0f;
                    text = (string)joEvent["startingDimmingLevel"];
                    if (text.IsNotEmpty())
                    {
                        try {
                            startingDimmingLevel = Convert.ToSingle(text);
                        } catch {
                            //
                        }
                    }

                    var endingDimmingLevel = 0.0f;
                    text = (string)joEvent["endingDimmingLevel"];
                    if (text.IsNotEmpty())
                    {
                        try {
                            endingDimmingLevel = Convert.ToSingle(text);
                        } catch {
                            //
                        }
                    }

                    state = new LightingState(
                        startTimeDescriptor,
                        endTimeDescriptor,
                        type,
                        startingDimmingLevel,
                        endingDimmingLevel);
                }
                else
                {
                    state = new LightingState(
                        startTimeDescriptor,
                        endTimeDescriptor,
                        type);
                }
                lightingStates.Add(state);
            }

            return(lightingStates.ToArray());
        }