HMChannel.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System.Xml;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. namespace System.Net.HomeMatic {
  5. public partial class HMChannel : HMBase {
  6. protected int _type;
  7. protected string _address;
  8. protected HomeMatic.Direction _direction = HomeMatic.Direction.Unknown;
  9. protected int _parentDevice; // link to iseId
  10. protected int _index;
  11. protected string _groupPartner;
  12. protected bool _aesAvailable;
  13. protected TransmissionMode _transmissionMode = HomeMatic.TransmissionMode.Default;
  14. protected bool _visible;
  15. protected bool _readyConfig;
  16. protected bool _operate;
  17. protected HMDevice _device;
  18. protected HMRoom _room;
  19. public HMChannel(HMApi Api, HMDevice Device) : base(Api) {
  20. this._device = Device;
  21. }
  22. public HMChannel(HMApi Api, HMDevice Device, XmlNode Data) :base(Api, Data) {
  23. this._device = Device;
  24. this.Init(Data);
  25. }
  26. [Browsable(true), Category("Device"), Description("")]
  27. public bool SystemChannel {
  28. get {
  29. if (this._device == null)
  30. return false;
  31. return this._device.SystemChannel == this._ise_id;
  32. }
  33. }
  34. public void Init(XmlNode Data) {
  35. //this._name = this.Attr_String(Data, "name");
  36. //this._ise_id = this.Attr_Int32(Data, "ise_id");
  37. this._address = this.Attr_String(Data, "address");
  38. this._direction = this.Attr_Direction(Data, "direction");
  39. this._parentDevice = this.Attr_Int32(Data, "parent_device");
  40. this._index = this.Attr_Int32(Data, "index");
  41. this._groupPartner = this.Attr_String(Data, "group_partner");
  42. this._aesAvailable = this.Attr_Bool(Data, "aes_available");
  43. this._transmissionMode = this.Attr_TransmissionMode(Data, "transmission_mode");
  44. this._visible = this.Attr_Bool(Data, "visible");
  45. this._readyConfig = this.Attr_Bool(Data, "ready_config");
  46. this._operate = this.Attr_Bool(Data, "operate");
  47. }
  48. [Browsable(true), Category("Channel"), Description("")]
  49. public int Type {
  50. get { return this._type; }
  51. }
  52. [Browsable(true), Category("Channel"), Description("")]
  53. public string Address {
  54. get { return this._address; }
  55. }
  56. [Browsable(true), Category("Channel"), Description("")]
  57. public HomeMatic.Direction Direction {
  58. get { return this._direction; }
  59. }
  60. [Browsable(true), Category("Device"), Description("")]
  61. public int ParentDevice {
  62. get { return this._parentDevice; }
  63. }
  64. [Browsable(true), Category("Channel"), Description("")]
  65. public int Index {
  66. get { return this._index; }
  67. }
  68. [Browsable(true), Category("Group"), Description("")]
  69. public string GroupPartner {
  70. get { return this._groupPartner; }
  71. }
  72. [Browsable(true), Category("Security"), Description("")]
  73. public bool AES_Available {
  74. get { return this._aesAvailable; }
  75. }
  76. [Browsable(true), Category("Channel"), Description("")]
  77. public HomeMatic.TransmissionMode TransmissionMode {
  78. get { return this._transmissionMode; }
  79. }
  80. [Browsable(true), Category("Channel"), Description("")]
  81. public bool Visible {
  82. get { return this._visible; }
  83. }
  84. [Browsable(true), Category("Channel"), Description("")]
  85. public bool ReadyConfig {
  86. get { return this._readyConfig; }
  87. }
  88. [Browsable(true), Category("Channel"), Description("")]
  89. public bool Operate {
  90. get { return this._operate; }
  91. }
  92. [Browsable(true), Category("Device"), Description("")]
  93. public HMDevice Device {
  94. get { return this._device; }
  95. }
  96. [Browsable(true), Category("Device"), Description("")]
  97. public string DeviceName {
  98. get {
  99. if (this._device != null)
  100. return this._device.Name;
  101. return "";
  102. }
  103. }
  104. [Browsable(true), Category("Room"), Description("")]
  105. public HMRoom Room {
  106. get { return this._room; }
  107. }
  108. public HMDataPoint GetDataPoint(string Name) {
  109. HMDataPoint[] dps = Api.GetDataPointList(this);
  110. foreach(HMDataPoint dp in dps) {
  111. if(dp.Channel.IseID == this._ise_id) {
  112. if(dp.Name == Name) {
  113. return dp;
  114. }
  115. }
  116. }
  117. return null;
  118. }
  119. public HMDataPoint GetDataPoint(int IseID) {
  120. HMDataPoint[] dps = Api.GetDataPointList(this);
  121. foreach (HMDataPoint dp in dps) {
  122. if (dp.Channel.IseID == this._ise_id) {
  123. if (dp.IseID == IseID) {
  124. return dp;
  125. }
  126. }
  127. }
  128. return null;
  129. }
  130. [Browsable(true), Category("DataPoint"), Description("")]
  131. public string Value {
  132. get {
  133. HMDataPoint[] dps = Api.GetDataPointList(this);
  134. foreach(HMDataPoint dp in dps) {
  135. if(dp.DataType == DataPoint_Type.State) {
  136. return dp.Value;
  137. }
  138. }
  139. return null;
  140. }
  141. set {
  142. HMDataPoint[] dps = Api.GetDataPointList(this);
  143. foreach (HMDataPoint dp in dps) {
  144. if (dp.DataType == DataPoint_Type.State) {
  145. dp.Value = value;
  146. }
  147. }
  148. }
  149. }
  150. public HMDataPoint GetDataPoint(DataPoint_Type _type) {
  151. //System.Diagnostics.Debug.WriteLine("GetDataPoint("+_type.ToString()+")");
  152. HMDataPoint[] dps = Api.GetDataPointList(this);
  153. //System.Diagnostics.Debug.WriteLine(" count: "+dps.Length.ToString());
  154. int counter = 0;
  155. foreach (HMDataPoint dp in dps) {
  156. counter++;
  157. //System.Diagnostics.Debug.WriteLine(" [" + counter.ToString()+"]");
  158. //System.Diagnostics.Debug.WriteLine(" ise: " + dp.IseID);
  159. //System.Diagnostics.Debug.WriteLine(" name: " + dp.Name);
  160. //System.Diagnostics.Debug.WriteLine(" type: " + dp.DataType.ToString());
  161. if (dp.Channel.IseID == this._ise_id) {
  162. if (dp.DataType == _type) {
  163. return dp;
  164. }
  165. }
  166. }
  167. return null;
  168. }
  169. private HMDataPoint[] _datapointList;
  170. private bool _initDatapointList = false;
  171. [Browsable(true), Category("DataPoint"), Description("")]
  172. public HMDataPoint[] DataPoints {
  173. get {
  174. if (this._initDatapointList == false)
  175. this.InitDataPointList();
  176. return this._datapointList;
  177. }
  178. }
  179. private void InitDataPointList() {
  180. List<HMDataPoint> res = new List<HMDataPoint>();
  181. foreach (HMDataPoint dp in this._api.DataPoints) {
  182. if (dp.Channel.IseID == this._ise_id) {
  183. res.Add(dp);
  184. }
  185. }
  186. this._datapointList = res.ToArray();
  187. this._initDatapointList = true;
  188. }
  189. public void UpdateDataPoints() {
  190. this.InitDataPointList();
  191. }
  192. [Browsable(true), Category("Device"), Description("")]
  193. public DeviceInfo Info {
  194. get { return this.Device.Info; }
  195. }
  196. protected override string GetClassName() {
  197. return "HMChannel";
  198. }
  199. protected override string ValuesToString() {
  200. return this._type.ToString() + ";" +
  201. this._address + ";" +
  202. this.GetDirection_To_String(this._direction) + ";" +
  203. this._index.ToString() + ";" +
  204. this._groupPartner + ";" +
  205. (this._aesAvailable ? "true" : "false") + ";" +
  206. this.GetTransmissionMode_To_String(this._transmissionMode) + ";" +
  207. (this._visible ? "true" : "false") + ";" +
  208. (this._readyConfig ? "true" : "false") + ";" +
  209. (this._operate ? "true" : "false") + ";";
  210. }
  211. }
  212. }