public static ReadOnlyBinarySensorState CopyFrom(IBinarySensorState source) { var result = new ReadOnlyBinarySensorState { Type = source.Type, Value = source.Value, TimeStamp = source.TimeStamp }; return(result); }
public static ReadOnlyBinarySensorState CopyFrom(IBinarySensorState source) { var result = new ReadOnlyBinarySensorState { Type = source.Type, Value = source.Value, TimeStamp = source.TimeStamp }; return result; }
public static void AssertBinarySensorEqual(IBinarySensorState one, IBinarySensorState two) { if (one == null && two == null) { return; } AssertHelperHelper(one, two); Assert.That(one.Type, Is.EqualTo(two.Type)); Assert.That(one.Value, Is.EqualTo(two.Value)); Assert.That(one.TimeStamp, Is.EqualTo(two.TimeStamp)); }
public static string Describe(this IBinarySensorState state, TimeZoneInfo timeZone = null) { var result = new StringBuilder(); if (state == null) { return(result.ToString()); } if (state.Value == null) { result.Append("Unknown"); } else { var value = state.Value.Value; switch (state.Type) { case BinarySensorType.Motion: result.Append(value ? "Motion" : "Stillness"); break; case BinarySensorType.Door: case BinarySensorType.Window: result.Append(value ? "Open" : "Closed"); break; default: result.Append(value); break; } } var timestamp = state.TimeStamp; if (timestamp != null) { result.Append(" (at "); result.AppendDateTime(state.TimeStamp, timeZone); result.Append(")"); } return(result.ToString()); }
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; }
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; }
public static XElement ToXElement(this IBinarySensorState state, string nodeName = "BinarySensor") { var result = new XElement(nodeName); if (state.Type != null) { result.Add(new XAttribute("Type", state.Type)); } if (state.Value != null) { result.Add(new XAttribute("Value", state.Value)); } if (state.TimeStamp != null) { result.Add(new XAttribute("TimeStamp", state.TimeStamp)); } 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 void Update(IBinarySensorState state) { Type = state.Type; Value = state.Value; TimeStamp = state.TimeStamp; }
public static IBinarySensorState Copy(this IBinarySensorState state) { return(ReadOnlyBinarySensorState.CopyFrom(state)); }