using System.Xml; namespace System.Net.HomeMatic { public enum SystemVariableType { Logic = 2, ValueList = 16, Numeric = 4, Alert = 6, String = 20, Unknown = 0 } public class HMSystemVariable : HMBase { private object _variable; private object _value; private string _valueList; private int _min; private int _max; private string _unit; private SystemVariableType _type; private string _subType; private int _timeStamp; private string _valueName0; private string _valueName1; private string _valueText; private bool _logged; private bool _visible; protected override string GetClassName() { return "HMSystemVariable"; } protected override string ValuesToString() { return this._variable.ToString() + ";" + this._value.ToString() + ";" + this._valueList + ";" + this._min.ToString() + ";" + this._max.ToString() + ";" + this._unit + ";" + this._type.ToString() + ";" + this._subType + ";" + this._timeStamp.ToString() + ";" + this._valueName0 + ";" + this._valueName1 + ";" + this._valueText + ";" + (this._logged?"true":"false") + ";" + (this._visible ? "true" : "false") + ";" ; } public string Name { get { return this._name; } } public object Variable { get { return this._variable; } } public object Value { //TODO: Nach Variablentype abfragen //TODO: Update wenn Timestamp älter ist get { if (this.UpdateRequired()) this.Update(); return this._value; } } public string[] ValueList { get { return this._valueList.Split(';'); } } public int Min { get { return this._min; } } public int Max { get { return this._max; } } public string Unit { get { return this._unit; } } public SystemVariableType VarType { get { return this._type; } } public string SubType { get { return this._subType; } } public int TimeStamp { get { return this._timeStamp; } } public string ValueName0 { get { return this._valueName0; } } public string ValueName1 { get { return this._valueName1; } } public string ValueText { get { return this._valueText; } } public bool Logged { get { return this._logged; } } public bool Visible { get { return this._visible; } } public HMSystemVariable(HMApi Api) : base(Api) { } public HMSystemVariable(HMApi Api, XmlNode Data) : base(Api, Data) { this.Init(Data); } private void Init(XmlNode Data) { this._variable = this.Attr_Object(Data, "variable"); this._value = this.Attr_Object(Data, "value"); this._valueList = this.Attr_String(Data, "value_list"); this._min = this.Attr_Int32(Data, "min"); this._max = this.Attr_Int32(Data, "max"); this._unit = this.Attr_String(Data, "unit"); string _t = this.Attr_String(Data, "type"); switch (_t) { case "2": this._type = SystemVariableType.Logic; break; case "4": this._type = SystemVariableType.Numeric; break; case "16": this._type = SystemVariableType.ValueList; break; case "6": this._type = SystemVariableType.Alert; break; case "20": this._type = SystemVariableType.String; break; default: this._type = SystemVariableType.Unknown; break; } this._subType = this.Attr_String(Data, "sub_type"); ; this._timeStamp = this.Attr_Int32(Data,"timestamp"); this._valueName0 = this.Attr_String(Data, "value_name_0"); this._valueName1 = this.Attr_String(Data, "value_name_1"); this._valueText = this.Attr_String(Data, "value_text"); this._logged = this.Attr_Bool(Data, "logged"); this._visible = this.Attr_Bool(Data, "visible"); this.lastUpdate = DateTime.Now; } private DateTime lastUpdate; private bool UpdateRequired() { return DateTime.Now.Ticks - this.lastUpdate.Ticks > 10000000; } public void Update() { XmlDocument doc = this._api.GetApiData(ApiMethode.SystemVariableList); XmlNodeList childs = doc.ChildNodes[1].ChildNodes; int c = childs.Count; if (c > 0) { for (int i = 0; i < c; i++) { if (childs[i].Name == "systemVariable") { string xname = this.Attr_String(childs[i], "name"); if(xname == this._name) { this.Init(childs[i]); } } } } } } }