From: <Ba...@us...> - 2012-01-25 23:00:25
|
Revision: 4425 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4425&view=rev Author: BartEv Date: 2012-01-25 23:00:16 +0000 (Wed, 25 Jan 2012) Log Message: ----------- First stable release Modified Paths: -------------- trunk/plugins/VeraControl/DeviceCam.cs trunk/plugins/VeraControl/DeviceSprinkler.cs trunk/plugins/VeraControl/DeviceSystem.cs trunk/plugins/VeraControl/DialogDeviceControl.cs trunk/plugins/VeraControl/DialogSceneControl.cs trunk/plugins/VeraControl/Scene.cs trunk/plugins/VeraControl/VeraCommunication.cs trunk/plugins/VeraControl/VeraControl.cs trunk/plugins/VeraControl/VeraControl.csproj trunk/plugins/VeraControl/VeraHelper.cs trunk/plugins/VeraControl/VeraSetupForm.Designer.cs trunk/plugins/VeraControl/VeraSetupForm.cs trunk/plugins/VeraControl/releases/VeraControl.xmp2 trunk/plugins/VeraControl/releases/update.xml trunk/plugins/VeraControl/skin/Default/VeraControl.xml trunk/plugins/VeraControl/skin/Default/VeraDialogDeviceControl.xml trunk/plugins/VeraControl/skin/Default/VeraDialogSceneControl.xml trunk/plugins/VeraControl/skin/DefaultWide/VeraControl.xml trunk/plugins/VeraControl/skin/DefaultWide/VeraDialogDeviceControl.xml trunk/plugins/VeraControl/skin/DefaultWide/VeraDialogSceneControl.xml trunk/plugins/VeraControl/skin/Media/Vera/Binary_Light_0.png trunk/plugins/VeraControl/skin/Media/Vera/Binary_Light_100.png trunk/plugins/VeraControl/skin/Media/Vera/Dimmable_Light_0.png trunk/plugins/VeraControl/skin/Media/Vera/Dimmable_Light_100.png trunk/plugins/VeraControl/skin/Media/Vera/Dimmable_Light_25.png trunk/plugins/VeraControl/skin/Media/Vera/Dimmable_Light_50.png trunk/plugins/VeraControl/skin/Media/Vera/Dimmable_Light_75.png trunk/plugins/VeraControl/skin/Media/Vera/Door_Lock.png trunk/plugins/VeraControl/skin/Media/Vera/Door_Lock_0.png trunk/plugins/VeraControl/skin/Media/Vera/Door_Lock_100.png trunk/plugins/VeraControl/skin/Media/Vera/Generic_IO.png trunk/plugins/VeraControl/skin/Media/Vera/Humidity_Sensor.png trunk/plugins/VeraControl/skin/Media/Vera/IR_Transmitter.png trunk/plugins/VeraControl/skin/Media/Vera/Ip_Camera.png trunk/plugins/VeraControl/skin/Media/Vera/Light_Sensor.png trunk/plugins/VeraControl/skin/Media/Vera/Motion_Sensor_0.png trunk/plugins/VeraControl/skin/Media/Vera/Motion_Sensor_100.png trunk/plugins/VeraControl/skin/Media/Vera/Power_Meter.png trunk/plugins/VeraControl/skin/Media/Vera/Scenes.png trunk/plugins/VeraControl/skin/Media/Vera/Temperature_Sensor.png trunk/plugins/VeraControl/skin/Media/Vera/Thermostat.png trunk/plugins/VeraControl/skin/Media/Vera/USB_UIRT.png trunk/plugins/VeraControl/skin/Media/Vera/default_panel.png trunk/plugins/VeraControl/skin/Media/Vera/energy.png trunk/plugins/VeraControl/skin/Media/Vera/findvera.png trunk/plugins/VeraControl/skin/Media/Vera/generic_sensor.png trunk/plugins/VeraControl/skin/Media/Vera/location.png trunk/plugins/VeraControl/skin/Media/Vera/music_audio.png trunk/plugins/VeraControl/skin/Media/Vera/plugins.png trunk/plugins/VeraControl/skin/Media/Vera/users.png Added Paths: ----------- trunk/plugins/VeraControl/JSON.cs trunk/plugins/VeraControl/releases/VeraControl_v0.9.0.1.mpe1 trunk/plugins/VeraControl/skin/Media/Vera/OpenList.png trunk/plugins/VeraControl/skin/Media/Vera/Scenes_active.png trunk/plugins/VeraControl/skin/Media/Vera/Sprinkler.png trunk/plugins/VeraControl/skin/Media/Vera/state_command_error.png trunk/plugins/VeraControl/skin/Media/Vera/state_connection_error.png trunk/plugins/VeraControl/skin/Media/Vera/state_error.png trunk/plugins/VeraControl/skin/Media/Vera/state_pending.png trunk/plugins/VeraControl/skin/Media/Vera/state_success.png Modified: trunk/plugins/VeraControl/DeviceCam.cs =================================================================== --- trunk/plugins/VeraControl/DeviceCam.cs 2012-01-23 23:04:46 UTC (rev 4424) +++ trunk/plugins/VeraControl/DeviceCam.cs 2012-01-25 23:00:16 UTC (rev 4425) @@ -58,7 +58,7 @@ public string imgUrl { - get { return "http://" + passString + _vera.veraAddress + "/data_request?id=cam_image¶meters=get_video_frame&Device_Num=" + id + "&rand=" + DateTime.Now.Ticks; + get { return _vera.veraAddress + "/data_request?id=cam_image¶meters=get_video_frame&Device_Num=" + id + "&rand=" + DateTime.Now.Ticks; // return "http://" + passString + m_sIp + "/" + m_sUrl.Replace("%2F", "/"); } set { } Modified: trunk/plugins/VeraControl/DeviceSprinkler.cs =================================================================== --- trunk/plugins/VeraControl/DeviceSprinkler.cs 2012-01-23 23:04:46 UTC (rev 4424) +++ trunk/plugins/VeraControl/DeviceSprinkler.cs 2012-01-25 23:00:16 UTC (rev 4425) @@ -100,7 +100,7 @@ public override string GetIconName() { - return "Humidity_Sensor"; + return "Sprinkler"; } public override string GetStatusText() Modified: trunk/plugins/VeraControl/DeviceSystem.cs =================================================================== --- trunk/plugins/VeraControl/DeviceSystem.cs 2012-01-23 23:04:46 UTC (rev 4424) +++ trunk/plugins/VeraControl/DeviceSystem.cs 2012-01-25 23:00:16 UTC (rev 4425) @@ -21,30 +21,30 @@ { } - public VeraHelper _helper = VeraHelper.Instance; + public VeraHelper _helper = VeraHelper.Instance; - public long _lastUpdate = 0; + public long _lastUpdate = 0; public bool _screenUpdateRequired = false; - private bool _fullReload = true; - private string _version = ""; - private string _model = ""; - private bool _zWaveHeal = false; - private bool _metric = true; - private string _serial = ""; - private string _fwd1Server = ""; - private string _fwd2Server = ""; - private string _loadTime = "0"; - private string _dataVersion = "0"; - private string _comment = ""; - private DevState _dsVeraState = DevState.NONE; + private bool _fullReload = true; + private string _version = ""; + private string _model = ""; + private bool _zWaveHeal = false; + private bool _metric = true; + private string _serial = ""; + private string _fwd1Server = ""; + private string _fwd2Server = ""; + private string _loadTime = "0"; + private string _dataVersion = "0"; + private string _comment = ""; + private DevState _dsVeraState = DevState.NONE; public bool update(XmlNode xn) { _fullReload = _helper.GetAttrAsBool (xn, "full", _fullReload); _version = _helper.GetAttrAsString (xn, "version", _version); - _model = _helper.GetAttrAsString (xn, "model", _model); - _zWaveHeal = _helper.GetAttrAsBool (xn, "zwave_heal", _zWaveHeal); + _model = _helper.GetAttrAsString (xn, "model", _model); + _zWaveHeal = _helper.GetAttrAsBool (xn, "zwave_heal", _zWaveHeal); _serial = _helper.GetAttrAsString (xn, "serial_number", _serial); _fwd1Server = _helper.GetAttrAsString (xn, "fwd1", _fwd1Server); _fwd2Server = _helper.GetAttrAsString (xn, "fwd2", _fwd2Server); Modified: trunk/plugins/VeraControl/DialogDeviceControl.cs =================================================================== --- trunk/plugins/VeraControl/DialogDeviceControl.cs 2012-01-23 23:04:46 UTC (rev 4424) +++ trunk/plugins/VeraControl/DialogDeviceControl.cs 2012-01-25 23:00:16 UTC (rev 4425) @@ -254,7 +254,7 @@ { _myDev.level = _desiredLevel; _slider.IntValue = _desiredLevel; - _lastLevelUpdate = DateTime.Now.Ticks + (TimeSpan.TicksPerSecond * 2); + _lastLevelUpdate = DateTime.Now.Ticks + (TimeSpan.TicksPerSecond * 2); } _levelUpdatePending = false; } Modified: trunk/plugins/VeraControl/DialogSceneControl.cs =================================================================== --- trunk/plugins/VeraControl/DialogSceneControl.cs 2012-01-23 23:04:46 UTC (rev 4424) +++ trunk/plugins/VeraControl/DialogSceneControl.cs 2012-01-25 23:00:16 UTC (rev 4425) @@ -69,6 +69,11 @@ _label1.Label = _myScene.name; + _imgLogo.Dispose(); + _imgLogo.SetFileName(@"Vera\" + _myScene.GetIconName() + ".png"); + _imgLogo.AllocResources(); + _imgLogo.KeepAspectRatio = true; + // save last update ticks _lastUpdate = DateTime.Now.Ticks; } Added: trunk/plugins/VeraControl/JSON.cs =================================================================== --- trunk/plugins/VeraControl/JSON.cs (rev 0) +++ trunk/plugins/VeraControl/JSON.cs 2012-01-25 23:00:16 UTC (rev 4425) @@ -0,0 +1,497 @@ +using System; +using System.Collections; +using System.Globalization; +using System.Text; + +namespace VeraControl.Properties +{ + /// <summary> + /// This class encodes and decodes JSON strings. + /// Spec. details, see http://www.json.org/ + /// + /// JSON uses Arrays and Objects. These correspond here to the datatypes ArrayList and Hashtable. + /// All numbers are parsed to doubles. + /// </summary> + public class JSON + { + public const int TOKEN_NONE = 0; + public const int TOKEN_CURLY_OPEN = 1; + public const int TOKEN_CURLY_CLOSE = 2; + public const int TOKEN_SQUARED_OPEN = 3; + public const int TOKEN_SQUARED_CLOSE = 4; + public const int TOKEN_COLON = 5; + public const int TOKEN_COMMA = 6; + public const int TOKEN_STRING = 7; + public const int TOKEN_NUMBER = 8; + public const int TOKEN_TRUE = 9; + public const int TOKEN_FALSE = 10; + public const int TOKEN_NULL = 11; + + private const int BUILDER_CAPACITY = 2000; + + /// <summary> + /// Parses the string json into a value + /// </summary> + /// <param name="json">A JSON string.</param> + /// <returns>An ArrayList, a Hashtable, a double, a string, null, true, or false</returns> + public static object JsonDecode(string json) + { + bool success = true; + + return JsonDecode(json, ref success); + } + + /// <summary> + /// Parses the string json into a value; and fills 'success' with the successfullness of the parse. + /// </summary> + /// <param name="json">A JSON string.</param> + /// <param name="success">Successful parse?</param> + /// <returns>An ArrayList, a Hashtable, a double, a string, null, true, or false</returns> + public static object JsonDecode(string json, ref bool success) + { + success = true; + if (json != null) { + char[] charArray = json.ToCharArray(); + int index = 0; + object value = ParseValue(charArray, ref index, ref success); + return value; + } else { + return null; + } + } + + /// <summary> + /// Converts a Hashtable / ArrayList object into a JSON string + /// </summary> + /// <param name="json">A Hashtable / ArrayList</param> + /// <returns>A JSON encoded string, or null if object 'json' is not serializable</returns> + public static string JsonEncode(object json) + { + StringBuilder builder = new StringBuilder(BUILDER_CAPACITY); + bool success = SerializeValue(json, builder); + return (success ? builder.ToString() : null); + } + + protected static Hashtable ParseObject(char[] json, ref int index, ref bool success) + { + Hashtable table = new Hashtable(); + int token; + + // { + NextToken(json, ref index); + + bool done = false; + while (!done) { + token = LookAhead(json, index); + if (token == JSON.TOKEN_NONE) { + success = false; + return null; + } else if (token == JSON.TOKEN_COMMA) { + NextToken(json, ref index); + } else if (token == JSON.TOKEN_CURLY_CLOSE) { + NextToken(json, ref index); + return table; + } else { + + // name + string name = ParseString(json, ref index, ref success); + if (!success) { + success = false; + return null; + } + + // : + token = NextToken(json, ref index); + if (token != JSON.TOKEN_COLON) { + success = false; + return null; + } + + // value + object value = ParseValue(json, ref index, ref success); + if (!success) { + success = false; + return null; + } + + table[name] = value; + } + } + + return table; + } + + protected static ArrayList ParseArray(char[] json, ref int index, ref bool success) + { + ArrayList array = new ArrayList(); + + // [ + NextToken(json, ref index); + + bool done = false; + while (!done) { + int token = LookAhead(json, index); + if (token == JSON.TOKEN_NONE) { + success = false; + return null; + } else if (token == JSON.TOKEN_COMMA) { + NextToken(json, ref index); + } else if (token == JSON.TOKEN_SQUARED_CLOSE) { + NextToken(json, ref index); + break; + } else { + object value = ParseValue(json, ref index, ref success); + if (!success) { + return null; + } + + array.Add(value); + } + } + + return array; + } + + protected static object ParseValue(char[] json, ref int index, ref bool success) + { + switch (LookAhead(json, index)) { + case JSON.TOKEN_STRING: + return ParseString(json, ref index, ref success); + case JSON.TOKEN_NUMBER: + return ParseNumber(json, ref index, ref success); + case JSON.TOKEN_CURLY_OPEN: + return ParseObject(json, ref index, ref success); + case JSON.TOKEN_SQUARED_OPEN: + return ParseArray(json, ref index, ref success); + case JSON.TOKEN_TRUE: + NextToken(json, ref index); + return true; + case JSON.TOKEN_FALSE: + NextToken(json, ref index); + return false; + case JSON.TOKEN_NULL: + NextToken(json, ref index); + return null; + case JSON.TOKEN_NONE: + break; + } + + success = false; + return null; + } + + protected static string ParseString(char[] json, ref int index, ref bool success) + { + StringBuilder s = new StringBuilder(BUILDER_CAPACITY); + char c; + + EatWhitespace(json, ref index); + + // " + c = json[index++]; + + bool complete = false; + while (!complete) { + + if (index == json.Length) { + break; + } + + c = json[index++]; + if (c == '"') { + complete = true; + break; + } else if (c == '\\') { + + if (index == json.Length) { + break; + } + c = json[index++]; + if (c == '"') { + s.Append('"'); + } else if (c == '\\') { + s.Append('\\'); + } else if (c == '/') { + s.Append('/'); + } else if (c == 'b') { + s.Append('\b'); + } else if (c == 'f') { + s.Append('\f'); + } else if (c == 'n') { + s.Append('\n'); + } else if (c == 'r') { + s.Append('\r'); + } else if (c == 't') { + s.Append('\t'); + } else if (c == 'u') { + int remainingLength = json.Length - index; + if (remainingLength >= 4) { + // parse the 32 bit hex into an integer codepoint + uint codePoint; + if (!(success = UInt32.TryParse(new string(json, index, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out codePoint))) { + return ""; + } + // convert the integer codepoint to a unicode char and add to string + s.Append(Char.ConvertFromUtf32((int)codePoint)); + // skip 4 chars + index += 4; + } else { + break; + } + } + + } else { + s.Append(c); + } + + } + + if (!complete) { + success = false; + return null; + } + + return s.ToString(); + } + + protected static double ParseNumber(char[] json, ref int index, ref bool success) + { + EatWhitespace(json, ref index); + + int lastIndex = GetLastIndexOfNumber(json, index); + int charLength = (lastIndex - index) + 1; + + double number; + success = Double.TryParse(new string(json, index, charLength), NumberStyles.Any, CultureInfo.InvariantCulture, out number); + + index = lastIndex + 1; + return number; + } + + protected static int GetLastIndexOfNumber(char[] json, int index) + { + int lastIndex; + + for (lastIndex = index; lastIndex < json.Length; lastIndex++) { + if ("0123456789+-.eE".IndexOf(json[lastIndex]) == -1) { + break; + } + } + return lastIndex - 1; + } + + protected static void EatWhitespace(char[] json, ref int index) + { + for (; index < json.Length; index++) { + if (" \t\n\r".IndexOf(json[index]) == -1) { + break; + } + } + } + + protected static int LookAhead(char[] json, int index) + { + int saveIndex = index; + return NextToken(json, ref saveIndex); + } + + protected static int NextToken(char[] json, ref int index) + { + EatWhitespace(json, ref index); + + if (index == json.Length) { + return JSON.TOKEN_NONE; + } + + char c = json[index]; + index++; + switch (c) { + case '{': + return JSON.TOKEN_CURLY_OPEN; + case '}': + return JSON.TOKEN_CURLY_CLOSE; + case '[': + return JSON.TOKEN_SQUARED_OPEN; + case ']': + return JSON.TOKEN_SQUARED_CLOSE; + case ',': + return JSON.TOKEN_COMMA; + case '"': + return JSON.TOKEN_STRING; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case '-': + return JSON.TOKEN_NUMBER; + case ':': + return JSON.TOKEN_COLON; + } + index--; + + int remainingLength = json.Length - index; + + // false + if (remainingLength >= 5) { + if (json[index] == 'f' && + json[index + 1] == 'a' && + json[index + 2] == 'l' && + json[index + 3] == 's' && + json[index + 4] == 'e') { + index += 5; + return JSON.TOKEN_FALSE; + } + } + + // true + if (remainingLength >= 4) { + if (json[index] == 't' && + json[index + 1] == 'r' && + json[index + 2] == 'u' && + json[index + 3] == 'e') { + index += 4; + return JSON.TOKEN_TRUE; + } + } + + // null + if (remainingLength >= 4) { + if (json[index] == 'n' && + json[index + 1] == 'u' && + json[index + 2] == 'l' && + json[index + 3] == 'l') { + index += 4; + return JSON.TOKEN_NULL; + } + } + + return JSON.TOKEN_NONE; + } + + protected static bool SerializeValue(object value, StringBuilder builder) + { + bool success = true; + + if (value is string) { + success = SerializeString((string)value, builder); + } else if (value is Hashtable) { + success = SerializeObject((Hashtable)value, builder); + } else if (value is ArrayList) { + success = SerializeArray((ArrayList)value, builder); + } else if (IsNumeric(value)) { + success = SerializeNumber(Convert.ToDouble(value), builder); + } else if ((value is Boolean) && ((Boolean)value == true)) { + builder.Append("true"); + } else if ((value is Boolean) && ((Boolean)value == false)) { + builder.Append("false"); + } else if (value == null) { + builder.Append("null"); + } else { + success = false; + } + return success; + } + + protected static bool SerializeObject(Hashtable anObject, StringBuilder builder) + { + builder.Append("{"); + + IDictionaryEnumerator e = anObject.GetEnumerator(); + bool first = true; + while (e.MoveNext()) { + string key = e.Key.ToString(); + object value = e.Value; + + if (!first) { + builder.Append(", "); + } + + SerializeString(key, builder); + builder.Append(":"); + if (!SerializeValue(value, builder)) { + return false; + } + + first = false; + } + + builder.Append("}"); + return true; + } + + protected static bool SerializeArray(ArrayList anArray, StringBuilder builder) + { + builder.Append("["); + + bool first = true; + for (int i = 0; i < anArray.Count; i++) { + object value = anArray[i]; + + if (!first) { + builder.Append(", "); + } + + if (!SerializeValue(value, builder)) { + return false; + } + + first = false; + } + + builder.Append("]"); + return true; + } + + protected static bool SerializeString(string aString, StringBuilder builder) + { + builder.Append("\""); + + char[] charArray = aString.ToCharArray(); + for (int i = 0; i < charArray.Length; i++) { + char c = charArray[i]; + if (c == '"') { + builder.Append("\\\""); + } else if (c == '\\') { + builder.Append("\\\\"); + } else if (c == '\b') { + builder.Append("\\b"); + } else if (c == '\f') { + builder.Append("\\f"); + } else if (c == '\n') { + builder.Append("\\n"); + } else if (c == '\r') { + builder.Append("\\r"); + } else if (c == '\t') { + builder.Append("\\t"); + } else { + int codepoint = Convert.ToInt32(c); + if ((codepoint >= 32) && (codepoint <= 126)) { + builder.Append(c); + } else { + builder.Append("\\u" + Convert.ToString(codepoint, 16).PadLeft(4, '0')); + } + } + } + + builder.Append("\""); + return true; + } + + protected static bool SerializeNumber(double number, StringBuilder builder) + { + builder.Append(Convert.ToString(number, CultureInfo.InvariantCulture)); + return true; + } + + /// <summary> + /// Determines if a given object is numeric in any way + /// (can be integer, double, null, etc). + /// + /// Thanks to mtighe for pointing out Double.TryParse to me. + /// </summary> + protected static bool IsNumeric(object o) + { + double result; + + return (o == null) ? false : Double.TryParse(o.ToString(), out result); + } + } +} Modified: trunk/plugins/VeraControl/Scene.cs =================================================================== --- trunk/plugins/VeraControl/Scene.cs 2012-01-23 23:04:46 UTC (rev 4424) +++ trunk/plugins/VeraControl/Scene.cs 2012-01-25 23:00:16 UTC (rev 4425) @@ -44,7 +44,7 @@ public override string GetIconName() { - return "Scenes"; + return "Scenes" + (IsActive() ? "_active":""); } public override string GetStatusText() Modified: trunk/plugins/VeraControl/VeraCommunication.cs =================================================================== --- trunk/plugins/VeraControl/VeraCommunication.cs 2012-01-23 23:04:46 UTC (rev 4424) +++ trunk/plugins/VeraControl/VeraCommunication.cs 2012-01-25 23:00:16 UTC (rev 4425) @@ -17,650 +17,684 @@ namespace VeraControl.Properties { - /// <summary> - /// Description of VeraCommunication. - /// </summary> - - public class VeraStatus - { - public DeviceSystem system = new DeviceSystem(); - public List<DeviceGeneric> devices = new List<DeviceGeneric>(); - public List<Scene> scenes = new List<Scene>(); - public List<Room> rooms = new List<Room>(); - public List<DevCategories> categories = new List<DevCategories>(); - public List<Section> sections = new List<Section>(); - - #region Vers get by id support functions + /// <summary> + /// Description of VeraCommunication. + /// </summary> + + public class VeraStatus + { + public DeviceSystem system = new DeviceSystem(); + public List<DeviceGeneric> devices = new List<DeviceGeneric>(); + public List<Scene> scenes = new List<Scene>(); + public List<Room> rooms = new List<Room>(); + public List<DevCategories> categories = new List<DevCategories>(); + public List<Section> sections = new List<Section>(); + + #region Vers get by id support functions - public void ClearAllLists() - { - devices.Clear(); - scenes.Clear(); - rooms.Clear(); - categories.Clear(); - sections.Clear(); - } - public Room GetRoomById(int id) - { - foreach(Room room in rooms) - { - if (room.id == id) - { - return room; - } - } - return new Room(null); - } - - public Section GetSectionById(int id) - { - foreach(Section section in sections) - { - if (section.id == id) - { - return section; - } - } - return new Section(null); - } - - public DeviceGeneric GetDeviceById(int id) - { - foreach(DeviceGeneric dev in devices) - { - if (dev.id == id) - { - return dev; - } - } - return new DeviceGeneric(null); - } + public void ClearAllLists() + { + devices.Clear(); + scenes.Clear(); + rooms.Clear(); + categories.Clear(); + sections.Clear(); + } + public Room GetRoomById(int id) + { + foreach(Room room in rooms) + { + if (room.id == id) + { + return room; + } + } + return new Room(null); + } + + public Section GetSectionById(int id) + { + foreach(Section section in sections) + { + if (section.id == id) + { + return section; + } + } + return new Section(null); + } + + public DeviceGeneric GetDeviceById(int id) + { + foreach(DeviceGeneric dev in devices) + { + if (dev.id == id) + { + return dev; + } + } + return new DeviceGeneric(null); + } - public Scene GetSceneById(int id) - { - foreach(Scene scene in scenes) - { - if (scene.id == id) - { - return scene; - } - } - return new Scene(null); - } - - public DevCategories GetCategoryById(int id) - { - foreach(DevCategories cat in categories) - { - if (cat.id == id) - { - return cat; - } - } - return new DevCategories(null); - } - - public bool IsSectionFound(int id) - { - foreach(Section section in sections) - { - if (section.id == id) - { - return true; - } - } - return false; - } - - public bool IsRoomFound(int id) - { - foreach(Room room in rooms) - { - if (room.id == id) - { - return true; - } - } - return false; - } - - public bool IsDeviceFound(int id) - { - foreach(DeviceGeneric dev in devices) - { - if (dev.id == id) - { - return true; - } - } - return false; - } + public Scene GetSceneById(int id) + { + foreach(Scene scene in scenes) + { + if (scene.id == id) + { + return scene; + } + } + return new Scene(null); + } + + public DevCategories GetCategoryById(int id) + { + foreach(DevCategories cat in categories) + { + if (cat.id == id) + { + return cat; + } + } + return new DevCategories(null); + } + + public bool IsSectionFound(int id) + { + foreach(Section section in sections) + { + if (section.id == id) + { + return true; + } + } + return false; + } + + public bool IsRoomFound(int id) + { + foreach(Room room in rooms) + { + if (room.id == id) + { + return true; + } + } + return false; + } + + public bool IsDeviceFound(int id) + { + foreach(DeviceGeneric dev in devices) + { + if (dev.id == id) + { + return true; + } + } + return false; + } - public bool IsSceneFound(int id) - { - foreach(Scene scene in scenes) - { - if (scene.id == id) - { - return true; - } - } - return false; - } - - public bool IsCategoryFound(int id) - { - foreach(DevCategories cat in categories) - { - if (cat.id == id) - { - return true; - } - } - return false; - } - #endregion - } - - - public sealed class VeraCommunication - { - private static volatile VeraCommunication _instance; - private static object _syncRoot = new Object(); - private VeraHelper _helper = VeraHelper.Instance; - - // Config data - private string _veraIPAddress; - private string _veraTCPIPPort; - private int _maxRefreshDelay; // Maximun delay between 2 status updates in seconds - private int _minRefreshDelay = 1000; // Minimun delay between 2 status updates in miliseconds - - // Actual device information - private VeraStatus _status = new VeraStatus(); - - // Communication status/control - private long _lastUpdate = 0; - private bool _screenUpdateRequired = false; // Only true when a new update was received AND at least one device(staus) or scene was changed - private bool _lastUpdateFailed = false; - private string _lastUpdateErrorMessage = ""; - private WebClient _webUpdateClient = new WebClient(); - private WebClient _webCommandClient = new WebClient(); - private Action<string> _webCommandClientErrorReporter = null; - - // Action control table - public int [] actionTriggerTable = new int[(int)Actiontrigger.LAST_ACTIONTRIGGER]; - - public static VeraCommunication Instance - { - get - { - if (_instance == null) - { - lock (_syncRoot) - { - if (_instance == null) - { - _instance = new VeraCommunication(); - } - } - } + public bool IsSceneFound(int id) + { + foreach(Scene scene in scenes) + { + if (scene.id == id) + { + return true; + } + } + return false; + } + + public bool IsCategoryFound(int id) + { + foreach(DevCategories cat in categories) + { + if (cat.id == id) + { + return true; + } + } + return false; + } + #endregion + } + + + public sealed class VeraCommunication + { + private static volatile VeraCommunication _instance; + private static object _syncRoot = new Object(); + private VeraHelper _helper = VeraHelper.Instance; + + // Config data + private int _maxRefreshDelay; // Maximun delay between 2 status updates in seconds + private int _minRefreshDelay = 1000; // Minimun delay between 2 status updates in miliseconds + + // Actual device information + private VeraStatus _status = new VeraStatus(); + + // Communication status/control + private long _lastUpdate = 0; + private bool _screenUpdateRequired = false; // Only true when a new update was received AND at least one device(staus) or scene was changed + private bool _lastUpdateFailed = false; + private string _lastUpdateErrorMessage = ""; + private WebClient _webUpdateClient = new WebClient(); + private WebClient _webCommandClient = new WebClient(); + private Action<string> _webCommandClientErrorReporter = null; + + // Action control table + public int [] actionTriggerTable = new int[(int)Actiontrigger.LAST_ACTIONTRIGGER]; + + public static VeraCommunication Instance + { + get + { + if (_instance == null) + { + lock (_syncRoot) + { + if (_instance == null) + { + _instance = new VeraCommunication(); + } + } + } - return _instance; - } - } - - private VeraCommunication() - { - using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) - { - _veraIPAddress = xmlreader.GetValueAsString("veracontroller", "ipaddress", "127.0.0.1"); - _veraTCPIPPort = xmlreader.GetValueAsString("veracontroller", "portnumber", "3480"); - - // Fill action table (config settings) - for (Actiontrigger i = 0; i < Actiontrigger.LAST_ACTIONTRIGGER; i++) - { - actionTriggerTable[(int)i] = xmlreader.GetValueAsInt("veracontroller", i.ToString(), 0); - } - _maxRefreshDelay = int.Parse(xmlreader.GetValueAsString("veracontroller", "maxrefreshdelay", "60")); - - // Set DownloadStringCompleted handler - _webUpdateClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnCompletedUpdateStatusRequest); - _webCommandClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnCompletedCommandRequest); - } - } - - public bool IsVeraAlive(string ip, string port) - { - string response = RetrieveURL("http://" + ip + ":" + port + "/data_request?id=lu_alive&time=" + DateTime.Now.Ticks); - return (response == "OK"); - } + return _instance; + } + } + + private VeraCommunication() + { + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) + { + // Fill action table (config settings) + for (Actiontrigger i = 0; i < Actiontrigger.LAST_ACTIONTRIGGER; i++) + { + actionTriggerTable[(int)i] = xmlreader.GetValueAsInt("veracontroller", i.ToString(), 0); + } + _maxRefreshDelay = int.Parse(xmlreader.GetValueAsString("veracontroller", "maxrefreshdelay", "60")); + + // Set DownloadStringCompleted handler + _webUpdateClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnCompletedUpdateStatusRequest); + _webCommandClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnCompletedCommandRequest); + } + } + + public bool IsVeraAlive(string ip, string port) + { + string response = RetrieveURL("http://" + ip + ":" + port + "/data_request?id=lu_alive&time=" + DateTime.Now.Ticks); + return (response == "OK"); + } - private string RetrieveURL(string url) - { - // No callback thus Synchronised call (wait for response) - try { - WebClient wc = new WebClient(); - wc.CancelAsync(); // Cancel any current pending Async calls... - return wc.DownloadString(url); - } catch( Exception ) - { - return "ERROR"; - } - } - - public void DoVeraCommandRequest(string param, Action<string> errorReporter) - { - if (_webCommandClient.IsBusy) - { - // TODO: What to do ? cancel pending request or queue new request? - for now just cancel the previous request (user is informed about the progress) - } - string url = "http://" + veraAddress + "/data_request" + param + "&time=" + DateTime.Now.Ticks; - - // Callback thus ASynchronised call (do NOT wait for response) - try { - _webCommandClientErrorReporter = errorReporter; - _webCommandClient.CancelAsync(); // Cancel any current pending Async calls... - _webCommandClient.DownloadStringAsync(new Uri(url)); - - } catch( Exception e ) - { - _webCommandClientErrorReporter = null; - status.system.ReportCommandError(e.Message); - setScreenUpdateRequired(); - } - } - - public void OnCompletedCommandRequest(object sender, DownloadStringCompletedEventArgs e) - { - if (e.Cancelled) - { - // Communication cancel for some reason, no valid data to be expected - if (_webCommandClientErrorReporter != null) - { - // Send error to dialog message handler - _webCommandClientErrorReporter("Request was canceled"); - } - else - { - // Show eror in MediaPortal Vera-main window - status.system.ReportCommandError("Request was canceled"); - } - setScreenUpdateRequired(); - } - else if (e.Error != null) - { - // Handle error here - if (_webCommandClientErrorReporter != null) - { - // Send error to dialog message handler - _webCommandClientErrorReporter(e.Error.Message); - } - else - { - // Show eror in MediaPortal Vera-main window - status.system.ReportCommandError(e.Error.Message); - } - setScreenUpdateRequired(); - } - else - { - // Communication succes full -> no parse Vera response... - if (!e.Result.ToUpper().Contains("<OK>OK</OK>") && !e.Result.ToUpper().Contains("<JOBID>")) - { - if (_webCommandClientErrorReporter != null) - { - // Send error to dialog message handler - _webCommandClientErrorReporter(e.Result); - } - else - { - // Show eror in MediaPortal Vera-main window - status.system.ReportCommandError(e.Result); - } - setScreenUpdateRequired(); - } - } - // Communication done clear error report handler - _webCommandClientErrorReporter = null; - } - - public void UpdateCurrentStatus() - { - /* Keep updating with webClient timeout 180 sec, even when last time did fail or connection was lost....*/ - if (!_webUpdateClient.IsBusy) - { - string url = "http://" + veraAddress + "/data_request" + - "?id=lu_sdata&loadtime=" + _status.system.loadtime + - "&dataversion=" + _status.system.dataversion + - "&minimumdelay=" + _minRefreshDelay + - "&timeout=" + _maxRefreshDelay + - "&output_format=xml" + - "&time=" + DateTime.Now.Ticks; - - // Callback thus ASynchronised call (do NOT wait for response) - try { - _webUpdateClient.CancelAsync(); // Cancel any current pending Async calls... - _webUpdateClient.DownloadStringAsync(new Uri(url)); - } catch( Exception e ) - { - _lastUpdateFailed = true; - _lastUpdateErrorMessage = e.Message; - } - _lastUpdate = _helper.GetSecondsSince1970(); - } - } - - public void OnCompletedUpdateStatusRequest(object sender, DownloadStringCompletedEventArgs e) - { - if (!e.Cancelled) - { - // Communication cancel for some reason, no valid data to be expected - if (e.Error != null) - { - // Handle error here - _lastUpdateFailed = true; - _lastUpdateErrorMessage = e.Error.Message; - setScreenUpdateRequired(); - } - else - { - ParseUpdateInfo(e.Result); - // ParseUpdateInfo(m_webClient.DownloadString(@"C:\Users\Bart\Documents\SharpDevelop Projects\VeraControl\testdata\text.xml")); - } - } - - // update timer again (took some time to get the data) - _lastUpdate = _helper.GetSecondsSince1970(); - } - - public void ParseUpdateInfo(string veraresponse) - { - var xmlDoc = new XmlDocument(); - try { - xmlDoc.LoadXml(veraresponse); - } catch (Exception) - { - // Parser failed so incorrect data received (could be an interrupted data transfer) - return; - } - // Parse header - XmlNode rootnode = xmlDoc.SelectSingleNode("/root"); - if (rootnode == null) - { - // Not a status update, just return - return; - } - - if (!_screenUpdateRequired) - { - // Clear flag, only when previous update was already handled (might be some new or remove devices/scenes to be displayed) - _status.system.ClearFullReloadFlag(); - } - if (_lastUpdateFailed) - { - _lastUpdateFailed = false; - setScreenUpdateRequired(); - _status.system.ClearConnectionError(); - } - // Process system status first - _status.system.update(rootnode); - if (_status.system.fullReload) - { - // We have a full refresh -> Clear all lists (to get clear of removed devices/scenes/catgories/rooms/etc...) - _status.ClearAllLists(); - } - - // Process Sections - XmlNodeList xnList = xmlDoc.SelectNodes("/root/sections/section"); - foreach (XmlNode xn in xnList) - { - Section sc = _status.GetSectionById( int.Parse(xn.Attributes["id"].Value) ); - if (sc.id != 0) { - sc.Update(xn); - } else { - _status.sections.Add(new Section(xn)); - } - } - - // Process Rooms - xnList = xmlDoc.SelectNodes("/root/rooms/room"); - foreach (XmlNode xn in xnList) - { - Room room = _status.GetRoomById( int.Parse(xn.Attributes["id"].Value) ); - if (room.id != 0) { - room.Update(xn); - } else { - _status.rooms.Add(new Room(xn)); - } - } - - // Process Scenes - xnList = xmlDoc.SelectNodes("/root/scenes/scene"); - // State update of Scenes are not reported done, so they have to be cleaned manualy - // if a message is still valid and/or new message will be reported below - foreach (Scene scene in _status.scenes) - { - scene.ClearCommState(); - } - foreach (XmlNode xn in xnList) - { - Scene sc = _status.GetSceneById( int.Parse(xn.Attributes["id"].Value) ); - if (sc.id != 0) { - sc.Update(xn); - } else { - _status.scenes.Add(new Scene(xn)); - } - } - - // Process Categories - xnList = xmlDoc.SelectNodes("/root/categories/categorie"); - foreach (XmlNode xn in xnList) - { - DevCategories cat = _status.GetCategoryById( int.Parse(xn.Attributes["id"].Value) ); - if (cat.id != 0) { - cat.Update(xn); - } else { - _status.categories.Add(new DevCategories(xn)); - } - } - - // Process Devices - xnList = xmlDoc.SelectNodes("/root/devices/device"); - foreach (XmlNode xn in xnList) - { - DeviceGeneric dev = _status.GetDeviceById( int.Parse(xn.Attributes["id"].Value) ); - if (dev.id != 0) { - // update existing device - dev.Update(xn); - } else { - _status.system.SetFullReloadFlag(); - - // catids: http://wiki.micasaverde.com/index.php/Luup_UPNP_Files - switch (xn.Attributes["category"].Value) - { - //case "1": // TODO: Implement interface device ? - // m_status.devices.Add(new DeviceInterface(xn)); - // break; - - case "2": - _status.devices.Add(new DeviceDimmer(xn)); - break; - - case "3": - case "11": // Generic IO - _status.devices.Add(new DeviceSwitch(xn)); - break; - - case "4": // Generic Sensor - case "12": // Motion Sensor - _status.devices.Add(new DeviceSecurity(xn)); - break; - - case "5": - _status.devices.Add(new DeviceThermostat(xn, _status.system.IsMetric())); - break; - - case "6": - _status.devices.Add(new DeviceCam(xn)); - break; - - case "7": - _status.devices.Add(new DeviceDoorlock(xn)); - break; - - case "8": - _status.devices.Add(new DeviceWindowCovering(xn)); - break; - - //case "9": - // m_status.devices.Add(new DeviceRemoteControl(xn)); - // break; - - //case "10": - // m_status.devices.Add(new DeviceIrTx(xn)); - // break; - - //case "13": - // m_status.devices.Add(new DeviceSerialPort(xn)); - // break - - case "14": - _status.devices.Add(new DeviceSceneController(xn)); - break; - - // case "15": - // m_status.devices.Add(new DeviceAV(xn)); - // break; - - case "16": - _status.devices.Add(new DeviceHumidity(xn)); - break; - - case "17": - _status.devices.Add(new DeviceTemperature(xn, _status.system.IsMetric())); - break; - - case "18": - _status.devices.Add(new DeviceLightSensor(xn)); - break; - - //case "19": - // m_status.devices.Add(new DeviceZwaveInt(xn)); - // break - //case "20": - // m_status.devices.Add(new DeviceInsteonInt(xn)); - // break - - case "21": - _status.devices.Add(new DevicePowerMeter(xn)); - break; - - case "0": - default: - // Check for Google Weather Device - if (xn.Attributes["WindCondition"] != null || xn.Attributes["windcondition"] != null) - { - _status.devices.Add(new DeviceGWeather(xn)); - break; - } - // Check for Bart's sprinkler Device - if (xn.Attributes["OperationMode"] != null) - { - _status.devices.Add(new DeviceSprinkler(xn)); - break; - } - /* Falltrough */ - _status.devices.Add(new DeviceGeneric(xn)); - break; - } - } - } - } - - public long SecondsSinceLastUpdate - { - get { return (_helper.GetSecondsSince1970() - _lastUpdate); } - set { } - } + private string RetrieveURL(string url) + { + // No callback thus Synchronised call (wait for response) + try { + WebClient wc = new WebClient(); + wc.CancelAsync(); // Cancel any current pending Async calls... + return wc.DownloadString(url); + } catch( Exception ) + { + return "ERROR"; + } + } + + public void DoVeraCommandRequest(string param, Action<string> errorReporter) + { + if (_webCommandClient.IsBusy) + { + // TODO: What to do ? cancel pending request or queue new request? - for now just cancel the previous request (user is informed about the progress) + } + string url = veraAddress + "/data_request" + param + "&time=" + DateTime.Now.Ticks; + + // Callback thus ASynchronised call (do NOT wait for response) + try { + _webCommandClientErrorReporter = errorReporter; + _webCommandClient.CancelAsync(); // Cancel any current pending Async calls... + _webCommandClient.DownloadStringAsync(new Uri(url)); + + } catch( Exception e ) + { + _webCommandClientErrorReporter = null; + status.system.ReportCommandError(e.Message); + setScreenUpdateRequired(); + } + } + + public void OnCompletedCommandRequest(object sender, DownloadStringCompletedEventArgs e) + { + if (e.Cancelled) + { + // Communication cancel for some reason, no valid data to be expected + if (_webCommandClientErrorReporter != null) + { + // Send error to dialog message handler + _webCommandClientErrorReporter("Request was canceled"); + } + else + { + // Show eror in MediaPortal Vera-main window + status.system.ReportCommandError("Request was canceled"); + } + setScreenUpdateRequired(); + } + else if (e.Error != null) + { + // Handle error here + if (_webCommandClientErrorReporter != null) + { + // Send error to dialog message handler + _webCommandClientErrorReporter(e.Error.Message); + } + else + { + // Show eror in MediaPortal Vera-main window + status.system.ReportCommandError(e.Error.Message); + } + setScreenUpdateRequired(); + } + else + { + // Communication succes full -> no parse Vera response... + if (!e.Result.ToUpper().Contains("<OK>OK</OK>") && !e.Result.ToUpper().Contains("<JOBID>")) + { + if (_webCommandClientErrorReporter != null) + { + // Send error to dialog message handler + _webCommandClientErrorReporter(e.Result); + } + else + { + // Show eror in MediaPortal Vera-main window + status.system.ReportCommandError(e.Result); + } + setScreenUpdateRequired(); + } + } + // Communication done clear error report handler + _webCommandClientErrorReporter = null; + } + + public void UpdateCurrentStatus() + { + /* Keep updating with webClient timeout 180 sec, even when last time did fail or connection was lost....*/ + if (!_webUpdateClient.IsBusy) + { + string url = veraAddress + "/data_request" + + "?id=lu_sdata&loadtime=" + _status.system.loadtime + + "&dataversion=" + _status.system.dataversion + + "&minimumdelay=" + _minRefreshDelay + + "&timeout=" + _maxRefreshDelay + + "&output_format=xml" + + "&time=" + DateTime.Now.Ticks; + + // Callback thus ASynchronised call (do NOT wait for response) + try { + _webUpdateClient.CancelAsync(); // Cancel any current pending Async calls... + _webUpdateClient.DownloadStringAsync(new Uri(url)); + } catch( Exception e ) + { + _lastUpdateFailed = true; + _lastUpdateErrorMessage = e.Message; + } + _lastUpdate = _helper.GetSecondsSince1970(); + } + } + + public void OnCompletedUpdateStatusRequest(object sender, DownloadStringCompletedEventArgs e) + { + if (!e.Cancelled) + { + // Communication cancel for some reason, no valid data to be expected + if (e.Error != null) + { + // Handle error here + _lastUpdateFailed = true; + _lastUpdateErrorMessage = e.Error.Message; + setScreenUpdateRequired(); + } + else + { + ParseUpdateInfo(e.Result); + // WebClient wc = new WebClient(); + // if (_status.system.dataversion == "0") + // { + //ParseUpdateInfo( wc.DownloadString(@"C:\Users\Bart\Documents\SharpDevelop Projects\VeraControl\testdata\text.xml")); + // } + } + } + + // update timer again (took some time to get the data) + _lastUpdate = _helper.GetSecondsSince1970(); + } + + public void ParseUpdateInfo(string veraresponse) + { + var xmlDoc = new XmlDocument(); + try { + xmlDoc.LoadXml(veraresponse); + } catch (Exception) + { + // Parser failed so incorrect data received (could be an interrupted data transfer) + return; + } + // Parse header + XmlNode rootnode = xmlDoc.SelectSingleNode("/root"); + if (rootnode == null) + { + // Not a status update, just return + return; + } + + if (!_screenUpdateRequired) + { + // Clear flag, only when previous update was already handled (might be some new or remove devices/scenes to be displayed) + _status.system.ClearFullReloadFlag(); + } + if (_lastUpdateFailed) + { + _lastUpdateFailed = false; + setScreenUpdateRequired(); + _status.system.ClearConnectionError(); + } + // Process system status first + _status.system.update(rootnode); + if (_status.system.fullReload) + { + // We have a full refresh -> Clear all lists (to get clear of removed devices/scenes/catgories/rooms/etc...) + _status.ClearAllLists(); + } + + // Process Sections + XmlNodeList xnList = xmlDoc.SelectNodes("/root/sections/section"); + foreach (XmlNode xn in xnList) + { + Section sc = _status.GetSectionById( int.Parse(xn.Attributes["id"].Value) ); + if (sc.id != 0) { + sc.Update(xn); + } else { + _status.sections.Add(new Section(xn)); + } + } + + // Process Rooms + xnList = xmlDoc.SelectNodes("/root/rooms/room"); + foreach (XmlNode xn in xnList) + { + Room room = _status.GetRoomById( int.Parse(xn.Attributes["id"].Value) ); + if (room.id != 0) { + room.Update(xn); + } else { + _status.rooms.Add(new Room(xn)); + } + } + + // Process Scenes + xnList = xmlDoc.SelectNodes("/root/scenes/scene"); + // State update of Scenes are not reported done, so they have to be cleaned manualy + // if a message is still valid and/or new message will be reported below + foreach (Scene scene in _status.scenes) + { + scene.ClearCommState(); + } + foreach (XmlNode xn in xnList) + { + Scene sc = _status.GetSceneById( int.Parse(xn.Attributes["id"].Value) ); + if (sc.id != 0) { + sc.Update(xn); + } else { + _status.scenes.Add(new Scene(xn)); + } + } + + // Process Categories + xnList = xmlDoc.SelectNodes("/root/categories/categorie"); + foreach (XmlNode xn in xnList) + { + DevCategories cat = _status.GetCategoryById( int.Parse(xn.Attributes["id"].Value) ); + if (cat.id != 0) { + cat.Update(xn); + } else { + _status.categories.Add(new DevCategories(xn)); + } + } + + // Process Devices + xnList = xmlDoc.SelectNodes("/root/devices/device"); + foreach (XmlNode xn in xnList) + { + DeviceGeneric dev = _status.GetDeviceById( int.Parse(xn.Attributes["id"].Value) ); + if (dev.id != 0) { + // update existing device + dev.Update(xn); + } else { + _status.system.SetFullReloadFlag(); + + // catids: http://wiki.micasaverde.com/index.php/Luup_UPNP_Files + switch (xn.Attributes["category"].Value) + { + //case "1": // TODO: Implement interface device ? + // m_status.devices.Add(new DeviceInterface(xn)); + // break; + + case "2": + _status.devices.Add(new DeviceDimmer(xn)); + break; + + case "3": + case "11": // Generic IO + _status.devices.Add(new DeviceSwitch(xn)); + break; + + case "4": // Generic Sensor + case "12": // Motion Sensor + _status.devices.Add(new DeviceSecurity(xn)); + break; + + case "5": + _status.devices.Add(new DeviceThermostat(xn, _status.system.IsMetric())); + break; + + case "6": + _status.devices.Add(new DeviceCam(xn)); + break; + + case "7": + _status.devices.Add(new DeviceDoorlock(xn)); + break; + + case "8": + _status.devices.Add(new DeviceWindowCovering(xn)); + break; + + //case "9": + // m_status.devices.Add(new DeviceRemoteControl(xn)); + // break; + + //case "10": + // m_status.devices.Add(new DeviceIrTx(xn)); + // break; + + //case "13": + // m_status.devices.Add(new DeviceSerialPort(xn)); + // break + + case "14": + _status.devices.Add(new DeviceSceneController(xn)); + break; + + // case "15": + // m_status.devices.Add(new DeviceAV(xn)); + // break; + + case "16": + _status.devices.Add(new DeviceHumidity(xn)); + break; + + case "17": + _status.devices.Add(new DeviceTemperature(xn, _status.system.IsMetric())); + break; + + case "18": + _status.devices.Add(new DeviceLightSensor(xn)); + break; + + //case "19": + // m_status.devices.Add(new DeviceZwaveInt(xn)); + // break + //case "20": + // m_status.devices.Add(new DeviceInsteonInt(xn)); + // break + + case "21": + _status.devices.Add(new DevicePowerMeter(xn)); + break; + + case "0": + default: + // Check for Google Weather Device + if (xn.Attributes["WindCondition"] != null || xn.Attributes["windcondition"] != null) + { + _status.devices.Add(new DeviceGWeather(xn)); + break; + } + // Check for Bart's sprinkler Device + if (xn.Attributes["OperationMode"] != null) + { + _status.devices.Add(new DeviceSprinkler(xn)); + break; + } + /* Falltrough */ + _status.devices.Add(new DeviceGeneric(xn)); + break; + } + } + } + } + + public long SecondsSinceLastUpdate + { + get { return (_helper.GetSecondsSince1970() - _lastUpdate); } + set { } + } - public List<Scene> scenes - { - get { return _status.scenes; } - set { } - } - - public List<DeviceGeneric> devices - { - get { return _status.devices; } - set { } - } + public List<Scene> scenes + { + get { return _status.scenes; } + set { } + } + + public List<DeviceGeneric> devices + { + get { return _status.devices; } + set { } + } - public List<Room> rooms - { - get { return _status.rooms; } - set { } - } + public List<Room> rooms + { + get { return _status.rooms; } + set { } + } - public List<DevCategories> categories - { - get { return _status.categories; } - set { } - } - - public List<Section> sections - { - get { return _status.sections; } - set { } - } - - public bool lastUpdateFailed - { - get { return _lastUpdateFailed; } - set { _lastUpdateFailed = value; } - } - - public string lastUpdateError - { - get { return _lastUpdateErrorMessage; } - set { } - } - - /// <summary> - /// Invoking this method will clear the update ready flag -> so caller need to handle the screen update - /// </summary> - /// <returns>When true a screen update shall be preformed by the caller</returns> - public bool NewScreenUpdateWaitingAndClearFlag() - { - bool b = _screenUpdateRequired; - _screenUpdateRequired = false; - return b; - } - - public void setScreenUpdateRequired() - { - _screenUpdateRequired = true; - } - /// <summary> - /// A request is currently being handled by Vera, this request takes at least _minRefreshDelay msecs, at most _maxRefreshDelay seconds and will be finished the moment Vera detects a change. - /// As soon as this function returns false a new update request should be invoked (with UpdateCurrentStatus()), Vera will take care of the Refresh delays (by keeping open the http-connection) - /// </summary> - public bool updatePending - { - get { return _webUpdateClient.IsBusy; } - set { } - } - - public VeraStatus status - { - get { return _status; } - set { } - } - - public string veraAddress - { - // TODO: handle FWD server address here, when configured so - get { return _veraIPAddress + ":" +_veraTCPIPPort; } - set { } - } - } + public List<DevCategories> categories + { + get { return _status.categories; } + set { } + } + + public List<Section> sections + { + get { return _status.sections; } + set { } + } + + public bool lastUpdateFailed + { + get { return _lastUpdateFailed; } + set { _lastUpdateFailed = value; } + } + + public string lastUpdateError + { + get { return _lastUpdateErrorMessage; } + set { } + } + + /// <summary> + /// Invoking this method will clear the update ready flag -> so caller need to handle the screen update + /// </summary> + /// <returns>When true a screen update shall be preformed by the caller</returns> + public bool NewScreenUpdateWaitingAndClearFlag() + { + bool b = _screenUpdateRequired; + _screenUpdateRequired = false; + return b; + } + + public void setScreenUpdateRequired() + { + _screenUpdateRequired = true; + } + /// <summary> + /// A request is currently being handled by Vera, this request takes at least _minRefreshDelay msecs, at most _maxRefreshDelay seconds and will be finished the moment Vera detects a change. + /// As soon as this function returns false a new update request should be invoked (with UpdateCurrentStatus()), Vera will take care of the Refresh delays (by keeping open the http-connection) + /// </summary> + public bool updatePending + { + get { return _webUpdateClient.IsBusy; } + set { } + } + + public VeraStatus status + { + get { return _status; } + set { } + } + + public string discreteVeraAddress + { + get { + if (_discreteVeraAddress == null) + { // Accessing this variable will set the discrete value aswell + string dum = veraAddress; + } + return _discreteVeraAddress; + } + } + private string _discreteVeraAddress = null; + + public string veraAddress + { + get { + if (_realVeraAddress == null) + { + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) + { + if (xmlreader.GetValueAsBool("veracontroller", "remoteConnected", false)) + { + string user = xmlreader.GetValueAsString("veracontroller", "miosusername", ""); + string pass = xmlreader.GetValueAsString("veracontroller", "miospassword", ... [truncated message content] |