| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- using System.Xml;
- using System.Collections.Generic;
- namespace System.Net.HomeMatic {
- public class HMDevice : HMBase {
- /*
- Thermostat Error F2
- <device name="Thermo_Eins" address="PEQ1316939" ise_id="2826" interface="BidCos-RF" device_type="HM-CC-RT-DN" ready_config="true">
- <channel name="HM-CC-RT-DN PEQ1316939:1" type="22" address="PEQ1316939:1" ise_id="2856" direction="RECEIVER" parent_device="2826" index="1" group_partner="" aes_available="false" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- <channel name="HM-CC-RT-DN PEQ1316939:2" type="17" address="PEQ1316939:2" ise_id="2857" direction="RECEIVER" parent_device="2826" index="2" group_partner="" aes_available="false" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- <channel name="HM-CC-RT-DN PEQ1316939:3" type="26" address="PEQ1316939:3" ise_id="2858" direction="RECEIVER" parent_device="2826" index="3" group_partner="" aes_available="true" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- <channel name="HM-CC-RT-DN PEQ1316939:4" type="17" address="PEQ1316939:4" ise_id="2859" direction="SENDER" parent_device="2826" index="4" group_partner="" aes_available="false" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- <channel name="HM-CC-RT-DN PEQ1316939:5" type="17" address="PEQ1316939:5" ise_id="2903" direction="RECEIVER" parent_device="2826" index="5" group_partner="" aes_available="true" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- <channel name="HM-CC-RT-DN PEQ1316939:6" type="17" address="PEQ1316939:6" ise_id="2904" direction="RECEIVER" parent_device="2826" index="6" group_partner="" aes_available="true" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- </device>
- Thermostat Fehlerfrei
- <device name="Thermo_Eins" address="PEQ1316939" ise_id="2826" interface="BidCos-RF" device_type="HM-CC-RT-DN" ready_config="true">
- <channel name="HM-CC-RT-DN PEQ1316939:1" type="22" address="PEQ1316939:1" ise_id="2856" direction="RECEIVER" parent_device="2826" index="1" group_partner="" aes_available="false" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- <channel name="HM-CC-RT-DN PEQ1316939:2" type="17" address="PEQ1316939:2" ise_id="2857" direction="RECEIVER" parent_device="2826" index="2" group_partner="" aes_available="false" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- <channel name="HM-CC-RT-DN PEQ1316939:3" type="26" address="PEQ1316939:3" ise_id="2858" direction="RECEIVER" parent_device="2826" index="3" group_partner="" aes_available="true" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- <channel name="HM-CC-RT-DN PEQ1316939:4" type="17" address="PEQ1316939:4" ise_id="2859" direction="SENDER" parent_device="2826" index="4" group_partner="" aes_available="false" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- <channel name="HM-CC-RT-DN PEQ1316939:5" type="17" address="PEQ1316939:5" ise_id="2903" direction="RECEIVER" parent_device="2826" index="5" group_partner="" aes_available="true" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- <channel name="HM-CC-RT-DN PEQ1316939:6" type="17" address="PEQ1316939:6" ise_id="2904" direction="RECEIVER" parent_device="2826" index="6" group_partner="" aes_available="true" transmission_mode="DEFAULT" visible="true" ready_config="true" operate="true"/>
- </device>
- */
- private string _address;
- private string _interface;
- private string _deviceType;
- private bool _readyConfig;
- private bool _unreach;
- private bool _stickyUnreach;
- private bool _configPending;
- //private List<HMChannel> _channels;
- private int _systemChannel = 0;
- public HMDevice(HMApi Api) : base(Api) {
-
- }
- public HMDevice(HMApi Api, XmlNode Data) : base(Api, Data) {
- this.Init(Data);
- }
- public void Init(XmlNode Data) {
- this._address = this.Attr_String(Data, "address");
- this._interface = this.Attr_String(Data, "interface");
- this._deviceType = this.Attr_String(Data, "device_type");
- this._readyConfig = this.Attr_Bool(Data, "ready_config");
- this._unreach = this.Attr_Bool(Data, "unreach");
- this._stickyUnreach = this.Attr_Bool(Data, "sticky_unreach");
- this._configPending = this.Attr_Bool(Data, "config_pending");
- }
- public string Address {
- get { return this._address; }
- }
- public string Interface {
- get { return this._interface; }
- }
- public string DeviceType {
- get { return this._deviceType; }
- }
- public bool ReadyConfig {
- get { return this._readyConfig; }
- }
- public bool Unreach {
- get { return this._unreach; }
- }
- public bool StickyUnreach {
- get { return this._stickyUnreach; }
- }
- public bool ConfigPending {
- get { return this._configPending; }
- }
- private HMChannel[] _channelList;
- private bool _initChannelList = false;
- public HMChannel[] Channels {
- get {
- if (this._initChannelList == false)
- this.InitChannelList();
- return this._channelList;
- }
- }
- private void InitChannelList() {
- List<HMChannel> res = new List<HMChannel>();
- foreach(HMChannel ch in this._api.Channels) {
- if (ch.Device.IseID == this._ise_id) {
- res.Add(ch);
- }
- }
- this._channelList = res.ToArray();
- this._initChannelList = true;
- }
- public void UpdateChannels() {
- this.InitChannelList();
- }
- public int SystemChannel {
- get {
- if(this._systemChannel<1) {
- this.UpdateDeviceInfo();
- }
- return this._systemChannel;
- }
- }
- private DateTime _lastDeviceInfoUpdate;
- private DeviceInfo _lastDeviceInfo;
- public DeviceInfo Info {
- get {
- TimeSpan ts = DateTime.Now - this._lastDeviceInfoUpdate;
- if (ts.TotalSeconds > 3) {
- this.UpdateDeviceInfo();
- }
- return this._lastDeviceInfo;
- }
- }
- public void UpdateDeviceInfo() {
- XmlDocument doc = this._api.GetApiData(ApiMethode.State, new Dictionary<string, object>() {["device_id"] = this._ise_id });
- XmlNodeList childs = doc.ChildNodes[1].ChildNodes;
- int c = childs.Count;
- this._lastDeviceInfoUpdate = DateTime.Now;
- if (this._systemChannel < 1) {
- if (c > 0)
- for (int i = 0; i < c; i++)
- if (childs[i].Name == "channel")
- if (childs[i].HasChildNodes) {
- int cc = childs[i].ChildNodes.Count;
- int matches = 0;
- for (int j = 0; j < cc; j++) {
- if (childs[i].ChildNodes[j].Name == "datapoint") {
- if (
- childs[i].ChildNodes[j].Attributes["type"].Value.ToUpper() == "UNREACH" ||
- childs[i].ChildNodes[j].Attributes["type"].Value.ToUpper() == "STICKY_UNREACH" ||
- childs[i].ChildNodes[j].Attributes["type"].Value.ToUpper() == "CONFIG_PENDING" ||
- childs[i].ChildNodes[j].Attributes["type"].Value.ToUpper() == "RSSI_DEVICE" ||
- childs[i].ChildNodes[j].Attributes["type"].Value.ToUpper() == "LOWBAT" ||
- childs[i].ChildNodes[j].Attributes["type"].Value.ToUpper() == "RSSI_PEER" ||
- childs[i].ChildNodes[j].Attributes["type"].Value.ToUpper() == "DEVICE_IN_BOOTLOADER" ||
- childs[i].ChildNodes[j].Attributes["type"].Value.ToUpper() == "UPDATE_PENDING"
- ) {
- matches++;
- }
- }
- }
- if (matches > 1) {
- DeviceInfo nfo = new DeviceInfo();
- nfo.Data(childs[i]);
- this._systemChannel = Convert.ToInt32(childs[i].Attributes["ise_id"].Value);
- this._lastDeviceInfo = nfo;
- return;
- }
- }
- } else {
- if (c > 0) {
- for (int k = 0; k < c; k++) {
- if (childs[k].Name == "channel" && Convert.ToInt32(childs[k].Attributes["ise_id"].Value) == this._systemChannel) {
- DeviceInfo nfo = new DeviceInfo();
- nfo.Data(childs[k]);
- this._lastDeviceInfo = nfo;
- return;
- }
- }
- }
- }
- }
- protected override string GetClassName() {
- return "HMDevice";
- }
- protected override string ValuesToString() {
- return this._address + ";" +
- this._interface + ";" +
- this._deviceType + ";" +
- (this._readyConfig ? "true" : "false") + ";" +
- (this._unreach ? "true" : "false") + ";" +
- (this._stickyUnreach ? "true" : "false") + ";" +
- (this._configPending ? "true" : "false") + ";";
- }
- // exp: Device ID: 1502, Channel ID: 1531
- }
- }
|