//TODO: unit test this public static ReadOnlyDeviceState CopyFrom(IDeviceState source) { var result = new ReadOnlyDeviceState { Name = source.Name, Address = source.Address, Location = source.Location.Copy(), NetworkState = source.NetworkState, IsConnected = source.IsConnected, Type = source.Type, CurrentAction = source.CurrentAction, BinarySwitchState = (source.BinarySwitchState == null) ? null : source.BinarySwitchState.Copy(), PowerSensorState = (source.PowerSensorState == null)?null:source.PowerSensorState.Copy(), TemperatureSensorState = (source.TemperatureSensorState == null) ? null : source.TemperatureSensorState.Copy(), HumiditySensorState = (source.HumiditySensorState == null) ? null : source.HumiditySensorState.Copy(), IlluminanceSensorState = (source.IlluminanceSensorState == null) ? null : source.IlluminanceSensorState.Copy(), MultilevelSwitchState = (source.MultilevelSwitchState == null) ? null : source.MultilevelSwitchState.Copy(), ColorSwitchState = (source.ColorSwitchState == null) ? null : source.ColorSwitchState.Copy(), BinarySensorState = (source.BinarySensorState == null)?null : source.BinarySensorState.Copy(), ThermostatState = (source.ThermostatState == null) ? null : source.ThermostatState.Copy(), KeypadState = (source.KeypadState == null) ? null : source.KeypadState.Copy() }; return(result); }
//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); }
public static ReadOnlyDeviceState Copy(this IDeviceState state) { return(ReadOnlyDeviceState.CopyFrom(state)); }
public static ReadOnlyDeviceState ToDeviceState(this XElement element) { return(ReadOnlyDeviceState.FromXElement(element)); }
//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; }
//TODO: unit test this public static ReadOnlyDeviceState CopyFrom(IDeviceState source) { var result = new ReadOnlyDeviceState { Name = source.Name, Address = source.Address, Location = source.Location.Copy(), NetworkState = source.NetworkState, IsConnected = source.IsConnected, Type = source.Type, CurrentAction = source.CurrentAction, BinarySwitchState = (source.BinarySwitchState == null) ? null : source.BinarySwitchState.Copy(), PowerSensorState = (source.PowerSensorState == null)?null:source.PowerSensorState.Copy(), TemperatureSensorState = (source.TemperatureSensorState == null) ? null : source.TemperatureSensorState.Copy(), HumiditySensorState = (source.HumiditySensorState == null) ? null : source.HumiditySensorState.Copy(), IlluminanceSensorState = (source.IlluminanceSensorState == null) ? null : source.IlluminanceSensorState.Copy(), MultilevelSwitchState = (source.MultilevelSwitchState == null) ? null : source.MultilevelSwitchState.Copy(), ColorSwitchState = (source.ColorSwitchState == null) ? null : source.ColorSwitchState.Copy(), BinarySensorState = (source.BinarySensorState == null)?null : source.BinarySensorState.Copy(), ThermostatState = (source.ThermostatState == null) ? null : source.ThermostatState.Copy(), KeypadState = (source.KeypadState == null) ? null : source.KeypadState.Copy() }; return result; }