public static XElement ToXElement(this IThermostatState state, string nodeName = "Thermostat")
        {
            var result = new XElement(nodeName);

            if (state.CoreState != null)
            {
                var element = state.CoreState.ToXElement();

                result.AddIfHasData(element);
            }

            if (state.FanState != null)
            {
                var element = state.FanState.ToXElement();

                result.AddIfHasData(element);
            }

            if (state.SetpointStates != null)
            {
                var element = state.SetpointStates.ToXElement();

                result.AddIfHasData(element);
            }

            return(result);
        }
        public static bool HasData(this IThermostatState state)
        {
            var result =
                (state.CoreState != null && state.CoreState.HasData()) ||
                (state.FanState != null && state.FanState.HasData()) ||
                (state.SetpointStates != null && state.SetpointStates.HasData())
            ;

            return(result);
        }
示例#3
0
        public static ReadOnlyThermostatState CopyFrom(IThermostatState state)
        {
            var result = new ReadOnlyThermostatState
            {
                CoreState = (state.CoreState == null) ? null : state.CoreState.Copy(),
                FanState = (state.FanState == null) ? null : state.FanState.Copy(),
                SetpointStates = (state.SetpointStates == null) ? null : state.SetpointStates.Copy(),
            };

            return result;
        }
示例#4
0
        public static ReadOnlyThermostatState CopyFrom(IThermostatState state)
        {
            var result = new ReadOnlyThermostatState
            {
                CoreState      = (state.CoreState == null) ? null : state.CoreState.Copy(),
                FanState       = (state.FanState == null) ? null : state.FanState.Copy(),
                SetpointStates = (state.SetpointStates == null) ? null : state.SetpointStates.Copy(),
            };

            return(result);
        }
示例#5
0
        public static void AssertThermostatEqual(IThermostatState one, IThermostatState two)
        {
            if (one == null && two == null)
            {
                return;
            }

            AssertHelperHelper(one, two);

            AssertThermostatCoreEqual(one.CoreState, two.CoreState);
            AssertThermostatFanEqual(one.FanState, two.FanState);
            AssertThermostatSetpointsAreEqual(one.SetpointStates, two.SetpointStates);
        }
        public static string Describe(this IThermostatState state)
        {
            var result = new StringBuilder();

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

            var coreDescription = state.CoreState.Describe();

            if (!string.IsNullOrEmpty(coreDescription))
            {
                if (result.Length > 0)
                {
                    result.Append(" | ");
                }

                result.Append("Core: ");
                result.Append(coreDescription);
            }

            var fanDescription = state.FanState.Describe();

            if (!string.IsNullOrEmpty(fanDescription))
            {
                if (result.Length > 0)
                {
                    result.Append(" | ");
                }

                result.Append("Fan: ");
                result.Append(fanDescription);
            }

            var setpointsDescription = state.SetpointStates.Describe();

            if (!string.IsNullOrEmpty(setpointsDescription))
            {
                if (result.Length > 0)
                {
                    result.Append(" | ");
                }

                result.Append("Setpoints: ");
                result.Append(setpointsDescription);
            }

            return(result.ToString());
        }
示例#7
0
 public ReadOnlyDeviceState(string name, string address, ILocation location, INetwork network, bool?isConnected, DeviceType type, string currentAction, IBinarySwitchState toggleSwitchState, IMultilevelSwitchState dimmerSwitchState, IColorSwitchState colorSwitchState, IBinarySensorState binarySensorState, IMultilevelSensorState <IPower> powerSensorState, IMultilevelSensorState <ITemperature> temperatureSensorState, IMultilevelSensorState <IHumidity> humiditySensorState, IMultilevelSensorState <IIlluminance> illuminanceSensorState, IThermostatState thermostatState, IKeypadState keypadState)
 {
     Name                   = name;
     Address                = address;
     Location               = location;
     NetworkState           = network;
     IsConnected            = isConnected;
     Type                   = type;
     CurrentAction          = currentAction;
     BinarySwitchState      = toggleSwitchState;
     MultilevelSwitchState  = dimmerSwitchState;
     ColorSwitchState       = colorSwitchState;
     BinarySensorState      = binarySensorState;
     PowerSensorState       = powerSensorState;
     TemperatureSensorState = temperatureSensorState;
     HumiditySensorState    = humiditySensorState;
     IlluminanceSensorState = illuminanceSensorState;
     ThermostatState        = thermostatState;
     KeypadState            = keypadState;
 }
示例#8
0
 public ReadOnlyDeviceState(string name, string address, ILocation location, INetwork network, bool? isConnected, DeviceType type, string currentAction, IBinarySwitchState toggleSwitchState, IMultilevelSwitchState dimmerSwitchState, IColorSwitchState colorSwitchState, IBinarySensorState binarySensorState, IMultilevelSensorState<IPower> powerSensorState, IMultilevelSensorState<ITemperature> temperatureSensorState, IMultilevelSensorState<IHumidity> humiditySensorState, IMultilevelSensorState<IIlluminance> illuminanceSensorState, IThermostatState thermostatState, IKeypadState keypadState)
 {
     Name = name;
     Address = address;
     Location = location;
     NetworkState = network;
     IsConnected = isConnected;
     Type = type;
     CurrentAction = currentAction;
     BinarySwitchState = toggleSwitchState;
     MultilevelSwitchState = dimmerSwitchState;
     ColorSwitchState = colorSwitchState;
     BinarySensorState = binarySensorState;
     PowerSensorState = powerSensorState;
     TemperatureSensorState = temperatureSensorState;
     HumiditySensorState = humiditySensorState;
     IlluminanceSensorState = illuminanceSensorState;
     ThermostatState = thermostatState;
     KeypadState = keypadState;
 }
示例#9
0
        //TODO: unit test this
        public static ReadOnlyDeviceState FromXElement(XElement element)
        {
            var name          = element.GetAttributeStringValue("Name");
            var notes         = element.GetAttributeStringValue("Notes");
            var address       = element.GetAttributeStringValue("Address");
            var isConnected   = element.GetAttributeBoolValue("IsConnected");
            var type          = element.GetAttributeStringValue("Type");
            var currentAction = element.GetAttributeStringValue("CurrentAction");
            var locationName  = element.GetAttributeStringValue("Location");

            IBinarySwitchState toggleSwitch = null;
            var toggleSwitchElement         = element.Element("ToggleSwitch");

            if (toggleSwitchElement != null)
            {
                toggleSwitch = toggleSwitchElement.ToToggleSwitch();
            }

            IMultilevelSwitchState dimmerSwitch = null;
            var dimmerSwitchElement             = element.Element("DimmerSwitch");

            if (dimmerSwitchElement != null)
            {
                dimmerSwitch = dimmerSwitchElement.ToDimmerSwitch();
            }

            IColorSwitchState colorSwitch = null;
            var colorSwitchElement        = element.Element("ColorSwitch");

            if (colorSwitchElement != null)
            {
                colorSwitch = colorSwitchElement.ToColorSwitch();
            }

            IBinarySensorState binarySensor = null;
            var binarySensorElement         = element.Element("BinarySensor");

            if (binarySensorElement != null)
            {
                binarySensor = binarySensorElement.ToBinarySensor();
            }

            ReadOnlyMultilevelSensorState <IPower> powerSensor = null;
            var powerSensorElement = element.Element("PowerSensor");

            if (powerSensorElement != null)
            {
                powerSensor = powerSensorElement.ToMultilevelSensor <IPower>();
            }

            ReadOnlyMultilevelSensorState <ITemperature> temperatureSensor = null;
            var temperatureSensorElement = element.Element("TemperatureSensor");

            if (temperatureSensorElement != null)
            {
                temperatureSensor = temperatureSensorElement.ToMultilevelSensor <ITemperature>();
            }

            ReadOnlyMultilevelSensorState <IHumidity> humiditySensor = null;
            var humiditySensorElement = element.Element("HumiditySensor");

            if (humiditySensorElement != null)
            {
                humiditySensor = humiditySensorElement.ToMultilevelSensor <IHumidity>();
            }

            ReadOnlyMultilevelSensorState <IIlluminance> illuminanceSensor = null;
            var illuminanceSensorElement = element.Element("IlluminanceSensor");

            if (illuminanceSensorElement != null)
            {
                illuminanceSensor = illuminanceSensorElement.ToMultilevelSensor <IIlluminance>();
            }

            IThermostatState thermostat = null;
            var thermostatElement       = element.Element("Thermostat");

            if (thermostatElement != null)
            {
                thermostat = thermostatElement.ToThermostat();
            }

            IKeypadState keypad        = null;
            var          keypadElement = element.Element("Keypad");

            if (keypadElement != null)
            {
                keypad = keypadElement.ToKeypad();
            }

            var result = new ReadOnlyDeviceState
            {
                Name                   = name,
                Address                = address,
                Location               = new Location(locationName),
                IsConnected            = isConnected,
                Type                   = DeviceType.GetTypeFromString(type),
                CurrentAction          = currentAction,
                BinarySwitchState      = toggleSwitch,
                MultilevelSwitchState  = dimmerSwitch,
                ColorSwitchState       = colorSwitch,
                BinarySensorState      = binarySensor,
                PowerSensorState       = powerSensor,
                TemperatureSensorState = temperatureSensor,
                HumiditySensorState    = humiditySensor,
                IlluminanceSensorState = illuminanceSensor,
                ThermostatState        = thermostat,
                KeypadState            = keypad
            };

            return(result);
        }
示例#10
0
 internal void Update(IThermostatState data)
 {
     Core.Update(data.CoreState ?? ReadOnlyThermostatCoreState.Blank());
     Fan.Update(data.FanState ?? ReadOnlyThermostatFanState.Blank());
     Setpoints.Update(data.SetpointStates ?? ReadOnlyThermostatSetpointCollection.Blank());
 }
示例#11
0
 internal void Update(IThermostatState data)
 {
     Core.Update(data.CoreState ?? ReadOnlyThermostatCoreState.Blank());
     Fan.Update(data.FanState ?? ReadOnlyThermostatFanState.Blank());
     Setpoints.Update(data.SetpointStates ?? ReadOnlyThermostatSetpointCollection.Blank());
 }
示例#12
0
 public static ReadOnlyThermostatState Copy(this IThermostatState state)
 {
     return(ReadOnlyThermostatState.CopyFrom(state));
 }