HMSystemVariable.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System.Xml;
  2. namespace System.Net.HomeMatic {
  3. public enum SystemVariableType {
  4. Logic = 2,
  5. ValueList = 16,
  6. Numeric = 4,
  7. Alert = 6,
  8. String = 20,
  9. Unknown = 0
  10. }
  11. public class HMSystemVariable : HMBase {
  12. private object _variable;
  13. private object _value;
  14. private string _valueList;
  15. private int _min;
  16. private int _max;
  17. private string _unit;
  18. private SystemVariableType _type;
  19. private string _subType;
  20. private int _timeStamp;
  21. private string _valueName0;
  22. private string _valueName1;
  23. private string _valueText;
  24. private bool _logged;
  25. private bool _visible;
  26. protected override string GetClassName() {
  27. return "HMSystemVariable";
  28. }
  29. protected override string ValuesToString() {
  30. return this._variable.ToString() + ";" +
  31. this._value.ToString() + ";" +
  32. this._valueList + ";" +
  33. this._min.ToString() + ";" +
  34. this._max.ToString() + ";" +
  35. this._unit + ";" +
  36. this._type.ToString() + ";" +
  37. this._subType + ";" +
  38. this._timeStamp.ToString() + ";" +
  39. this._valueName0 + ";" +
  40. this._valueName1 + ";" +
  41. this._valueText + ";" +
  42. (this._logged?"true":"false") + ";" +
  43. (this._visible ? "true" : "false") + ";"
  44. ;
  45. }
  46. public string Name {
  47. get { return this._name; }
  48. }
  49. public object Variable {
  50. get { return this._variable; }
  51. }
  52. public object Value {
  53. //TODO: Nach Variablentype abfragen
  54. //TODO: Update wenn Timestamp älter ist
  55. get {
  56. if (this.UpdateRequired())
  57. this.Update();
  58. return this._value;
  59. }
  60. }
  61. public string[] ValueList {
  62. get { return this._valueList.Split(';'); }
  63. }
  64. public int Min {
  65. get { return this._min; }
  66. }
  67. public int Max {
  68. get { return this._max; }
  69. }
  70. public string Unit {
  71. get { return this._unit; }
  72. }
  73. public SystemVariableType VarType {
  74. get { return this._type; }
  75. }
  76. public string SubType {
  77. get { return this._subType; }
  78. }
  79. public int TimeStamp {
  80. get { return this._timeStamp; }
  81. }
  82. public string ValueName0 {
  83. get { return this._valueName0; }
  84. }
  85. public string ValueName1 {
  86. get { return this._valueName1; }
  87. }
  88. public string ValueText {
  89. get { return this._valueText; }
  90. }
  91. public bool Logged {
  92. get { return this._logged; }
  93. }
  94. public bool Visible {
  95. get { return this._visible; }
  96. }
  97. public HMSystemVariable(HMApi Api) : base(Api) {
  98. }
  99. public HMSystemVariable(HMApi Api, XmlNode Data) : base(Api, Data) {
  100. this.Init(Data);
  101. }
  102. private void Init(XmlNode Data) {
  103. this._variable = this.Attr_Object(Data, "variable");
  104. this._value = this.Attr_Object(Data, "value");
  105. this._valueList = this.Attr_String(Data, "value_list");
  106. this._min = this.Attr_Int32(Data, "min");
  107. this._max = this.Attr_Int32(Data, "max");
  108. this._unit = this.Attr_String(Data, "unit");
  109. string _t = this.Attr_String(Data, "type");
  110. switch (_t) {
  111. case "2":
  112. this._type = SystemVariableType.Logic;
  113. break;
  114. case "4":
  115. this._type = SystemVariableType.Numeric;
  116. break;
  117. case "16":
  118. this._type = SystemVariableType.ValueList;
  119. break;
  120. case "6":
  121. this._type = SystemVariableType.Alert;
  122. break;
  123. case "20":
  124. this._type = SystemVariableType.String;
  125. break;
  126. default:
  127. this._type = SystemVariableType.Unknown;
  128. break;
  129. }
  130. this._subType = this.Attr_String(Data, "sub_type"); ;
  131. this._timeStamp = this.Attr_Int32(Data,"timestamp");
  132. this._valueName0 = this.Attr_String(Data, "value_name_0");
  133. this._valueName1 = this.Attr_String(Data, "value_name_1");
  134. this._valueText = this.Attr_String(Data, "value_text");
  135. this._logged = this.Attr_Bool(Data, "logged");
  136. this._visible = this.Attr_Bool(Data, "visible");
  137. this.lastUpdate = DateTime.Now;
  138. }
  139. private DateTime lastUpdate;
  140. private bool UpdateRequired() {
  141. return DateTime.Now.Ticks - this.lastUpdate.Ticks > 10000000;
  142. }
  143. public void Update() {
  144. XmlDocument doc = this._api.GetApiData(ApiMethode.SystemVariableList);
  145. XmlNodeList childs = doc.ChildNodes[1].ChildNodes;
  146. int c = childs.Count;
  147. if (c > 0) {
  148. for (int i = 0; i < c; i++) {
  149. if (childs[i].Name == "systemVariable") {
  150. string xname = this.Attr_String(childs[i], "name");
  151. if(xname == this._name) {
  152. this.Init(childs[i]);
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }