public static ReadOnlyThermostatCoreState Empty()
        {
            var result = new ReadOnlyThermostatCoreState
            {
                SupportedModes = new ThermostatMode[] {}
            };

            return(result);
        }
        public static ReadOnlyThermostatCoreState Blank()
        {
            var result = new ReadOnlyThermostatCoreState
            {
                SupportedModes = new ThermostatMode[0]
            };

            return(result);
        }
        public static ReadOnlyThermostatCoreState Empty()
        {
            var result = new ReadOnlyThermostatCoreState
                {
                    SupportedModes = new ThermostatMode[] {}
                };

            return result;
        }
        public static ReadOnlyThermostatCoreState Blank()
        {
            var result = new ReadOnlyThermostatCoreState
            {
                SupportedModes = new ThermostatMode[0]
            };

            return result;
        }
        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 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 ReadOnlyThermostatCoreState FromXElement(XElement element)
        {
            ThermostatCurrentAction?currentAction = null;
            var currentActionString = element.GetAttributeStringValue("CurrentAction");

            if (currentActionString != null)
            {
                currentAction = currentActionString.ToThermostatCurrentAction();
            }

            ThermostatMode?mode       = null;
            var            modeString = element.GetAttributeStringValue("Mode");

            if (modeString != null)
            {
                mode = modeString.ToThermostatMode();
            }

            var supportedModes     = new List <ThermostatMode>();
            var supportedModesNode = element.Element("SupportedModes");

            if (supportedModesNode != null)
            {
                foreach (var modeElement in supportedModesNode.Elements())
                {
                    var supportedMode = modeElement.Value.ToThermostatMode();
                    supportedModes.Add(supportedMode);
                }
            }

            var result = new ReadOnlyThermostatCoreState
            {
                CurrentAction  = currentAction,
                Mode           = mode,
                SupportedModes = supportedModes
            };

            return(result);
        }
        public static ReadOnlyThermostatCoreState FromXElement(XElement element)
        {
            ThermostatCurrentAction? currentAction = null;
            var currentActionString = element.GetAttributeStringValue("CurrentAction");
            if (currentActionString != null)
            {
                currentAction = currentActionString.ToThermostatCurrentAction();
            }

            ThermostatMode? mode = null;
            var modeString = element.GetAttributeStringValue("Mode");
            if (modeString != null)
            {
                mode = modeString.ToThermostatMode();
            }

            var supportedModes = new List<ThermostatMode>();
            var supportedModesNode = element.Element("SupportedModes");
            if (supportedModesNode != null)
            {
                foreach (var modeElement in supportedModesNode.Elements())
                {
                    var supportedMode = modeElement.Value.ToThermostatMode();
                    supportedModes.Add(supportedMode);
                }
            }

            var result = new ReadOnlyThermostatCoreState
                {
                    CurrentAction = currentAction,
                    Mode = mode,
                    SupportedModes = supportedModes
                };

            return result;
        }
Exemple #9
0
        public static IDeviceState GenerateExampleDevice(DeviceType type, bool includeCurrentAction, bool includeToggle, bool includeDimmer, bool includeColorSwitch, bool includeBinarySensor, bool includePowerSensor, bool includeTemperatureSensor, bool includeHumiditySensor, bool includeIlluminanceSensor, bool includeThermostat, bool includeKeypad)
        {
            string currentAction = "Idle";

            var toggle = new ReadOnlyBinarySwitchSwitchState(BinarySwitchPower.On);
            var dimmer = new ReadOnlyMultilevelSwitchState(25, 100);
            var colorSwitch = new ReadOnlyColorSwitchState(new NamedColor("Purple"));

            var binarySensor = new ReadOnlyBinarySensorState(BinarySensorType.Motion, true, DateTime.UtcNow.AddMinutes(-4));

            var powerSensor = new ReadOnlyMultilevelSensorState<IPower>(new WattsPower(25), DateTime.UtcNow.AddSeconds(-2));

            var temperatureSensor = new ReadOnlyMultilevelSensorState<ITemperature>(new CelsiusTemperature(3), DateTime.UtcNow.AddSeconds(-1));

            var humiditySensor = new ReadOnlyMultilevelSensorState<IHumidity>(new RelativeHumidity(25), DateTime.UtcNow.AddSeconds(-5));

            var illuminanceSensor = new ReadOnlyMultilevelSensorState<IIlluminance>(new LuxIlluminance(50), DateTime.UtcNow.AddSeconds(-4));

            var thermostatCoreModes = new[] { ThermostatMode.Auto, ThermostatMode.Cool, ThermostatMode.Heat, ThermostatMode.FanOnly, ThermostatMode.Off };
            var thermostatCore = new ReadOnlyThermostatCoreState(thermostatCoreModes, ThermostatMode.Cool, ThermostatCurrentAction.Cooling);

            var thermostatFanModes = new[] { ThermostatFanMode.Auto, ThermostatFanMode.On };
            var thermostatFan = new ReadOnlyThermostatFanState(thermostatFanModes, ThermostatFanMode.Auto, ThermostatFanCurrentAction.On);

            var thermostatSetpoints = new ReadOnlyThermostatSetpointCollection(new Dictionary<ThermostatSetpointType, ITemperature>
                {
                    {ThermostatSetpointType.Cool, new FahrenheitTemperature(74)},
                    {ThermostatSetpointType.Heat, new FahrenheitTemperature(70)}
                });

            var thermostat = new ReadOnlyThermostatState(thermostatCore, thermostatFan, thermostatSetpoints);

            var keypadButtons = new []
                {
                    new ReadOnlyKeypadButtonState("1", false),
                    new ReadOnlyKeypadButtonState("2", true),
                    new ReadOnlyKeypadButtonState("3", null)
                };

            var keypad = new ReadOnlyKeypadState(keypadButtons);

            var location = new Location("Here");

            var address = _id.ToString();
            _id++;

            if (!includeCurrentAction)
            {
                currentAction = null;
            }

            if (!includeToggle)
            {
                toggle = null;
            }

            if (!includeDimmer)
            {
                dimmer = null;
            }

            if (!includeColorSwitch)
            {
                colorSwitch = null;
            }

            if (!includeBinarySensor)
            {
                binarySensor = null;
            }

            if (!includePowerSensor)
            {
                powerSensor = null;
            }

            if (!includeTemperatureSensor)
            {
                temperatureSensor = null;
            }

            if (!includeHumiditySensor)
            {
                humiditySensor = null;
            }

            if (!includeIlluminanceSensor)
            {
                illuminanceSensor = null;
            }

            if (!includeThermostat)
            {
                thermostat = null;
            }

            if (!includeKeypad)
            {
                keypad = null;
            }

            var device = new ReadOnlyDeviceState("Sample Device", address, location, null, true, type, currentAction, toggle, dimmer, colorSwitch, binarySensor, powerSensor, temperatureSensor, humiditySensor, illuminanceSensor, thermostat, keypad);

            return device;
        }
 public static ReadOnlyThermostatCoreState ToThermostatCoreState(this XElement element)
 {
     return(ReadOnlyThermostatCoreState.FromXElement(element));
 }
 public static ReadOnlyThermostatCoreState Copy(this IThermostatCoreState state)
 {
     return(ReadOnlyThermostatCoreState.CopyFrom(state));
 }