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 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); }
public void Update(IThermostatFanState state) { Mode = state.Mode; CurrentAction = state.CurrentAction; if (state.SupportedModes != null) { SupportedModes = state.SupportedModes.ToList(); } }
public static bool HasData(this IThermostatFanState state) { var result = state.CurrentAction != null || state.Mode != null || (state.SupportedModes != null && state.SupportedModes.Any()) ; return(result); }
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)); }
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; }
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()); }
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); }
public ReadOnlyThermostatState(IThermostatCoreState coreState, IThermostatFanState fanState, IThermostatSetpointCollectionState setpointStates) { CoreState = coreState; FanState = fanState; SetpointStates = setpointStates; }
public static ReadOnlyThermostatFanState Copy(this IThermostatFanState state) { return(ReadOnlyThermostatFanState.CopyFrom(state)); }