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); }
public static XElement ToXElement(this IThermostatCoreState state, string nodeName = "ThermostatCoreState") { 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); }
public void Update(IThermostatCoreState state) { Mode = state.Mode; CurrentAction = state.CurrentAction; if (state.SupportedModes != null) { SupportedModes = state.SupportedModes.ToList(); } }
public static bool HasData(this IThermostatCoreState state) { var result = state.CurrentAction != null || state.Mode != null || (state.SupportedModes != null && state.SupportedModes.Any()) ; return(result); }
public static void AssertThermostatCoreEqual(IThermostatCoreState one, IThermostatCoreState 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)); }
public static ReadOnlyThermostatCoreState CopyFrom(IThermostatCoreState state) { var supportedModes = new List<ThermostatMode>(); if (state.SupportedModes != null) { supportedModes.AddRange(state.SupportedModes); } var result = new ReadOnlyThermostatCoreState { SupportedModes = supportedModes, Mode = state.Mode, CurrentAction = state.CurrentAction }; return result; }
public static string Describe(this IThermostatCoreState 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()); }
public static ReadOnlyThermostatCoreState CopyFrom(IThermostatCoreState state) { var supportedModes = new List <ThermostatMode>(); if (state.SupportedModes != null) { supportedModes.AddRange(state.SupportedModes); } var result = new ReadOnlyThermostatCoreState { SupportedModes = supportedModes, Mode = state.Mode, CurrentAction = state.CurrentAction }; return(result); }
public ReadOnlyThermostatState(IThermostatCoreState coreState, IThermostatFanState fanState, IThermostatSetpointCollectionState setpointStates) { CoreState = coreState; FanState = fanState; SetpointStates = setpointStates; }
public static ReadOnlyThermostatCoreState Copy(this IThermostatCoreState state) { return(ReadOnlyThermostatCoreState.CopyFrom(state)); }