public static ReadOnlyMultilevelSwitchState CopyFrom(IMultilevelSwitchState source)
        {
            var result = new ReadOnlyMultilevelSwitchState
            {
                Power = source.Power,
                MaxPower =  source.MaxPower
            };

            return result;
        }
        public static ReadOnlyMultilevelSwitchState CopyFrom(IMultilevelSwitchState source)
        {
            var result = new ReadOnlyMultilevelSwitchState
            {
                Power    = source.Power,
                MaxPower = source.MaxPower
            };

            return(result);
        }
Exemple #3
0
        public static void AssertDimmerSwitchEqual(IMultilevelSwitchState one, IMultilevelSwitchState two)
        {
            if (one == null && two == null)
            {
                return;
            }

            AssertHelperHelper(one, two);

            Assert.That(one.Power, Is.EqualTo(two.Power));
        }
Exemple #4
0
        public static XElement ToXElement(this IMultilevelSwitchState state, string nodeName = "DimmerSwitch")
        {
            var result = new XElement("DimmerSwitch");

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

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

            return(result);
        }
Exemple #5
0
        public static int?CalculatePowerPercentage(this IMultilevelSwitchState state)
        {
            if (state == null)
            {
                return(null);
            }

            if (state.Power == null)
            {
                return(null);
            }

            var result = state.Power * 100 / (state.MaxPower > 0 ? state.MaxPower : 100);

            return(result);
        }
Exemple #6
0
        public static string Describe(this IMultilevelSwitchState state)
        {
            var result = new StringBuilder();

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

            var percentage = state.CalculatePowerPercentage();

            if (percentage != null)
            {
                result.Append(percentage);
                result.Append("%");
            }

            return(result.ToString());
        }
Exemple #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;
 }
Exemple #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;
 }
Exemple #9
0
 public void Update(IMultilevelSwitchState state)
 {
     Power = state.Power;
     MaxPower = state.MaxPower;
 }
Exemple #10
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);
        }
Exemple #11
0
 public static ReadOnlyMultilevelSwitchState Copy(this IMultilevelSwitchState state)
 {
     return(ReadOnlyMultilevelSwitchState.CopyFrom(state));
 }
Exemple #12
0
 public void Update(IMultilevelSwitchState state)
 {
     Power = state.Power;
     MaxPower = state.MaxPower;
 }