From: <Ba...@us...> - 2012-01-05 12:17:33
|
Revision: 4373 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4373&view=rev Author: BartEv Date: 2012-01-05 12:17:24 +0000 (Thu, 05 Jan 2012) Log Message: ----------- Added Paths: ----------- trunk/plugins/VeraControl/ trunk/plugins/VeraControl/DevCategories.cs trunk/plugins/VeraControl/DeviceDimmer.cs trunk/plugins/VeraControl/DeviceDoorlock.cs trunk/plugins/VeraControl/DeviceGWeather.cs trunk/plugins/VeraControl/DeviceGeneric.cs trunk/plugins/VeraControl/DeviceHumidity.cs trunk/plugins/VeraControl/DeviceLightSensor.cs trunk/plugins/VeraControl/DevicePowerMeter.cs trunk/plugins/VeraControl/DeviceSecurity.cs trunk/plugins/VeraControl/DeviceSprinkler.cs trunk/plugins/VeraControl/DeviceSwitch.cs trunk/plugins/VeraControl/DeviceTemperature.cs trunk/plugins/VeraControl/DeviceThermostat.cs trunk/plugins/VeraControl/DeviceWindowCovering.cs trunk/plugins/VeraControl/DialogActionTrigger.cs trunk/plugins/VeraControl/DialogDeviceControl.cs trunk/plugins/VeraControl/Properties/ trunk/plugins/VeraControl/Properties/AssemblyInfo.cs trunk/plugins/VeraControl/Room.cs trunk/plugins/VeraControl/Scene.cs trunk/plugins/VeraControl/Section.cs trunk/plugins/VeraControl/VeraCommunication.cs trunk/plugins/VeraControl/VeraControl.cs trunk/plugins/VeraControl/VeraControl.csproj trunk/plugins/VeraControl/VeraSetupForm.Designer.cs trunk/plugins/VeraControl/VeraSetupForm.cs trunk/plugins/VeraControl/VeraSetupForm.resx trunk/plugins/VeraControl/skin/ trunk/plugins/VeraControl/skin/Default/ trunk/plugins/VeraControl/skin/Default/VeraControl.xml trunk/plugins/VeraControl/skin/Default/VeraDialogActionTrigger.xml trunk/plugins/VeraControl/skin/Default/VeraDialogDeviceControl.xml trunk/plugins/VeraControl/skin/DefaultWide/ trunk/plugins/VeraControl/skin/DefaultWide/VeraControl.xml trunk/plugins/VeraControl/skin/DefaultWide/VeraDialogActionTrigger.xml trunk/plugins/VeraControl/skin/DefaultWide/VeraDialogDeviceControl.xml trunk/plugins/VeraControl/skin/Media/ trunk/plugins/VeraControl/skin/Media/Vera/ 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/Insteon.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/Window_Covering.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 Added: trunk/plugins/VeraControl/DevCategories.cs =================================================================== --- trunk/plugins/VeraControl/DevCategories.cs (rev 0) +++ trunk/plugins/VeraControl/DevCategories.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,58 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 22-12-2011 + * Time: 14:14 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DevCategories. + /// </summary> + public class DevCategories + { + public DevCategories(XmlNode xn) + { + if (xn == null) { + m_sName = ""; + m_iId = 0; + } else { + update(xn); + } + } + + private string m_sName; + private int m_iId; + + public bool update(XmlNode xn) + { + m_sName = xn.Attributes["name"].Value; + m_iId = int.Parse(xn.Attributes["id"].Value); + return true; + } + + public int id + { + get { return m_iId; } + set { } + } + + public string name + { + get { return m_sName; } + set { } + } + + public override string ToString() + { + return name; + } + } +} Added: trunk/plugins/VeraControl/DeviceDimmer.cs =================================================================== --- trunk/plugins/VeraControl/DeviceDimmer.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceDimmer.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,108 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 22-12-2011 + * Time: 17:36 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceDimmer. + /// </summary> + public class DeviceDimmer : DeviceGeneric + { + private int m_iLevel; + private string m_sWatt; + + public DeviceDimmer( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_iLevel = (xn.Attributes["level"] != null ? int.Parse(xn.Attributes["level"].Value) : 0); + m_sWatt = (xn.Attributes["watts"] != null ? xn.Attributes["watts"].Value : "0"); + + return base.update(xn); + } + + public string watts + { + get { return m_sWatt; } + set { } + } + + public override bool state + { + get { return (m_iLevel > 0); } + set { + + } + } + + public override int level + { + get { return m_iLevel; } + set + { + int newValue = value; + if (newValue > 100) { + newValue = 100; + } else { + if (newValue < 0) { newValue = 0; } + } + VeraCommunication vera = VeraCommunication.Instance; + // Do something with vera + string cmd = "?id=lu_action&DeviceNum="+id.ToString()+ + "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget" + + "&newLoadlevelTarget="+value; + string sResult = vera.doVeraRequest(cmd); + m_iLevel = newValue; + } + } + + public override int maxLevel + { + get { return 100; } + set { } + } + + public override string ToString() + { + return name + " [" + getStatusText() + "]"; + } + + public override bool isControllable + { + get { return true; } + set { } + } + + public override string getIconName() + { + string leveltxt = "0"; + if (level > 0) { leveltxt = "25"; } + if (level > 35) { leveltxt = "50"; } + if (level > 65) { leveltxt = "75"; } + if (level > 85) { leveltxt = "100"; } + + return "Dimmable_Light_"+leveltxt; + } + + public override string getStatusText() + { + return ( state ? level.ToString() + "%" : "Off"); + } + } +} Added: trunk/plugins/VeraControl/DeviceDoorlock.cs =================================================================== --- trunk/plugins/VeraControl/DeviceDoorlock.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceDoorlock.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,89 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 3-1-2012 + * Time: 11:51 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceDoorlock. + /// </summary> + public class DeviceDoorlock : DeviceGeneric + { + private bool m_bStatus; + + public DeviceDoorlock( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_bStatus = (xn.Attributes["status"].Value == "1"); + + return base.update(xn); + } + + public override bool state + { + get { return m_bStatus; } + set { + VeraCommunication vera = VeraCommunication.Instance; + // Do something with vera + string cmd = "?id=lu_action&DeviceNum="+id.ToString()+ + "&serviceId=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget" + + "&newTargetValue="+(value ? "1" : "0"); + string sResult = vera.doVeraRequest(cmd); + m_bStatus = value; + } + } + + public override int level + { + get { return (m_bStatus ? 1 : 0); } + set + { + state = (value > 0); + } + } + + public override int maxLevel + { + get { return 1; } + set { } + } + + public override string ToString() + { + return name + " [" + getStatusText() + "]"; + } + + public override bool isControllable + { + get { return true; } + set { } + } + + public override string getIconName() + { + return "Door_" + (m_bStatus ? "LOCKED" : "UNLOCKED"); + } + + public override string getStatusText() + { + return (state ? "Locked" : "Unlocked"); + } + + } +} Added: trunk/plugins/VeraControl/DeviceGWeather.cs =================================================================== --- trunk/plugins/VeraControl/DeviceGWeather.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceGWeather.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,54 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 3-1-2012 + * Time: 12:51 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceGWeather. + /// </summary> + public class DeviceGWeather : DeviceGeneric + { + private string m_sCondition; + private string m_sWindCondition; + + public DeviceGWeather( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_sCondition = (xn.Attributes["Condition"] != null ? xn.Attributes["Condition"].Value : "-"); + m_sWindCondition = (xn.Attributes["WindCondition"] != null ? xn.Attributes["WindCondition"].Value : "-"); + + return base.update(xn); + } + + public override string ToString() + { + return name + " [" + getStatusText() + "]"; + } + + public override string getStatusText() + { + return m_sCondition.Replace("_", " "); + } + public override string getExtraText() + { + return m_sWindCondition; + } + } +} Added: trunk/plugins/VeraControl/DeviceGeneric.cs =================================================================== --- trunk/plugins/VeraControl/DeviceGeneric.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceGeneric.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,141 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 22-12-2011 + * Time: 13:07 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; +using System.Collections.Generic; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceGeneric. + /// </summary> + public class DeviceGeneric + { + private string m_sName = ""; + private int m_iId = 0; + private string m_sAltId = ""; + private int m_iCategory = 0; + private int m_iRoom = 0; + + public DeviceGeneric(XmlNode xn) + { + if (xn != null) + { + update(xn); + } + } + + public virtual bool update(XmlNode xn) + { + m_sName = xn.Attributes["name"].Value; + m_iId = int.Parse(xn.Attributes["id"].Value); + m_sAltId = xn.Attributes["altid"].Value; + m_iCategory = int.Parse(xn.Attributes["category"].Value); + m_iRoom = int.Parse(xn.Attributes["room"].Value); + return true; + } + + public int id + { + get { return m_iId; } + set { } + } + + public string altid + { + get { return m_sAltId; } + set { } + } + + public string name + { + get { return m_sName; } + set { } + } + + public int category + { + get { return m_iCategory; } + set { } + } + + public bool inRoom(int id) + { + return (m_iRoom == id); + } + + public int room + { + get { return m_iRoom; } + set { } + } + + public override string ToString() + { + return name; + } + + public virtual bool isControllable + { + get { return false; } + set { } + } + + public virtual bool state + { + get { return false; } + set { } + } + + public virtual int level + { + get { return 0; } + set { } + } + + public virtual string mode + { + get { return ""; } + set { } + } + + public virtual int maxLevel + { + get { return -1; } + set { } + } + public virtual int minLevel + { + get { return 0; } + set { } + } + + public virtual string getIconName() + { + return "generic_sensor"; + } + + public virtual string getStatusText() + { + return ""; + } + + public virtual string getExtraText() + { + return ""; + } + + public virtual string[] getCommands() + { + return new string [] {"Off", "On"}; + } + } +} Added: trunk/plugins/VeraControl/DeviceHumidity.cs =================================================================== --- trunk/plugins/VeraControl/DeviceHumidity.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceHumidity.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,64 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 22-12-2011 + * Time: 17:47 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceHumidity. + /// </summary> + public class DeviceHumidity : DeviceGeneric + { + private int m_iLevel; + + public DeviceHumidity( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_iLevel = int.Parse(xn.Attributes["humidity"].Value); + return base.update(xn); + } + + public override int level + { + get { return m_iLevel; } + set {} + } + + public override int maxLevel + { + get { return 100; } + set { } + } + + public override string ToString() + { + return name + " [" + level.ToString() + "%]"; + } + + public override string getIconName() + { + return "Humidity_Sensor"; + } + + public override string getStatusText() + { + return level + "%"; + } + } +} Added: trunk/plugins/VeraControl/DeviceLightSensor.cs =================================================================== --- trunk/plugins/VeraControl/DeviceLightSensor.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceLightSensor.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,70 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 3-1-2012 + * Time: 12:09 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceLightSensor. + /// </summary> + public class DeviceLightSensor : DeviceGeneric + { + private int m_iLevel; + + public DeviceLightSensor( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_iLevel = (xn.Attributes["level"] != null ? int.Parse(xn.Attributes["level"].Value) : 0); + return base.update(xn); + } + + public override bool state + { + get { return (m_iLevel > 0); } + set { } + } + + public override int level + { + get { return m_iLevel; } + set { } + } + + public override int maxLevel + { + get { return 100; } + set { } + } + + public override string ToString() + { + return name + " [" + getStatusText() + "]"; + } + + public override string getIconName() + { + return "Light_Sensor"; + } + + public override string getStatusText() + { + return level.ToString() + "%"; + } + } +} Added: trunk/plugins/VeraControl/DevicePowerMeter.cs =================================================================== --- trunk/plugins/VeraControl/DevicePowerMeter.cs (rev 0) +++ trunk/plugins/VeraControl/DevicePowerMeter.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,76 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 3-1-2012 + * Time: 12:21 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DevicePowerMeter. + /// </summary> + public class DevicePowerMeter : DeviceGeneric + { + private int m_iLevel; + + public DevicePowerMeter( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_iLevel = (xn.Attributes["level"] != null ? int.Parse(xn.Attributes["watts"].Value) : 0); + return base.update(xn); + } + + public string watts + { + get { return m_iLevel.ToString(); } + set { } + } + + public override bool state + { + get { return (m_iLevel > 0); } + set { } + } + + public override int level + { + get { return m_iLevel; } + set { } + } + + public override int maxLevel + { + get { return 1000; } + set { } + } + + public override string ToString() + { + return name + " [" + getStatusText() + "]"; + } + + public override string getIconName() + { + return "Power_Meter"; + } + + public override string getStatusText() + { + return level.ToString() + "W"; + } + } +} Added: trunk/plugins/VeraControl/DeviceSecurity.cs =================================================================== --- trunk/plugins/VeraControl/DeviceSecurity.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceSecurity.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,95 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 22-12-2011 + * Time: 18:03 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; +using System.Collections.Generic; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceSecurity. + /// </summary> + public class DeviceSecurity: DeviceGeneric + { + private bool m_bTripped; + private bool m_bArmed; + + public DeviceSecurity( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_bTripped = (xn.Attributes["tripped"].Value == "1"); + m_bArmed = (xn.Attributes["armed"].Value == "1"); + return base.update(xn); + } + + public override bool state + { + get { return m_bArmed; } + set { VeraCommunication vera = VeraCommunication.Instance; + // Do something with vera + string cmd = "?id=lu_action&DeviceNum="+id.ToString()+ + "&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&action=SetArmed" + + "&newArmedValue=" + (value ? "1" : "0"); + string sResult = vera.doVeraRequest(cmd); + m_bArmed = value; + } + } + + public bool tripped + { + get { return m_bTripped; } + set { } + } + + public override int level + { + get { return (m_bArmed ? 1 : 0); } + set { state = (value > 0); } + } + + public override int maxLevel + { + get { return 1; } + set { } + } + public override bool isControllable + { + get { return true; } + set { } + } + public override string ToString() + { + return name + " [" + getStatusText() + "]"; + } + + public override string getIconName() + { + return "Motion_Sensor_" + (m_bTripped ? "100" : "0"); + } + + public override string getStatusText() + { + return (state ? ( tripped ? "TRIPPED" : "standby") : "bypass"); + } + + public override string[] getCommands() + { + return new string [] {"Bypass", "Arm"}; + } + } +} Added: trunk/plugins/VeraControl/DeviceSprinkler.cs =================================================================== --- trunk/plugins/VeraControl/DeviceSprinkler.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceSprinkler.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,119 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 3-1-2012 + * Time: 16:26 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; +using System.Collections.Generic; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceSprinkler. + /// </summary> + public class DeviceSprinkler : DeviceGeneric + { + private bool m_bStatus; + private string m_sMode; + private string m_sShortMode; + private string m_sOperationMode; + private string m_sCondition; + + public DeviceSprinkler( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_bStatus = (xn.Attributes["status"].Value == "1"); + m_sMode = (xn.Attributes["Mode"] != null ? xn.Attributes["Mode"].Value : "-"); + m_sShortMode = (xn.Attributes["ShortMode"] != null ? xn.Attributes["ShortMode"].Value : "-"); + m_sOperationMode = (xn.Attributes["OperationMode"] != null ? xn.Attributes["OperationMode"].Value : "-"); + m_sCondition = (xn.Attributes["Condition"] != null ? xn.Attributes["Condition"].Value : "-"); + return base.update(xn); + } + + public override bool state + { + get { return m_bStatus; } + set { + VeraCommunication vera = VeraCommunication.Instance; + // Do something with vera + string cmd = "?id=lu_action&DeviceNum="+id.ToString()+ + "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget" + + "&newTargetValue="+(value ? "1" : "0"); + string sResult = vera.doVeraRequest(cmd); + m_bStatus = value; + } + } + + public override int level + { + get { return (m_bStatus ? 1 : 0); } + set { state = (value > 0); } + } + + public override string mode + { + get { return m_sMode; } + set { + VeraCommunication vera = VeraCommunication.Instance; + // Do something with vera + string cmd = "?id=lu_action&DeviceNum="+id.ToString()+ + "&serviceId=urn:upnp-micasaverde-com:serviceId:Sprinkler1&action=" + + (value == "Auto" ? "SetModeAuto" : (value == "Block" ? "SetModeBlock" : "SetModeManual")); + string sResult = vera.doVeraRequest(cmd); + m_sMode = value; + } + } + + public override string ToString() + { + return name + " [" + m_sShortMode + "]"; + } + + public override bool isControllable + { + get { return true; } + set { } + } + + public override int maxLevel + { + get { return 1; } + set { } + } + + public override string getIconName() + { + return "Humidity_Sensor"; + } + + public override string getStatusText() + { + return m_sOperationMode.Replace("_", " "); + } + + public override string getExtraText() + { + return m_sCondition; + } + + + + public override string [] getCommands() + { + return new string [] {"Off", "On", "Auto", "Block", "Manual"}; + } + } +} Added: trunk/plugins/VeraControl/DeviceSwitch.cs =================================================================== --- trunk/plugins/VeraControl/DeviceSwitch.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceSwitch.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,92 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 22-12-2011 + * Time: 14:25 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceSwitch. + /// </summary> + public class DeviceSwitch : DeviceGeneric + { + private bool m_bStatus; + private string m_sWatt; + + public DeviceSwitch( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_bStatus = (xn.Attributes["status"].Value == "1"); + m_sWatt = (xn.Attributes["watts"] != null ? xn.Attributes["watts"].Value : "0"); + return base.update(xn); + } + + public string watts + { + get { return m_sWatt; } + set { } + } + + public override bool state + { + get { return m_bStatus; } + set { + VeraCommunication vera = VeraCommunication.Instance; + // Do something with vera + string cmd = "?id=lu_action&DeviceNum="+id.ToString()+ + "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget" + + "&newTargetValue="+(value ? "1" : "0"); + string sResult = vera.doVeraRequest(cmd); + m_bStatus = value; + } + } + + public override int level + { + get { return (m_bStatus ? 1 : 0); } + set { state = (value > 0); } + } + + public override int maxLevel + { + get { return 1; } + set { } + } + + public override string ToString() + { + return name + " [" + getStatusText()+ "]"; + } + + public override bool isControllable + { + get { return true; } + set { } + } + + public override string getIconName() + { + return "Binary_Light_" + (m_bStatus ? "100" : "0"); + } + + public override string getStatusText() + { + return (state ? "On" : "Off"); + } + } +} Added: trunk/plugins/VeraControl/DeviceTemperature.cs =================================================================== --- trunk/plugins/VeraControl/DeviceTemperature.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceTemperature.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,73 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 22-12-2011 + * Time: 17:52 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceTemperature. + /// </summary> + public class DeviceTemperature : DeviceGeneric + { + public int m_iLevel; + private bool m_bMetric = true; + + public DeviceTemperature( XmlNode xn, bool bMetric ): base (xn) + { + m_bMetric = bMetric; + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_iLevel = (xn.Attributes["temperature"] != null ? int.Parse(xn.Attributes["temperature"].Value) : 0); + return base.update(xn); + } + + public override int level + { + get { return m_iLevel; } + set { } + } + + public override int maxLevel + { + get { return (m_bMetric ? 100 : 212); } + set { } + } + + public override int minLevel + { + get { return (m_bMetric ? -22 : -7); } + set { } + } + + public override string ToString() + { + return name + " [" + getStatusText() + "]"; + } + + public override string getIconName() + { + return "Temperature_Sensor"; + } + + public override string getStatusText() + { + return level + (m_bMetric ? "°C" : "F"); + } + + } +} Added: trunk/plugins/VeraControl/DeviceThermostat.cs =================================================================== --- trunk/plugins/VeraControl/DeviceThermostat.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceThermostat.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,109 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 25-12-2011 + * Time: 0:03 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceThermostat. + /// </summary> + public class DeviceThermostat : DeviceTemperature + { + private bool m_bMetric = true; + private string m_sFan = ""; + private string m_sState = "Off"; // "Off', "Idle", "Heating", "Cooling", "FanOnly", "PendingHeat", "PendingCool", "Vent" + private string m_sMode = "Off"; // "Off', "InDeadBand", "HeatOn", "CoolOn", "AutoChangeOver", "AuxHeatOn", "EconomyHeatOn", "EmergencyHeatOn", + // "AuxCoolOn", "EconomyCoolOn", "BuildingProtection", "EnergySavingsHeating", "EnergySavingsCooling" + + public DeviceThermostat( XmlNode xn, bool bMetric ): base (xn, bMetric) + { + m_bMetric = bMetric; + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_iLevel = (xn.Attributes["temperature"] != null ? int.Parse(xn.Attributes["temperature"].Value) : 0); + m_sFan = (xn.Attributes["fan"] != null ? xn.Attributes["fn"].Value : "Off"); + m_sState = (xn.Attributes["hvacstate"] != null ? xn.Attributes["hvacstate"].Value : "Off"); + m_sMode = (xn.Attributes["mode"] != null ? xn.Attributes["mode"].Value : "Off"); + return base.update(xn); + } + + public override bool state + { + get { return (mode != "Off"); } + set { mode = (value ? "Auto" : "Off"); } + } + + public override int level + { + get { return -1; } + set { } + } + + public override string mode + { + get { return m_sMode; } + set { + VeraCommunication vera = VeraCommunication.Instance; + // Do something with vera + string cmd = "?id=lu_action&DeviceNum="+id.ToString()+ + "&serviceId=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget" + + "&NewModeTarget="+(value == "Off" ? "Off" : (value == "Cool" ? "CoolOn" : (value == "Heat" ? "HeatOn" : "AutoChangeOver")) + ); + string sResult = vera.doVeraRequest(cmd); + m_sMode = value; + } + } + + public override string ToString() + { + return name + " [" + mode + "]"; + } + + public override bool isControllable + { + get { return true; } + set { } + } + + public override int maxLevel + { + get { return -1; } + set { } + } + + public override string getStatusText() + { + return mode; + } + + public override string getExtraText() + { + return m_sState + " - Fan : " + m_sFan + " - " + m_iLevel + (m_bMetric ? "°C" : "F") ; + } + + public override string getIconName() + { + return "Thermostat"; + } + + public override string [] getCommands() + { + return new string [] {"Off", "On", "Auto", "Heat", "Cool"}; + } + } +} Added: trunk/plugins/VeraControl/DeviceWindowCovering.cs =================================================================== --- trunk/plugins/VeraControl/DeviceWindowCovering.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceWindowCovering.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,34 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 24-12-2011 + * Time: 23:56 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceWindowCovering. + /// </summary> + public class DeviceWindowCovering : DeviceDimmer + { + public DeviceWindowCovering( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override string getIconName() + { + return "Window_Covering"; + } + } +} Added: trunk/plugins/VeraControl/DialogActionTrigger.cs =================================================================== --- trunk/plugins/VeraControl/DialogActionTrigger.cs (rev 0) +++ trunk/plugins/VeraControl/DialogActionTrigger.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,176 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 30-12-2011 + * Time: 0:35 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using MediaPortal; +using MediaPortal.Util; +using MediaPortal.GUI.Library; +using MediaPortal.Dialogs; +using System.Collections.Generic; +using Alignment = MediaPortal.GUI.Library.GUIControl.Alignment; +using VAlignment = MediaPortal.GUI.Library.GUIControl.VAlignment; +using Action = MediaPortal.GUI.Library.Action; +using VeraControl.Properties; + +namespace VeraControl +{ + /// <summary> + /// Description of DialogActionTrigger. + /// </summary> + public class DialogActionTrigger : GUIDialogWindow + { + [SkinControl(2)] protected GUIButtonControl btnClose = null; + [SkinControl(4)] protected GUILabelControl lblHeading = null; + [SkinControl(100)] protected GUIButtonControl btnStore = null; + + [SkinControlAttribute(20)] protected GUISpinButton spMusicStart = null; + [SkinControlAttribute(21)] protected GUISpinButton spMusicPause = null; + [SkinControlAttribute(22)] protected GUISpinButton spMusicResume = null; + [SkinControlAttribute(23)] protected GUISpinButton spMusicStop = null; + + [SkinControlAttribute(25)] protected GUISpinButton spVideoStart = null; + [SkinControlAttribute(26)] protected GUISpinButton spVideoPause = null; + [SkinControlAttribute(27)] protected GUISpinButton spVideoResume = null; + [SkinControlAttribute(28)] protected GUISpinButton spVideoStop = null; + + [SkinControlAttribute(30)] protected GUISpinButton spTVStart = null; + [SkinControlAttribute(31)] protected GUISpinButton spTVPause = null; + [SkinControlAttribute(32)] protected GUISpinButton spTVResume = null; + [SkinControlAttribute(33)] protected GUISpinButton spTVStop = null; + + [SkinControlAttribute(35)] protected GUISpinButton spRecStart = null; + [SkinControlAttribute(36)] protected GUISpinButton spRecPause = null; + [SkinControlAttribute(37)] protected GUISpinButton spRecResume = null; + [SkinControlAttribute(38)] protected GUISpinButton spRecStop = null; + + [SkinControlAttribute(40)] protected GUISpinButton spRadioStart = null; + [SkinControlAttribute(41)] protected GUISpinButton spRadioPause = null; + [SkinControlAttribute(42)] protected GUISpinButton spRadioResume = null; + [SkinControlAttribute(43)] protected GUISpinButton spRadioStop = null; + + [SkinControlAttribute(45)] protected GUISpinButton spUnknownStart = null; + [SkinControlAttribute(46)] protected GUISpinButton spUnknownPause = null; + [SkinControlAttribute(47)] protected GUISpinButton spUnknownResume= null; + [SkinControlAttribute(48)] protected GUISpinButton spUnknownStop = null; + + [SkinControlAttribute(50)] protected GUISpinButton spMPStart = null; + [SkinControlAttribute(51)] protected GUISpinButton spMPSleep = null; + [SkinControlAttribute(52)] protected GUISpinButton spMPExit = null; + + + public DialogActionTrigger() + { + GetID = (int)1974; + } + + public void SetHeading(string strLine) + { + //LoadSkin(); + AllocResources(); + InitControls(); + + GUISpinButton[] spinList = new GUISpinButton[] { + spMusicStart, spMusicPause, spMusicResume, spMusicStop, + spVideoStart, spVideoPause, spVideoResume, spVideoStop, + spTVStart, spTVPause, spTVResume, spTVStop, + spRecStart, spRecPause, spRecResume, spRecStop, + spRadioStart, spRadioPause, spRadioResume, spRadioStop, + spUnknownStart, spUnknownPause, spUnknownResume, spUnknownStop, + spMPStart, spMPSleep, spMPExit + }; + + // (P)re load spin contor + for (int i = 0; i < spinList.Length; i++) + { + initSpinButtons(spinList[i], VeraCommunication.Instance.actionTriggerTable[i]); + } + + lblHeading.Label = strLine; + } + + public override bool Init() + { + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) + { + for (Actiontrigger i = 0; i < Actiontrigger.LAST_ACTIONTRIGGER; i++) + { + VeraCommunication.Instance.actionTriggerTable[(int)i] = xmlreader.GetValueAsInt("veracontroller", i.ToString(), 0); + } + } + return Load(GUIGraphicsContext.Skin + @"\VeraDialogActionTrigger.xml"); + } + + protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) + { + if (control == btnStore) + { + StoreSettings(); + PageDestroy(); + } + // Back to the text button to switch from image view + if (control == btnClose) + { + PageDestroy(); + } + base.OnClicked(controlId, control, actionType); + } + + private void initSpinButtons(GUISpinButton spin, int iSelectedScene) + { + GUIControl.ClearControl(GetID, spin.GetID); + int iSceneIndex = 0; + spin.AddSpinLabel("- none -", 0); + + for (int i = 0; i < VeraCommunication.Instance.scenes.Count; i++) + { + spin.AddSpinLabel(shortString(VeraCommunication.Instance.scenes[i].name), VeraCommunication.Instance.scenes[i].id); + if (VeraCommunication.Instance.scenes[i].id == iSelectedScene) + { + iSceneIndex = i + 1; // 0 is - none - + } + } + spin.SpinValue = iSceneIndex; + } + + private string shortString( string str ) + { + if (str.Length > 15) + { + return str.Substring(0, 14) + ".."; + } + return str; + } + + private void StoreSettings() + { + using (MediaPortal.Profile.Settings xmlwritter = new MediaPortal.Profile.MPSettings()) + { + GUISpinButton[] spinList = new GUISpinButton[] { + spMusicStart, spMusicPause, spMusicResume, spMusicStop, + spVideoStart, spVideoPause, spVideoResume, spVideoStop, + spTVStart, spTVPause, spTVResume, spTVStop, + spRecStart, spRecPause, spRecResume, spRecStop, + spRadioStart, spRadioPause, spRadioResume, spRadioStop, + spUnknownStart, spUnknownPause, spUnknownResume, spUnknownStop, + spMPStart, spMPSleep, spMPExit + }; + for (int i = 0; i < spinList.Length; i++) + { + if (spinList[i].SpinValue == 0) { + VeraCommunication.Instance.actionTriggerTable[i] = 0; + } else { + VeraCommunication.Instance.actionTriggerTable[i] = VeraCommunication.Instance.scenes[spinList[i].SpinValue - 1].id; + } + xmlwritter.SetValue("veracontroller", ((Actiontrigger) i).ToString(), VeraCommunication.Instance.actionTriggerTable[i].ToString()); + } + } + } + } +} Added: trunk/plugins/VeraControl/DialogDeviceControl.cs =================================================================== --- trunk/plugins/VeraControl/DialogDeviceControl.cs (rev 0) +++ trunk/plugins/VeraControl/DialogDeviceControl.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,194 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 24-12-2011 + * Time: 14:17 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Collections; +using MediaPortal; +using MediaPortal.Util; +using MediaPortal.GUI.Library; +using MediaPortal.Dialogs; +using System.Collections.Generic; +using Alignment = MediaPortal.GUI.Library.GUIControl.Alignment; +using VAlignment = MediaPortal.GUI.Library.GUIControl.VAlignment; +using Action = MediaPortal.GUI.Library.Action; +using VeraControl.Properties; + +namespace VeraControl +{ + /// <summary> + /// Description of DialogDeviceControl. + /// </summar`y> + public class DialogDeviceControl : GUIDialogWindow + { + [SkinControl(2)] protected GUIButtonControl btnClose = null; + [SkinControl(4)] protected GUILabelControl lblHeading = null; + [SkinControl(5)] protected GUIImage imgLogo = null; + + [SkinControlAttribute(6)] protected GUILabelControl label1=null; + [SkinControlAttribute(7)] protected GUILabelControl label2=null; + [SkinControlAttribute(8)] protected GUILabelControl label3=null; + + [SkinControl(10)] protected GUIButtonControl btnLeft = null; + [SkinControl(11)] protected GUIButtonControl btnRight = null; + [SkinControl(12)] protected GUIButtonControl btnMode1 = null; + [SkinControl(13)] protected GUIButtonControl btnMode2 = null; + [SkinControl(14)] protected GUIButtonControl btnMode3 = null; + [SkinControl(15)] protected GUISliderControl slider = null; + + DeviceGeneric myDev = null; + + public DialogDeviceControl() + { + GetID = (int)1973; + } + + public void InitDialog(string strLine, DeviceGeneric dev) + { + //LoadSkin(); + AllocResources(); + InitControls(); + + lblHeading.Label = strLine; + + myDev = dev; + } + + public override bool Init() + { + bool bResult = Load(GUIGraphicsContext.Skin + @"\VeraDialogDeviceControl.xml"); + return bResult; + } + + protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) + { + if (control == btnLeft) + { + myDev.level = myDev.minLevel; + SetSlider( myDev.level, myDev.maxLevel ); + } + + if (control == btnRight) + { + myDev.level = myDev.maxLevel; + SetSlider( myDev.level, myDev.maxLevel ); + } + + if (control == btnMode1) + { + myDev.mode = btnMode1.Label; + SetActiveBut(-1, 0); + } + if (control == btnMode2) + { + myDev.mode = btnMode2.Label; + SetActiveBut(-1, 1); + } + if (control == btnMode3) + { + myDev.mode = btnMode3.Label; + SetActiveBut(-1, 2); + } + + if (control == slider) + { + myDev.level = slider.IntValue; + } + + // update button high lighting + SetActiveBut( (slider.IntValue > 0 ? 1 : 0), -1); + + // update icon + SetImage("Vera\\" + myDev.getIconName() + ".png"); + + // Back to the text button to switch from image view + if (control == btnClose) + { + PageDestroy(); + } + base.OnClicked(controlId, control, actionType); + } + + public void SetButtons(string [] butTxt) + { + GUIButtonControl[] btns = new GUIButtonControl[] {btnLeft, btnRight, btnMode1, btnMode3, btnMode2}; + for (int i=0; i < btns.Length; i++) + { + if (butTxt.Length > i) { + btns[i].Label = butTxt[i]; + btns[i].Visibility = System.Windows.Visibility.Visible; + } else { + btns[i].Visibility = System.Windows.Visibility.Hidden; + } + } + + if (butTxt.Length > 2) + { + btnLeft.NavigateUp = 12; + btnRight.NavigateUp = 14; + + if (butTxt.Length < 5) + { + // if only 2 buttons required, use right iso middle button + btnMode1.NavigateRight = 14; + btnMode3.NavigateLeft = 12; + } + } + } + + public void SetSlider(int iVal, int iMaxval) + { + if (iVal >= 0) + { + slider.SetRange(0, iMaxval); + slider.IntValue = iVal; + slider.Visibility = System.Windows.Visibility.Visible; + } + } + + public void SetText(string txt1, string txt2, string txt3) + { + label1.Label = txt1; + label2.Label = txt2; + label3.Label = txt3; + } + + public void SetActiveBut( int iButNr, int iModeNr ) + { + if (iButNr >= 0) + { + btnLeft.TextColor = (iButNr == 0 ? 0xFFFFFF00 : 0xFFFFFFFF ); + btnLeft.TextColorNoFocus = (iButNr == 0 ? 0x60FFFF00 : 0x60ffffff); + + btnRight.TextColor = (iButNr == 1 ? 0xFFFFFF00 : 0xFFFFFFFF ); + btnRight.TextColorNoFocus = (iButNr == 1 ? 0x60FFFF00 : 0x60ffffff); + } + + if (iModeNr >= 0) + { + btnMode1.TextColor = (iModeNr == 0 ? 0xFFFFFF00 : 0xFFFFFFFF ); + btnMode1.TextColorNoFocus = (iModeNr == 0 ? 0x60FFFF00 : 0x60ffffff); + + btnMode2.TextColor = (iModeNr == 1 ? 0xFFFFFF00 : 0xFFFFFFFF ); + btnMode2.TextColorNoFocus = (iModeNr == 1 ? 0x60FFFF00 : 0x60ffffff); + + btnMode3.TextColor = (iModeNr == 2 ? 0xFFFFFF00 : 0xFFFFFFFF ); + btnMode3.TextColorNoFocus = (iModeNr == 2 ? 0x60FFFF00 : 0x60ffffff); + } + } + + public void SetImage(string filename) + { + imgLogo.Dispose(); + imgLogo.SetFileName(filename); + imgLogo.AllocResources(); + imgLogo.KeepAspectRatio = true; + } + } +} Added: trunk/plugins/VeraControl/Properties/AssemblyInfo.cs =================================================================== --- trunk/plugins/VeraControl/Properties/AssemblyInfo.cs (rev 0) +++ trunk/plugins/VeraControl/Properties/AssemblyInfo.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,31 @@ +#region Using directives + +using System; +using System.Reflection; +using System.Runtime.InteropServices; + +#endregion + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("VeraControl")] +[assembly: AssemblyDescription("MediaPortal - Windows Plugin")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Bart Eversdijk")] +[assembly: AssemblyProduct("VeraControl")] +[assembly: AssemblyCopyright("Copyright 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("ba...@ev...")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all the values or you can use the default the Revision and +// Build Numbers by using the '*' as shown below: +[assembly: AssemblyVersion("0.5.*")] Added: trunk/plugins/VeraControl/Room.cs =================================================================== --- trunk/plugins/VeraControl/Room.cs (rev 0) +++ trunk/plugins/VeraControl/Room.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,69 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 22-12-2011 + * Time: 14:05 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of Room. + /// </summary> + public class Room + { + public Room(XmlNode xn) + { + if (xn == null) + { + m_sName = ""; + m_iId = 0; + m_iSection = 0; + } else { + update(xn); + } + } + + private string m_sName; + private int m_iId; + private int m_iSection; + + public bool update(XmlNode xn) + { + m_sName = xn.Attributes["name"].Value; + m_iId = int.Parse(xn.Attributes["id"].Value); + m_iSection = int.Parse(xn.Attributes["section"].Value); + return true; + } + + public int id + { + get { return m_iId; } + set { } + } + + public string name + { + get { return m_sName; } + set { } + } + + + public int section + { + get { return m_iSection; } + set { } + } + + public override string ToString() + { + return name; + } + } +} Added: trunk/plugins/VeraControl/Scene.cs =================================================================== --- trunk/plugins/VeraControl/Scene.cs (rev 0) +++ trunk/plugins/VeraControl/Scene.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,93 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 22-12-2011 + * Time: 13:50 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of Scene. + /// </summary> + public class Scene + { + public Scene(XmlNode xn) + { + if (xn == null) + { + m_sName = ""; + m_iId = 0; + m_bActive = false; + m_iRoom = 0; + } else { + update(xn); + } + } + + private string m_sName; + private int m_iId; + private bool m_bActive; + private int m_iRoom; + + public bool update(XmlNode xn) + { + m_sName = xn.Attributes["name"].Value; + m_iId = int.Parse(xn.Attributes["id"].Value); + m_iRoom = int.Parse(xn.Attributes["room"].Value); + m_bActive = (xn.Attributes["name"].Value == "1"); + return true; + } + + public int id + { + get { return m_iId; } + set { } + } + + public string name + { + get { return m_sName; } + set { } + } + + + public bool isActive() + { + return m_bActive; + } + + public bool inRoom(int id) + { + return (m_iRoom == id); + } + + public int room + { + get { return m_iRoom; } + set { } + } + + public override string ToString() + { + return name; + } + + public string run() + { + if (id == 0) + { + return "Unknown scene"; + } + VeraCommunication vera = VeraCommunication.Instance; + string cmd = "?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="+id; + return vera.doVeraRequest(cmd, true); + } + } +} Added: trunk/plugins/VeraControl/Section.cs =================================================================== --- trunk/plugins/VeraControl/Section.cs (rev 0) +++ trunk/plugins/VeraControl/Section.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,59 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 23-12-2011 + * Time: 21:05 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of Section. + /// </summary> + public class Section + { + public Section(XmlNode xn) + { + if (xn == null) + { + m_sName = ""; + m_iId = 0; + } else { + update(xn); + } + } + + private string m_sName; + private int m_iId; + + public bool update(XmlNode xn) + { + m_sName = xn.Attributes["name"].Value; + m_iId = int.Parse(xn.Attributes["id"].Value); + return true; + } + + public int id + { + get { return m_iId; } + set { } + } + + public string name + { + get { return m_sName; } + set { } + } + + public override string ToString() + { + return name; + } + } +} Added: trunk/plugins/VeraControl/VeraCommunication.cs =================================================================== --- trunk/plugins/VeraControl/VeraCommunication.cs (rev 0) +++ trunk/plugins/VeraControl/VeraCommunication.cs 2012-01-05 12:17:24 UTC (rev 4373) @@ -0,0 +1,474 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 21-12-2011 + * Time: 22:26 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Net; +using System.IO; +using System.Collections.Generic; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of VeraCommunication. + /// </summary> + + public class VeraStatus + { + 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 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 string m_sVeraIPAddress; + private string m_sVeraTCPIPPort; + private string m_sDataVersion = ""; + private bool m_bMetric = true; + + private VeraStatus m_status = new VeraStatus(); + private long m_lLastUpdate = 0; + private bool m_bUpdatePending = false; + + 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()) + { + m_sVeraIPAddress = xmlreader.GetValueAsString("veracontroller", "ipaddress", "127.0.0.1"); + m_sVeraTCPIPPort = xmlreader.GetValueAsString("veracontroller", "portnumber", "49451"); + } + // Clear action table (TO DO: load with config settings) + for (int i = 0; i < (int)Actiontrigger.LAST_ACTIONTRIGGER; i++) + { + actionTriggerTable[i] = 0; + } + } + + public bool updateCurrentStatus() + { + if (m_bUpdatePending) + { + return false; + } + m_bUpdatePending = true; + string verastatus = doVeraRequest("?id=lu_sdata&output_format=xml"); + m_lLastUpdate = getSecondSince1970(); + + var xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(verastatus); + + // Parse header + XmlNode rootnode = xmlDoc.SelectSingleNode("/root"); + m_bMetric = (rootnode.Attributes["temperature"].Value == "C"); + bool bFullRefresh = (m_sDataVersion != rootnode.Attributes["dataversion"].Value); + m_sDataVersion = rootnode.Attributes["dataversion"].Value; + + if (bFullRefresh) + { + // We have a full refresh -> Clear all lists + m_status.clearAllLists(); + } + + // Process Sections + XmlNodeList xnList = xmlDoc.SelectNodes("/root/sections/section"); + foreach (XmlNode xn in xnList) + { + Section sc = m_status.getSectionById( int.Parse(xn.Attributes["id"].Value) ); + if (sc.id != 0) { + sc.update(xn); + } else { + m_status.sections.Add(new Section(xn)); + } + } + + // Process Scenes + xnList = xmlDoc.SelectNodes("/root/scenes/scene"); + foreach (XmlNode xn in xnList) + { + Scene sc = m_status.getSceneById( int.Parse(xn.Attributes["id"].Value) ); + if (sc.id != 0) { + sc.update(xn); + } else { + m_status.scenes.Add(new Scene(xn)); + } + } + + // Process Rooms + xnList = xmlDoc.SelectNodes("/root/rooms/room"); + foreach (XmlNode xn in xnList) + { + Room room = m_status.getRoomById( int.Parse(xn.Attributes["id"].Value) ); + if (room.id != 0) { + room.update(xn); + } else { + m_status.rooms.Add(new Room(xn)); + } + } + + // Process Categories + xnList = xmlDoc.SelectNodes("/root/categories/categorie"); + foreach (XmlNode xn in xnList) + { + DevCategories cat = m_status.getCategoryById( int.Parse(xn.Attributes["id"].Value) ); + if (cat.id != 0) { + cat.update(xn); + } else { + m_status.categories.Add(new DevCategories(xn)); + } + } + + // Process Devices + xnList = xmlDoc.SelectNodes("/root/devices/device"); + foreach (XmlNode xn in xnList) + { + DeviceGeneric dev = m_status.getDeviceById( int.Parse(xn.Attributes["id"].Value) ); + if (dev.id != 0) { + dev.update(xn); + } else { + switch (xn.Attributes["category"].Value) + { + case "2": + m_status.devices.Add(new DeviceDimmer(xn)); + break; + + case "3": + case "11": // Generic IO + m_status.devices.Add(new DeviceSwitch(xn)); + break; + + case "4": // Generic Sensor + case "12": // Motion Sensor + m_status.devices.Add(new DeviceSecurity(xn)); + break; + + case "5": + m_status.devices.Add(new DeviceThermostat(xn, m_bMetric)); + break; + + // case "6": // TODO: Implement camera class ? + // m_status.devices.Add(new DeviceCamera(xn, m_bMetric)); + // break; + + case "7": + m_status.devices.Add(new DeviceDoorlock(xn)); + break; + + case "8": + m_status.devices.Add(new DeviceWindowCovering(xn)); + break; + + // case "14": // TODO: Implement Scene controller device ? + // m_status.devices.Add(new DeviceSceneController(xn)); + // break; + + // case "15": // TODO: Implement AV device ? + // m_status.devices.Add(new DeviceSensor(xn)); + // break; + + case "16": + m_status.devices.Add(new DeviceHumidity(xn)); + break; + + case "17": + m_status.devices.Add(new DeviceTemperature(xn, m_bMetric)); + break; + + case "18": + m_status.devices.Add(new DeviceLightSensor(xn)); + break; + + case "21": + m_status.devices.Add(new DevicePowerMeter(xn)); + break; + + case "0": + default: + // Check for Google Weather Device + if (xn.Attributes["WindCondition"] != null) + { + m_status.devices.Add(new DeviceGWeather(xn)); + break; + } + // Check for Bart's sprinkler Device + if (xn.Attributes["OperationMode"] != null) + { + m_status.devices.Add(new DeviceSprinkler(xn)); + break; + } + /* Falltrough */ + m_status.devices.Add(new DeviceGeneric(xn)); + break; + } + } + } + // update timer again (took some time to get the data) + m_lLastUpdate = getSecondSince1970(); + m_bUpdatePending = false; + return bFullRefresh; + } + + public string doVeraRequest( string param, bool pParseResult ) + { + string response = doVeraRequest( param ); + if (pParseResult) + { + response = parseVeraRespones(response); + } + return response; + } + + public string doVeraRequest( string param ) + { + return retrieveURL("http://" + m_sVeraIPAddress + ":" + m_sVeraTCPIPPort + "/data_request" + p... [truncated message content] |