Ejemplo n.º 1
0
        public static ReadOnlyThermostatState FromXElement(XElement element)
        {
            IThermostatCoreState coreState = null;
            var coreStateNode = element.Element("ThermostatCoreState");

            if (coreStateNode != null)
            {
                coreState = coreStateNode.ToThermostatCoreState();
            }

            IThermostatFanState fanState = null;
            var fanStateNode             = element.Element("ThermostatFanState");

            if (fanStateNode != null)
            {
                fanState = fanStateNode.ToThermostatFanState();
            }

            IThermostatSetpointCollectionState setpoints = null;
            var setpointsNode = element.Element("Setpoints");

            if (setpointsNode != null)
            {
                setpoints = setpointsNode.ToSetpoints();
            }

            var result = new ReadOnlyThermostatState
            {
                CoreState      = coreState,
                FanState       = fanState,
                SetpointStates = setpoints
            };

            return(result);
        }
Ejemplo n.º 2
0
        public static XElement ToXElement(this IThermostatFanState state, string nodeName = "ThermostatFanState")
        {
            var result = new XElement(nodeName);

            if (state.CurrentAction != null)
            {
                result.Add(new XAttribute("CurrentAction", state.CurrentAction));
            }

            if (state.Mode != null)
            {
                result.Add(new XAttribute("Mode", state.Mode));
            }

            if (state.SupportedModes != null)
            {
                var supportedModes = state.SupportedModes.ToList();

                if (supportedModes.Count > 0)
                {
                    var supportedModesNode = new XElement("SupportedModes");
                    supportedModes.ForEach(x => supportedModesNode.Add(new XElement("SupportedMode", x)));
                    result.Add(supportedModesNode);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
 public void Update(IThermostatFanState state)
 {
     Mode = state.Mode;
     CurrentAction = state.CurrentAction;
     if (state.SupportedModes != null)
     {
         SupportedModes = state.SupportedModes.ToList();
     }
 }
Ejemplo n.º 4
0
 public void Update(IThermostatFanState state)
 {
     Mode          = state.Mode;
     CurrentAction = state.CurrentAction;
     if (state.SupportedModes != null)
     {
         SupportedModes = state.SupportedModes.ToList();
     }
 }
Ejemplo n.º 5
0
        public static bool HasData(this IThermostatFanState state)
        {
            var result =
                state.CurrentAction != null ||
                state.Mode != null ||
                (state.SupportedModes != null && state.SupportedModes.Any())
            ;

            return(result);
        }
Ejemplo n.º 6
0
        public static void AssertThermostatFanEqual(IThermostatFanState one, IThermostatFanState two)
        {
            if (one == null && two == null)
            {
                return;
            }

            AssertHelperHelper(one, two);

            Assert.That(one.Mode, Is.EqualTo(two.Mode));
            CollectionAssert.AreEquivalent(one.SupportedModes, two.SupportedModes);
            Assert.That(one.CurrentAction, Is.EqualTo(two.CurrentAction));
        }
Ejemplo n.º 7
0
        public static ReadOnlyThermostatFanState CopyFrom(IThermostatFanState state)
        {
            var supportedModes = new List<ThermostatFanMode>();
            if (state.SupportedModes != null)
            {
                supportedModes.AddRange(state.SupportedModes);
            }

            var result = new ReadOnlyThermostatFanState
            {
                SupportedModes = supportedModes,
                Mode = state.Mode,
                CurrentAction = state.CurrentAction
            };

            return result;
        }
Ejemplo n.º 8
0
        public static string Describe(this IThermostatFanState state)
        {
            var result = new StringBuilder();

            if (state == null)
            {
                return(result.ToString());
            }

            if (state.CurrentAction != null)
            {
                result.Append("Current Action: ");
                result.Append(state.CurrentAction);
            }

            if (state.Mode != null)
            {
                if (result.Length > 0)
                {
                    result.Append(", ");
                }

                result.Append("Mode: ");
                result.Append(state.Mode);
            }

            if (state.SupportedModes != null)
            {
                var modes = state.SupportedModes.ToArray();

                if (modes.Length > 0)
                {
                    if (result.Length > 0)
                    {
                        result.Append(", ");
                    }

                    result.Append("Supported Modes: ");

                    result.Append(string.Join(", ", modes));
                }
            }

            return(result.ToString());
        }
Ejemplo n.º 9
0
        public static ReadOnlyThermostatFanState CopyFrom(IThermostatFanState state)
        {
            var supportedModes = new List <ThermostatFanMode>();

            if (state.SupportedModes != null)
            {
                supportedModes.AddRange(state.SupportedModes);
            }

            var result = new ReadOnlyThermostatFanState
            {
                SupportedModes = supportedModes,
                Mode           = state.Mode,
                CurrentAction  = state.CurrentAction
            };

            return(result);
        }
Ejemplo n.º 10
0
 public ReadOnlyThermostatState(IThermostatCoreState coreState, IThermostatFanState fanState, IThermostatSetpointCollectionState setpointStates)
 {
     CoreState = coreState;
     FanState = fanState;
     SetpointStates = setpointStates;
 }
Ejemplo n.º 11
0
 public static ReadOnlyThermostatFanState Copy(this IThermostatFanState state)
 {
     return(ReadOnlyThermostatFanState.CopyFrom(state));
 }
Ejemplo n.º 12
0
 public ReadOnlyThermostatState(IThermostatCoreState coreState, IThermostatFanState fanState, IThermostatSetpointCollectionState setpointStates)
 {
     CoreState      = coreState;
     FanState       = fanState;
     SetpointStates = setpointStates;
 }