From d7ad5a3953a8cd001659092ebde204b881f94b9d Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期四, 31 十月 2019 10:47:13 +0800
Subject: [PATCH] 2019-10-31-1

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs |  699 ++++++---------------------------------------------------
 1 files changed, 80 insertions(+), 619 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
index b4435dd..a9bb880 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
@@ -9,7 +9,7 @@
 using System.Net;
 using Newtonsoft.Json.Linq;
 using MQTTnet.Core.Client;
-//using MQTTnet;
+using MQTTnet;
 using Shared.Common;
 using Shared.Phone.UserView;
 
@@ -98,12 +98,7 @@
             }
         }
 
-        #region variable
-        /// <summary>
-        ///  杩滅▼鏄惁琚尋涓嬬嚎銆傞粯璁よ繙绋嬫病鏈夎鎸や笅绾跨殑
-        /// </summary>
-        public static bool IsRemoteBeingSqueezedOffline = false;
-
+        #region variable 
         /// <summary>
         /// 杩滅▼杩炴帴鎴愬姛鏃剁殑鏃堕棿
         /// </summary>
@@ -226,7 +221,6 @@
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� DDevice/IsGetEpointInfo:鏈夋柊璁惧鍔犲叆zigbee缃戠粶鍙嶉</para>璁惧璇锋眰APP鑾峰彇鍗囩骇鏁版嵁
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� Device/DeviceJoinZbNet:鑾峰彇鏂拌澶囨墍鏈夌鐐逛俊鎭槸鍚︽垚鍔熷弽棣�</para>
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� DeviceRequestAcUpdateData: 璁惧璇锋眰绌鸿皟鍙戝崌绾ф暟鎹�</para>
-        /// "宸茬粡閫氱煡");//宸茬粡閫氱煡");
         /// </summary>
         [Newtonsoft.Json.JsonIgnore]
         public Action<string, object> ReportAction;
@@ -3110,7 +3104,7 @@
                         if (mqttClient == null)
                         {
                             //(2)鍒涘缓Mqtt瀹㈡埛绔�
-                            mqttClient = new MQTTnet.MqttClientFactory().CreateMqttClient();
+                            mqttClient = new MqttClientFactory().CreateMqttClient();
                             //(3)褰揫杩炴帴Mqtt鎴愬姛鍚嶿鎴栬�匸Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒版暟鎹寘鍝嶅簲鏃跺湪mqttClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊
                             mqttClient.ApplicationMessageReceived += (sender, e) =>
                             {
@@ -3210,7 +3204,7 @@
             {
                 try
                 {
-                    if (remoteMqttIsConnecting)
+                    if (remoteMqttIsConnecting || Shared.Common.Config.Instance.HomeId == "")
                     {
                         return;
                     }
@@ -3219,12 +3213,13 @@
                     var url = Shared.Common.Config.Instance.ZigbeeMqttBrokerLoadSubDomain;//.Replace("6688","6689");
                     if (string.IsNullOrEmpty(url) || !url.StartsWith("tcp://") || url.Split(':').Length != 3)
                     {
+                        remoteMqttIsConnecting = false;
                         return;
                     }
                     if (RemoteMqttClient == null)
                     {
                         //(2)鍒涘缓Mqtt瀹㈡埛绔�
-                        RemoteMqttClient = new MQTTnet.MqttClientFactory().CreateMqttClient();
+                        RemoteMqttClient = new MqttClientFactory().CreateMqttClient();
                         //(3)褰揫杩炴帴浜戠鐨凪qtt鎴愬姛鍚嶿鎴栬�匸浠ュ強鍚庨潰App閫氳繃浜戠Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒颁簯绔暟鎹寘鍝嶅簲鏃跺湪mqttServerClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊
                         RemoteMqttClient.ApplicationMessageReceived += (sender, e) =>
                         {
@@ -3306,7 +3301,7 @@
 
                     //杩樻湁绉嶆儏鍐垫槸鍚屼竴涓狪D 鏈夊涓澶囩敤杩欎釜id杩炴帴锛堜細瀵艰嚧涓柇锛�
                     string clientId = Shared.Common.Config.Instance.ConnectZigbeeMqttClientId;
-                    string username = Shared.Common.Config.Instance.ConnectZigbeeMqttBrokerName;
+                    string username = Shared.Common.Config.Instance.ConnectGuid;
                     string passwordRemote = Shared.Common.Config.Instance.ConnectZigbeeMqttBrokerPwd;
                     //(1)杩炴帴鍒颁簯绔殑Mqtt瀹㈡埛绔繛鎺ュ弬鏁�
                     var connectCloudMqttClientOptions = new MqttClientTcpOptions
@@ -3320,11 +3315,12 @@
                         KeepAlivePeriod = new TimeSpan(0, 5, 0),//璁剧疆蹇冭烦鏃堕棿锛堟渶澶у�硷紝2^16-1 = 65535绉� = 18灏忔椂銆傛渶灏忓�煎彲浠ヤ负0锛岃〃绀哄鎴风涓嶆柇寮�銆備竴鑸涓哄嚑鍒嗛挓锛屾瘮濡傚井淇″績璺冲懆鏈熶负300绉掋�傦級
                         DefaultCommunicationTimeout = new TimeSpan(0, 0, 100),//璁剧疆瓒呮椂鏃堕棿
                     };
-                    //杩滅▼閫氳杩炴帴锛岃繛鎺ヤ簯绔湇鍔″櫒
-                    if (ZigBee.Device.ZbGateway.IsRemoteBeingSqueezedOffline == false)
-                    {
-                        await RemoteMqttClient.ConnectAsync(connectCloudMqttClientOptions);
+                    //杩滅▼閫氳杩炴帴锛岃繛鎺ヤ簯绔湇鍔″櫒 
+                    if (RemoteMqttClient != null)
+                    {
+                        await RemoteMqttClient.ConnectAsync(connectCloudMqttClientOptions);
                     }
+
                 }
                 catch (Exception ex)
                 {
@@ -3391,15 +3387,9 @@
         /// </summary>
         async System.Threading.Tasks.Task SendRemoteMsg(string topicName, byte[] message, MQTTnet.Core.Protocol.MqttQualityOfServiceLevel qosLevel = MQTTnet.Core.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, bool retain = false)
         {
-            #region MD5鍔犲瘑 token
-            var result = System.Text.Encoding.UTF8.GetBytes(Shared.Common.Config.Instance.Password);
-            var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
-            var output = md5.ComputeHash(result);
-            var md5Password = BitConverter.ToString(output).Replace("-", "").ToUpper();
-            #endregion
-
             //(1)鐢熸垚[鐢ㄦ埛鍚�:瀵嗙爜]
-            var userNameAndPwdStr = string.Concat(Shared.Common.Config.Instance.Account, RemoteOperatorConsts.CAP_NUMBER, md5Password);
+            var userNameAndPwdStr = string.Concat(Shared.Common.Config.Instance.Guid, RemoteOperatorConsts.CAP_NUMBER, Shared.Common.Config.Instance.MD5PWD);
+            DebugPrintLog($"userNameAndPwdStr锛歿userNameAndPwdStr} ");
 
             //(2)灏�(1)杞垚Base64瀛楃涓�,鐢熸垚鏍煎紡[Base64(鐢ㄦ埛鍚�:瀵嗙爜)]
             var userNameAndPwdStrBaseSexFour = Convert.ToBase64String(ZigBee.Common.CommonInfo.EncodingUTF8.GetBytes(userNameAndPwdStr));
@@ -3407,16 +3397,17 @@
             //(3)灏�(2)缁х画鐢熸垚鏍煎紡[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp]
             var userNameAndPwdStrBaseSexFourAndTimestamp = string.Concat(userNameAndPwdStrBaseSexFour, RemoteOperatorConsts.CAP_NUMBER, CurrentTimeStamp.ToString());
 
-            ///[Zigbee.Buspro]App/id(甯愬彿Id)/Base64(DES[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp ]/缃戝叧鍞竴Id/杞彂缁欑綉鍏崇殑涓婚/XX/XX
+            //[Zigbee.Buspro]App/id(甯愬彿Id)/Base64(DES[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp ]/缃戝叧鍞竴Id/杞彂缁欑綉鍏崇殑涓婚/XX/XX
             //(4)鐢熸垚涓婃姤涓婚锛屼富棰樻ā寮忛渶瑕佷负  /ZigbeeApp/id(涓诲瓙璋冭瘯甯愬彿Id)/Base64(DES[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp ]/缃戝叧鍞竴Id/topicName "000204022022"   GateWayId  000204022022
-            var reportTopic = string.Format("/{0}/{1}/{2}/{3}/{4}", RemoteOperatorConsts.ZIGBEE_APP_STARTS_WITH, Shared.Common.Config.Instance.Account, userNameAndPwdStrBaseSexFourAndTimestamp, this.getGatewayBaseInfo?.gwID, topicName);
+            var reportTopic = string.Format("/{0}/{1}/{2}/{3}/{4}", RemoteOperatorConsts.ZIGBEE_APP_STARTS_WITH, Shared.Common.Config.Instance.Guid, userNameAndPwdStrBaseSexFourAndTimestamp, this.getGatewayBaseInfo?.gwID, topicName);
+            var aa = System.Text.Encoding.UTF8.GetString(message);
 
-            //(5)浣跨敤浣犵櫥褰曟垚鍔熸椂8浣峩ey锛岃繘琛孌ES鍔犲瘑浣犻渶瑕佷笂鎶ョ殑鏁版嵁
             string topicEncStr = reportTopic;
             //鏂囦欢娴佷笉鐢ㄥ姞瀵�
             topicEncStr = ZigBee.Common.SecuritySet.AesEncrypt(System.Text.Encoding.UTF8.GetBytes(topicEncStr), Shared.Common.Config.Instance.MqttKey);
             topicEncStr = topicEncStr.Replace("/", "[[$-MQTT_TILT_SYMBOL_REPLACE-$]]").Replace("+", "[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]");
             message = System.Text.Encoding.UTF8.GetBytes(SecuritySet.AesEncrypt(message, Shared.Common.Config.Instance.MqttKey));
+            var bb = System.Text.Encoding.UTF8.GetString(message);
 
             //(6)鏋勫缓Mqtt闇�瑕佸彂甯冪殑鏁版嵁鍖�,鍙戝竷缁欎簯绔殑MqttBroker
             await RemoteMqttClient.PublishAsync(new MQTTnet.Core.MqttApplicationMessage(topicEncStr, message, qosLevel, retain));
@@ -3434,12 +3425,18 @@
         {
             try
             {
+                if (Shared.Common.Config.Instance.HomeId == "")
+                {
+                    return;
+                }
+
                 if (IsRemote)
                 {
+
+                    await SendRemoteMsg(topic, message, qosLevel, retain);
 #if DEBUG
                     DebugPrintLog($"杩滅▼ 鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")
-#endif
-                    await SendRemoteMsg(topic, message, qosLevel, retain);
+#endif            
                 }
                 else
                 {
@@ -3525,7 +3522,6 @@
                     //浜戠涓殑褰撳墠杩炴帴琚尋涓嬬嚎锛岄渶瑕侀�氱煡app
                     //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
                     message = "BeingSqueezedOffline";
-                    ZigBee.Device.ZbGateway.IsRemoteBeingSqueezedOffline = true;
                     Shared.Phone.UserCenter.HdlGatewayReceiveLogic.GatewayOverallMsgReceive("", topic, null);
                     DebugPrintLog($"琚尋涓嬬嚎閫氱煡:{ topic}_杩滅▼杩斿洖鐨勬暟鎹甠{message}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")
                     return;
@@ -3822,344 +3818,43 @@
                 if (topic == gatewayID + "/" + "DeviceInComingRespon")
                 {
                     //鏂拌澶囦笂鎶ワ紝閲嶆柊鍙戣幏鍙栨墍鏈夌殑璁惧
-                    var deviceID = jobject.Value<int>("Device_ID");
-                    switch ((DeviceType)(deviceID))
-                    {
-                        case DeviceType.DimmableLight:
-                            var dimmableLight = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            dimmableLight.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.NewDeviceInfoData>(jobject["Data"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
-                                gwa.ReportAction("DeviceInComingRespon", dimmableLight.getNewDeviceInfo);
-                            }
-                            UpdateDeviceInfo(dimmableLight, "DeviceInComingRespon");
-                            UpdateDeviceStatus(gwa);
-                            break;
-                        case DeviceType.OnOffOutput:
-                            var toggleLight = new ToggleLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            toggleLight.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.NewDeviceInfoData>(jobject["Data"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
-                                gwa.ReportAction("DeviceInComingRespon", toggleLight.getNewDeviceInfo);
-                            }
-                            UpdateDeviceInfo(toggleLight, "DeviceInComingRespon");
-                            UpdateDeviceStatus(gwa);
-                            break;
-                        case DeviceType.AirSwitch:
-                            var airSwitch = new AirSwitch() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            airSwitch.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.NewDeviceInfoData>(jobject["Data"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
-                                gwa.ReportAction("DeviceInComingRespon", airSwitch.getNewDeviceInfo);
-                            }
-                            UpdateDeviceInfo(airSwitch, "DeviceInComingRespon");
-                            UpdateDeviceStatus(gwa);
-                            break;
-                        case DeviceType.OnOffSwitch:
-                            var panel = new Panel() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            panel.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.NewDeviceInfoData>(jobject["Data"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
-                                gwa.ReportAction("DeviceInComingRespon", panel.getNewDeviceInfo);
-                            }
-                            UpdateDeviceInfo(panel, "DeviceInComingRespon");
-                            UpdateDeviceStatus(gwa);
-                            break;
-                        case DeviceType.WindowCoveringDevice:
-                            var curtain = new Rollershade() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            curtain.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.NewDeviceInfoData>(jobject["Data"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
-                                gwa.ReportAction("DeviceInComingRespon", curtain.getNewDeviceInfo);
-                            }
-                            UpdateDeviceInfo(curtain, "DeviceInComingRespon");
-                            UpdateDeviceStatus(gwa);
-                            break;
-                        case DeviceType.IASZone:
-                            var ias = new IASZone() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            ias.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.NewDeviceInfoData>(jobject["Data"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
-                                gwa.ReportAction("DeviceInComingRespon", ias.getNewDeviceInfo);
-                            }
-                            UpdateDeviceInfo(ias, "DeviceInComingRespon");
-                            UpdateDeviceStatus(gwa);
-                            break;
-                        case DeviceType.Repeater:
-                            var repeater = new Repeater() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            repeater.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater.NewDeviceInfoData>(jobject["Data"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
-                                gwa.ReportAction("DeviceInComingRespon", repeater.getNewDeviceInfo);
-                            }
-                            UpdateDeviceInfo(repeater, "DeviceInComingRespon");
-                            UpdateDeviceStatus(gwa);
-                            break;
-                        case DeviceType.Thermostat:
-                            var ac = new AC() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            ac.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.NewDeviceInfoData>(jobject["Data"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
-                                gwa.ReportAction("DeviceInComingRespon", ac.getNewDeviceInfo);
-                            }
-                            UpdateDeviceInfo(ac, "DeviceInComingRespon");
-                            UpdateDeviceStatus(gwa);
-                            break;
-                        case DeviceType.Transverter:
-                            var transverter = new Transverter() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            transverter.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter.NewDeviceInfoData>(jobject["Data"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
-                                gwa.ReportAction("DeviceInComingRespon", transverter.getNewDeviceInfo);
-                            }
-                            UpdateDeviceInfo(transverter, "DeviceInComingRespon");
-                            UpdateDeviceStatus(gwa);
-                            break;
-                    }
+                    var tempDevice = new CommonDevice() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
+                    tempDevice.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.NewDeviceInfoData>(jobject["Data"].ToString());
+                    if (gwa.ReportAction != null)
+                    {
+                        DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
+                        gwa.ReportAction("DeviceInComingRespon", tempDevice.getNewDeviceInfo);
+                    }
+                    UpdateDeviceInfo(tempDevice, "DeviceInComingRespon");
+                    UpdateDeviceStatus(gwa);
                 }
                 #endregion
                 #region 璁惧鍦ㄧ嚎鐘舵�佹洿鏂板弽棣�
                 else if (topic == gatewayID + "/" + "OnlineStatusChange_Respon")
                 {
-                    var deviceID = jobject.Value<int>("Device_ID");
-                    switch ((DeviceType)(deviceID))
-                    {
-                        case DeviceType.DimmableLight:
-                            var dimmableLight = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            dimmableLight.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
-                                gwa.ReportAction("OnlineStatusChange", dimmableLight);
-                            }
-                            var lightDimmer = gwa.DeviceList.Find(obj => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr);
-                            if (lightDimmer == null)
-                            {
-                                gwa.DeviceList.Add(dimmableLight);
-                                UpdateDeviceStatus(dimmableLight);
-                                UpdateDeviceInfo(dimmableLight, "OnlineStatusChange");
-                            }
-                            else
-                            {
-                                if (dimmableLight.DeviceInfo != null)
-                                {
-                                    dimmableLight.DeviceInfo.IsOnline = dimmableLight.IsOnline;
-                                }
-                                UpdateDeviceInfo(dimmableLight, "OnlineStatusChange");
-                                UpdateDeviceStatus(dimmableLight);
-                            }
-
-                            break;
-                        case DeviceType.OnOffOutput:
-                            var toggleLight = new ToggleLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            toggleLight.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
-                                gwa.ReportAction("OnlineStatusChange", toggleLight);
-                            }
-                            var toggleInfo = gwa.DeviceList.Find(obj => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr);
-                            if (toggleInfo == null)
-                            {
-                                gwa.DeviceList.Add(toggleLight);
-                                UpdateDeviceInfo(toggleLight, "OnlineStatusChange");
-                                UpdateDeviceStatus(toggleLight);
-                            }
-                            else
-                            {
-                                if (toggleLight.DeviceInfo != null)
-                                {
-                                    toggleLight.DeviceInfo.IsOnline = toggleLight.IsOnline;
-                                }
-                                UpdateDeviceInfo(toggleLight, "OnlineStatusChange");
-                                UpdateDeviceStatus(toggleLight);
-                            }
-                            break;
-                        case DeviceType.AirSwitch:
-                            var airSwitch = new AirSwitch() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            airSwitch.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
-                                gwa.ReportAction("OnlineStatusChange", airSwitch);
-                            }
-                            var airSwitchInfo = gwa.DeviceList.Find(obj => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr);
-                            if (airSwitchInfo == null)
-                            {
-                                gwa.DeviceList.Add(airSwitch);
-                                UpdateDeviceInfo(airSwitch, "OnlineStatusChange");
-                                UpdateDeviceStatus(gwa);
-                            }
-                            else
-                            {
-                                if (airSwitchInfo.DeviceInfo != null)
-                                {
-                                    airSwitchInfo.DeviceInfo.IsOnline = airSwitchInfo.IsOnline;
-                                }
-                                UpdateDeviceInfo(airSwitchInfo, "OnlineStatusChange");
-                                UpdateDeviceStatus(airSwitchInfo);
-                            }
-                            break;
-                        case DeviceType.OnOffSwitch:
-                            var panel = new Panel() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            panel.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
-                                gwa.ReportAction("OnlineStatusChange", panel);
-                            }
-                            var panelInfo = gwa.DeviceList.Find(obj => obj.DeviceID == panel.DeviceID && obj.DeviceAddr == panel.DeviceAddr);
-                            if (panelInfo == null)
-                            {
-                                gwa.DeviceList.Add(panel);
-                                UpdateDeviceInfo(panel, "OnlineStatusChange");
-                                UpdateDeviceStatus(panel);
-                            }
-                            else
-                            {
-                                if (panelInfo.DeviceInfo != null)
-                                {
-                                    panelInfo.DeviceInfo.IsOnline = panelInfo.IsOnline;
-                                }
-                                UpdateDeviceInfo(panelInfo, "OnlineStatusChange");
-                                UpdateDeviceStatus(panelInfo);
-                            }
-                            break;
-                        case DeviceType.WindowCoveringDevice:
-                            var curtain = new Rollershade() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            curtain.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
-                                gwa.ReportAction("OnlineStatusChange", curtain);
-                            }
-                            var curtainInfo = gwa.DeviceList.Find(obj => obj.DeviceID == curtain.DeviceID && obj.DeviceAddr == curtain.DeviceAddr);
-                            if (curtainInfo == null)
-                            {
-                                gwa.DeviceList.Add(curtain);
-                                UpdateDeviceInfo(curtain, "OnlineStatusChange");
-                                UpdateDeviceStatus(gwa);
-                            }
-                            else
-                            {
-                                if (curtain.DeviceInfo != null)
-                                {
-                                    curtain.DeviceInfo.IsOnline = curtain.IsOnline;
-                                }
-                                UpdateDeviceStatus(curtain);
-                                UpdateDeviceInfo(curtain, "OnlineStatusChange");
-                            }
-                            break;
-                        case DeviceType.IASZone:
-                            var ias = new IASZone() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            ias.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
-                                gwa.ReportAction("OnlineStatusChange", ias);
-                            }
-                            var iasInfo = gwa.DeviceList.Find(obj => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr);
-                            if (iasInfo == null)
-                            {
-                                gwa.DeviceList.Add(iasInfo);
-                                UpdateDeviceInfo(iasInfo, "OnlineStatusChange");
-                                UpdateDeviceStatus(gwa);
-                            }
-                            else
-                            {
-                                if (iasInfo.DeviceInfo != null)
-                                {
-                                    iasInfo.DeviceInfo.IsOnline = iasInfo.IsOnline;
-                                }
-                                UpdateDeviceInfo(iasInfo, "OnlineStatusChange");
-                                UpdateDeviceStatus(iasInfo);
-                            }
-                            break;
-                        case DeviceType.Repeater:
-                            var repeater = new Repeater() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            repeater.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
-                                gwa.ReportAction("OnlineStatusChange", repeater);
-                            }
-                            var repeaterInfo = gwa.DeviceList.Find(obj => obj.DeviceID == repeater.DeviceID && obj.DeviceAddr == repeater.DeviceAddr);
-                            if (repeaterInfo == null)
-                            {
-                                gwa.DeviceList.Add(repeaterInfo);
-                                UpdateDeviceInfo(repeaterInfo, "OnlineStatusChange");
-                                UpdateDeviceStatus(gwa);
-                            }
-                            else
-                            {
-                                if (repeaterInfo.DeviceInfo != null)
-                                {
-                                    repeaterInfo.DeviceInfo.IsOnline = repeaterInfo.IsOnline;
-                                }
-                                UpdateDeviceInfo(repeaterInfo, "OnlineStatusChange");
-                                UpdateDeviceStatus(repeaterInfo);
-                            }
-                            break;
-                        case DeviceType.Thermostat:
-                            var ac = new AC() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            ac.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
-                                gwa.ReportAction("OnlineStatusChange", ac);
-                            }
-                            var acInfo = gwa.DeviceList.Find(obj => obj.DeviceID == ac.DeviceID && obj.DeviceAddr == ac.DeviceAddr);
-                            if (acInfo == null)
-                            {
-                                gwa.DeviceList.Add(acInfo);
-                                UpdateDeviceInfo(acInfo, "OnlineStatusChange");
-                                UpdateDeviceStatus(gwa);
-                            }
-                            else
-                            {
-                                if (acInfo.DeviceInfo != null)
-                                {
-                                    acInfo.DeviceInfo.IsOnline = acInfo.IsOnline;
-                                }
-                                UpdateDeviceInfo(acInfo, "OnlineStatusChange");
-                                UpdateDeviceStatus(acInfo);
-                            }
-                            break;
-                        case DeviceType.Transverter:
-                            var transverter = new Transverter() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                            transverter.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-                            if (gwa.ReportAction != null)
-                            {
-                                DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
-                                gwa.ReportAction("OnlineStatusChange", transverter);
-                            }
-                            var transverterInfo = gwa.DeviceList.Find(obj => obj.DeviceID == transverter.DeviceID && obj.DeviceAddr == transverter.DeviceAddr);
-                            if (transverterInfo == null)
-                            {
-                                gwa.DeviceList.Add(transverterInfo);
-                                UpdateDeviceInfo(transverterInfo, "OnlineStatusChange");
-                                UpdateDeviceStatus(gwa);
-                            }
-                            else
-                            {
-                                if (transverterInfo.DeviceInfo != null)
-                                {
-                                    transverterInfo.DeviceInfo.IsOnline = transverterInfo.IsOnline;
-                                }
-                                UpdateDeviceInfo(transverterInfo, "OnlineStatusChange");
-                                UpdateDeviceStatus(transverterInfo);
-                            }
-                            break;
+                    var tempDevice = new CommonDevice() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
+                    tempDevice.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
+
+                    if (gwa.ReportAction != null)
+                    {
+                        DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
+                        gwa.ReportAction("OnlineStatusChange", tempDevice);
+                    }
+                    var infoTempDevice = gwa.DeviceList.Find(obj => obj.DeviceID == tempDevice.DeviceID && obj.DeviceAddr == tempDevice.DeviceAddr);
+                    if (infoTempDevice == null)
+                    {
+                        gwa.DeviceList.Add(tempDevice);
+                        UpdateDeviceStatus(tempDevice);
+                        UpdateDeviceInfo(tempDevice, "OnlineStatusChange");
+                    }
+                    else
+                    {
+                        if (infoTempDevice.DeviceInfo != null)
+                        {
+                            infoTempDevice.DeviceInfo.IsOnline = infoTempDevice.IsOnline;
+                        }
+                        UpdateDeviceInfo(infoTempDevice, "OnlineStatusChange");
+                        UpdateDeviceStatus(infoTempDevice);
                     }
                 }
                 #endregion
@@ -4177,198 +3872,24 @@
                             {
                                 foreach (var delD in gatewayTemp.removeDeviceResponseData.DeviceList)
                                 {
-                                    var deviceID = delD.Device_ID;
-                                    switch ((DeviceType)(deviceID))
-                                    {
-                                        case DeviceType.OnOffOutput:
-                                            var toggleLight = new ToggleLight() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                                            toggleLight.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.RemoveDeviceResponseData>(jobject["Data"].ToString());
-                                            if (toggleLight.removeDeviceResponseData == null)
-                                            {
-                                                return;
-                                            }
-                                            else
-                                            {
-                                                UpdateDeviceStatus(toggleLight);
-                                                UpdateDeviceInfo(toggleLight, "RemoveDeviceRespon");
-                                                if (toggleLight.removeDeviceResponseData.Result == 0)
-                                                {
-                                                    var infoToggleLight = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr && obj.DeviceEpoint == toggleLight.DeviceEpoint);
-                                                    if (infoToggleLight != null)
-                                                    {
-                                                        gwa.DeviceList.Remove(infoToggleLight);
-                                                    }
-                                                }
-                                            }
-                                            break;
-                                        case DeviceType.AirSwitch:
-                                            var airSwitch = new AirSwitch() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                                            airSwitch.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.RemoveDeviceResponseData>(jobject["Data"].ToString());
-                                            if (airSwitch.removeDeviceResponseData == null)
-                                            {
-                                                return;
-                                            }
-                                            else
-                                            {
-                                                UpdateDeviceStatus(airSwitch);
-                                                UpdateDeviceInfo(airSwitch, "RemoveDeviceRespon");
-                                                if (airSwitch.removeDeviceResponseData.Result == 0)
-                                                {
-                                                    var infoAirSwitch = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr && obj.DeviceEpoint == airSwitch.DeviceEpoint);
-                                                    if (infoAirSwitch != null)
-                                                    {
-                                                        gwa.DeviceList.Remove(infoAirSwitch);
-                                                    }
-                                                }
-                                            }
-                                            break;
-                                        case DeviceType.OnOffSwitch:
-                                            var panelObj = new Panel() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                                            panelObj.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.RemoveDeviceResponseData>(jobject["Data"].ToString());
-                                            if (panelObj.removeDeviceResponseData == null)
-                                            {
-                                                return;
-                                            }
-                                            else
-                                            {
-                                                UpdateDeviceStatus(panelObj);
-                                                UpdateDeviceInfo(panelObj, "RemoveDeviceRespon");
-                                                if (panelObj.removeDeviceResponseData.Result == 0)
-                                                {
-                                                    var infoPanel = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == panelObj.DeviceID && obj.DeviceAddr == panelObj.DeviceAddr && obj.DeviceEpoint == panelObj.DeviceEpoint);
-                                                    if (infoPanel != null)
-                                                    {
-                                                        gwa.DeviceList.Remove(infoPanel);
-                                                    }
-                                                }
-                                            }
-                                            break;
-                                        case DeviceType.WindowCoveringDevice:
-                                            var rollershade = new Rollershade() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                                            rollershade.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.RemoveDeviceResponseData>(jobject["Data"].ToString());
-                                            if (rollershade.removeDeviceResponseData == null)
-                                            {
-                                                return;
-                                            }
-                                            else
-                                            {
-                                                UpdateDeviceStatus(rollershade);
-                                                UpdateDeviceInfo(rollershade, "RemoveDeviceRespon");
-                                                if (rollershade.removeDeviceResponseData.Result == 0)
-                                                {
-                                                    var infoRoller = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == rollershade.DeviceID && obj.DeviceAddr == rollershade.DeviceAddr && obj.DeviceEpoint == rollershade.DeviceEpoint);
-                                                    if (infoRoller != null)
-                                                    {
-                                                        gwa.DeviceList.Remove(infoRoller);
-                                                    }
-                                                }
-                                            }
-                                            break;
-                                        case DeviceType.IASZone:
-                                            var ias = new IASZone() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                                            ias.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.RemoveDeviceResponseData>(jobject["Data"].ToString());
-                                            if (ias.removeDeviceResponseData == null)
-                                            {
-                                                return;
-                                            }
-                                            else
-                                            {
-                                                UpdateDeviceStatus(ias);
-                                                UpdateDeviceInfo(ias, "RemoveDeviceRespon");
-                                                if (ias.removeDeviceResponseData.Result == 0)
-                                                {
-                                                    var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr && obj.DeviceEpoint == ias.DeviceEpoint);
-                                                    if (info != null)
-                                                    {
-                                                        gwa.DeviceList.Remove(info);
-                                                    }
-                                                }
-                                            }
-                                            break;
-                                        case DeviceType.DimmableLight:
-                                            var dimmableLight = new DimmableLight() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                                            dimmableLight.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.RemoveDeviceResponseData>(jobject["Data"].ToString());
-                                            if (dimmableLight.removeDeviceResponseData == null)
-                                            {
-                                                return;
-                                            }
-                                            else
-                                            {
-                                                UpdateDeviceStatus(dimmableLight);
-                                                UpdateDeviceInfo(dimmableLight, "RemoveDeviceRespon");
-                                                if (dimmableLight.removeDeviceResponseData.Result == 0)
-                                                {
-                                                    var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr && obj.DeviceEpoint == dimmableLight.DeviceEpoint);
-                                                    if (info != null)
-                                                    {
-                                                        gwa.DeviceList.Remove(info);
-                                                    }
-                                                }
-                                            }
-                                            break;
-                                        case DeviceType.Repeater:
-                                            var repeater = new Repeater() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                                            repeater.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.RemoveDeviceResponseData>(jobject["Data"].ToString());
-                                            if (repeater.removeDeviceResponseData == null)
-                                            {
-                                                return;
-                                            }
-                                            else
-                                            {
-                                                UpdateDeviceStatus(repeater);
-                                                UpdateDeviceInfo(repeater, "RemoveDeviceRespon");
-                                                if (repeater.removeDeviceResponseData.Result == 0)
-                                                {
-                                                    var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == repeater.DeviceID && obj.DeviceAddr == repeater.DeviceAddr && obj.DeviceEpoint == repeater.DeviceEpoint);
-                                                    if (info != null)
-                                                    {
-                                                        gwa.DeviceList.Remove(info);
-                                                    }
-                                                }
-                                            }
-                                            break;
-                                        case DeviceType.Thermostat:
-                                            var ac = new AC() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                                            ac.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.RemoveDeviceResponseData>(jobject["Data"].ToString());
-                                            if (ac.removeDeviceResponseData == null)
-                                            {
-                                                return;
-                                            }
-                                            else
-                                            {
-                                                UpdateDeviceStatus(ac);
-                                                UpdateDeviceInfo(ac, "RemoveDeviceRespon");
-                                                if (ac.removeDeviceResponseData.Result == 0)
-                                                {
-                                                    var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == ac.DeviceID && obj.DeviceAddr == ac.DeviceAddr && obj.DeviceEpoint == ac.DeviceEpoint);
-                                                    if (info != null)
-                                                    {
-                                                        gwa.DeviceList.Remove(info);
-                                                    }
-                                                }
-                                            }
-                                            break;
-                                        case DeviceType.Transverter:
-                                            var transverter = new Transverter() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
-                                            transverter.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter.RemoveDeviceResponseData>(jobject["Data"].ToString());
-                                            if (transverter.removeDeviceResponseData == null)
-                                            {
-                                                return;
-                                            }
-                                            else
-                                            {
-                                                UpdateDeviceStatus(transverter);
-                                                UpdateDeviceInfo(transverter, "RemoveDeviceRespon");
-                                                if (transverter.removeDeviceResponseData.Result == 0)
-                                                {
-                                                    var info = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == transverter.DeviceID && obj.DeviceAddr == transverter.DeviceAddr && obj.DeviceEpoint == transverter.DeviceEpoint);
-                                                    if (info != null)
-                                                    {
-                                                        gwa.DeviceList.Remove(info);
-                                                    }
-                                                }
-                                            }
-                                            break;
+                                    var tempDevice = new CommonDevice() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
+                                    tempDevice.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RemoveDeviceResponseData>(jobject["Data"].ToString());
+                                    if (tempDevice.removeDeviceResponseData == null)
+                                    {
+                                        return;
+                                    }
+                                    else
+                                    {
+                                        UpdateDeviceStatus(tempDevice);
+                                        UpdateDeviceInfo(tempDevice, "RemoveDeviceRespon");
+                                        if (tempDevice.removeDeviceResponseData.Result == 0)
+                                        {
+                                            var infoTempDevice = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == tempDevice.DeviceID && obj.DeviceAddr == tempDevice.DeviceAddr && obj.DeviceEpoint == tempDevice.DeviceEpoint);
+                                            if (infoTempDevice != null)
+                                            {
+                                                gwa.DeviceList.Remove(infoTempDevice);
+                                            }
+                                        }
                                     }
                                 }
                             }
@@ -4385,70 +3906,10 @@
                     var tempEpoint = jobject.Value<int>("Epoint");
                     var dataId = jobject.Value<int>("Data_ID");
 
-                    switch ((DeviceType)(deviceID))
-                    {
-                        case DeviceType.DimmableLight:
-                            var light = new DimmableLight { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
-                            light.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.DeviceStatusReportData>(jobject["Data"].ToString());
-                            UpdateDeviceStatus(light);
-                            UpdateDeviceInfo(light, "DeviceStatusReport");
-                            break;
-                        case DeviceType.OnOffSwitch:
-                            var lightSwitch = new Panel { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
-                            lightSwitch.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(jobject["Data"].ToString());
-                            UpdateDeviceStatus(lightSwitch);
-                            UpdateDeviceInfo(lightSwitch, "DeviceStatusReport");
-                            break;
-                        case DeviceType.OnOffOutput:
-                            var lighttoggle = new ToggleLight { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
-                            lighttoggle.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.DeviceStatusReportData>(jobject["Data"].ToString());
-                            UpdateDeviceStatus(lighttoggle);
-                            UpdateDeviceInfo(lighttoggle, "DeviceStatusReport");
-                            break;
-                        case DeviceType.AirSwitch:
-                            var airSwitch = new AirSwitch { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
-                            airSwitch.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.DeviceStatusReportData>(jobject["Data"].ToString());
-                            UpdateDeviceStatus(airSwitch);
-                            UpdateDeviceInfo(airSwitch, "DeviceStatusReport");
-                            break;
-                        case DeviceType.WindowCoveringDevice:
-                            var curtain = new Rollershade { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
-                            curtain.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.DeviceStatusReportData>(jobject["Data"].ToString());
-                            UpdateDeviceStatus(curtain);
-                            UpdateDeviceInfo(curtain, "DeviceStatusReport");
-                            break;
-                        case DeviceType.OtaDevice:
-                        case DeviceType.OtaPanelDevice:
-                            var ota = new OTADevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
-                            ota.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<OTADevice.DeviceStatusReportData>(jobject["Data"].ToString());
-                            UpdateDeviceStatus(ota);
-                            UpdateDeviceInfo(ota, "DeviceStatusReport");
-                            break;
-                        case DeviceType.IASZone:
-                            var ias = new IASZone { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
-                            ias.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.DeviceStatusReportData>(jobject["Data"].ToString());
-                            UpdateDeviceStatus(ias);
-                            UpdateDeviceInfo(ias, "DeviceStatusReport");
-                            break;
-                        case DeviceType.Repeater:
-                            var repeater = new Repeater { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
-                            repeater.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater.DeviceStatusReportData>(jobject["Data"].ToString());
-                            UpdateDeviceStatus(repeater);
-                            UpdateDeviceInfo(repeater, "DeviceStatusReport");
-                            break;
-                        case DeviceType.Thermostat:
-                            var ac = new AC { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
-                            ac.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.DeviceStatusReportData>(jobject["Data"].ToString());
-                            UpdateDeviceStatus(ac);
-                            UpdateDeviceInfo(ac, "DeviceStatusReport");
-                            break;
-                        case DeviceType.Transverter:
-                            var transverter = new Transverter { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
-                            transverter.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<AC.DeviceStatusReportData>(jobject["Data"].ToString());
-                            UpdateDeviceStatus(transverter);
-                            UpdateDeviceInfo(transverter, "DeviceStatusReport");
-                            break;
-                    }
+                    var tempDevice = new CommonDevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
+                    tempDevice.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceStatusReportData>(jobject["Data"].ToString());
+                    UpdateDeviceStatus(tempDevice);
+                    UpdateDeviceInfo(tempDevice, "DeviceStatusReport");
                 }
                 #endregion
                 #region IAS瀹夐槻淇℃伅涓婃姤

--
Gitblit v1.8.0