From 9a4b76398009cf76c508d61f7e48fb6f5cb7ac2d Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期二, 21 七月 2020 09:46:53 +0800
Subject: [PATCH] 请合并最新多功能面板代码

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs |  309 +++++++++++++++++++++++++-------------------------
 1 files changed, 155 insertions(+), 154 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
index a572e70..0ae3f20 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
@@ -85,6 +85,7 @@
         /// <para>鎸佺画鏁版嵁涓婃姤(MomentStatus=0   TriggerZoneStatus>=1锛滄姤璀︼紴  TriggerZoneStatus=0锛滃彇娑堟姤璀︼紴)</para>
         /// <para>21: Door/Window 闂ㄧ獥浼犳劅鍣紙鏈�21鍜�22锛岃繖閲屾病鏈夊啓閿欙級</para>
         /// <para>22:Door/Window 闂ㄧ獥浼犳劅鍣紙鏈�21鍜�22锛岃繖閲屾病鏈夊啓閿�</para>
+        /// <para>541 鐞冨瀷绉诲姩浼犳劅鍣�</para>
         /// </summary>
         public int IasDeviceType;
         /// <summary>
@@ -108,7 +109,12 @@
         /// 0锛氳澶囦笉鍦ㄧ嚎
         /// <para>1锛氳澶囧湪绾�</para>
         /// </summary>
-        public int IsOnline;
+        public int IsOnline;
+        /// <summary>
+        /// 1锛氳矾鐢辫澶�
+        /// <para>2锛氱粓绔澶囷紝鐢垫睜璁惧</para>
+        /// </summary>
+        public int ZigbeeType;
         /// <summary>
         /// 褰撳墠杩愯绋嬪簭鐗堟湰淇℃伅銆� 鏈�澶�64瀛楄妭
         /// </summary>
@@ -194,12 +200,12 @@
                 {
                     return null;
                 }
-                var gateWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.getGatewayBaseInfo != null) && (obj.getGatewayBaseInfo.gwID == CurrentGateWayId));
+                var gateWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.GwId == CurrentGateWayId));
                 if (gateWay == null)
                 {
                     gateWay = new ZbGateway { IsVirtual = true, };
-                    gateWay.getGatewayBaseInfo.gwID = CurrentGateWayId;
-                    gateWay.getGatewayBaseInfo.HomeId = Shared.Common.Config.Instance.HomeId;
+                    gateWay.GwId = CurrentGateWayId;
+                    gateWay.HomeId = Shared.Common.Config.Instance.HomeId;
                     ZbGateway.GateWayList.Add(gateWay);
                 }
 
@@ -243,9 +249,21 @@
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte);
             }
+            else if (strDeviceType == ZigBee.Device.DeviceType.ColorDimmerSwitch.ToString())
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmerSwitch>(strDeviceByte);
+            }
+            else if (strDeviceType == ZigBee.Device.DeviceType.LevelControlSwitch.ToString())
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<LevelControlSwitch>(strDeviceByte);
+            }
             else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringDevice.ToString())
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade>(strDeviceByte);
+            }
+            else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringController.ToString())
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<WindowCoveringController>(strDeviceByte);
             }
             else if (strDeviceType == ZigBee.Device.DeviceType.OnOffSwitch.ToString())
             {
@@ -290,6 +308,18 @@
             else if (strDeviceType == ZigBee.Device.DeviceType.FreshAir.ToString())
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<FreshAir>(strDeviceByte);
+            }
+            else if (strDeviceType == ZigBee.Device.DeviceType.PMSensor.ToString())
+            {
+                return Newtonsoft.Json.JsonConvert.DeserializeObject<PMSensor>(strDeviceByte);
+            }
+            else if (strDeviceType == ZigBee.Device.DeviceType.ColorTemperatureLight.ToString())
+            {
+                return Newtonsoft.Json.JsonConvert.DeserializeObject<ColorTemperatureLight>(strDeviceByte);
+            }
+            else if (strDeviceType == ZigBee.Device.DeviceType.Buzzer.ToString())
+            {
+                return Newtonsoft.Json.JsonConvert.DeserializeObject<Buzzer>(strDeviceByte);
             }
             else { return null; }
             //鑳藉皯瀛樹竴涓彉閲忓氨灏戝瓨涓�涓�
@@ -360,6 +390,11 @@
                 {
                     //璋冨厜鍣�
                     IconPath = "Device/Light.png";
+                }
+                else if (this.Type == DeviceType.ColorTemperatureLight)
+                {
+                    //鑹叉俯鐏�
+                    IconPath = "Device/ColorLightTemperature.png";
                 }
                 else if (this.Type == DeviceType.OnOffOutput)
                 {
@@ -375,6 +410,11 @@
                 {
                     //鏂伴 
                     IconPath = "Device/FreshAirEpoint.png";
+                }
+                else if (this.Type == DeviceType.PMSensor)
+                {
+                    //PM2.5绌烘皵璐ㄩ噺浼犳劅鍣� 
+                    IconPath = "Device/AirQualitySensorEpoint.png";
                 }
                 else if (this.Type == DeviceType.FreshAirHumiditySensor)
                 {
@@ -462,6 +502,8 @@
             /// 娓╁害娴嬮噺鍔熻兘鐨勮澶囧锛氭俯搴︿紶鎰熷櫒銆傘�傘��
             /// <para>1029:Relative Humidity Measurement,璁惧鏀寔鈥滄箍搴︽祴閲忓姛鑳解��</para>
             /// 婀垮害娴嬮噺鍔熻兘鐨勮澶囧锛氭箍搴︿紶鎰熷櫒銆傘�傘��
+            /// <para>1066:Pm2.5  Measurement,璁惧鏀寔鈥減m2.5娴嬮噺鍔熻兘鈥�</para>
+            /// Pm2.5娴嬮噺鍔熻兘鐨勮澶囧锛歅m2.5浼犳劅鍣ㄣ�傘�傘��
             /// </summary>
             public int InCluster;
         }
@@ -646,6 +688,10 @@
             /// 濂藉儚鏄簭鍒楀彿
             /// </summary>
             public string ProductCode = string.Empty;
+            /// <summary>
+            /// 璁惧鍔熻兘绫诲瀷(绌烘皵寮�鍏冲拰缁х數鍣ㄤ笓鐢�)
+            /// </summary>
+            public int FunctionType = -1;
             /// <summary>
             /// 杈撳叆绨囧垪琛�
             /// </summary>
@@ -732,80 +778,6 @@
         #endregion
 
         #region 淇敼璁惧绔彛鍚嶇О
-        ///<summary >
-        /// 淇敼璁惧绔彛锛堟寜閿級鍚嶇О
-        /// <para>Gateway:璁惧鎵�灞炵綉鍏筹紙璋冪敤鏂规硶锛歞evice.Gateway)</para>
-        /// <para>deviceName:鎸夐敭鍚嶇О</para>
-        /// </summary>
-        public async System.Threading.Tasks.Task<DeviceRenameAllData> RenameDeviceNameAsync(string deviceAddr, int deviceEpoint, string deviceName)
-        {
-            if (Gateway == null)
-            {
-                return null;
-            }
-            return await System.Threading.Tasks.Task.Run(async () =>
-            {
-                DeviceRenameAllData d = null;
-                Action<string, string> action = (topic, message) =>
-                {
-                    var gatewayID = topic.Split('/')[0];
-                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-
-                    if (topic == gatewayID + "/" + "Error_Respon")
-                    {
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
-
-                        if (temp == null)
-                        {
-                            d = new DeviceRenameAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
-                        }
-                        else
-                        {
-                            d = new DeviceRenameAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
-                        }
-                    }
-
-                    if (topic == gatewayID + "/" + "DeviceRenameRespon")
-                    {
-                        var receiptData = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceRenameResponseData>(jobject["Data"].ToString());
-                        d = new DeviceRenameAllData { deviceRenameData = receiptData };
-                    }
-                };
-                Gateway.Actions += action;
-                System.Console.WriteLine("DeviceRename_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
-                try
-                {
-                    var bytes = new byte[64];
-                    var reamarkGwBytes = Encoding.UTF8.GetBytes(deviceName);
-                    System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 64 < reamarkGwBytes.Length ? 64 : reamarkGwBytes.Length);
-                    deviceName = Encoding.UTF8.GetString(bytes);
-
-                    var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 96 } };
-                    var data = new JObject { { "DeviceName", deviceName } };
-                    jObject.Add("Data", data);
-                    Gateway?.Send(("DeviceRename"), jObject.ToString());
-                }
-                catch { }
-
-                var dateTime = DateTime.Now;
-                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
-                {
-                    await System.Threading.Tasks.Task.Delay(10);
-                    if (d != null)
-                    {
-                        break;
-                    }
-                }
-                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
-                {
-                    d = new DeviceRenameAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
-                }
-
-                Gateway.Actions -= action;
-                System.Console.WriteLine("DeviceRename_Actions閫�鍑�" + System.DateTime.Now.ToString());
-                return d;
-            });
-        }
 
         /// <summary>
         /// 閲嶅懡鍚嶈澶�,缃戝叧鍙嶉鍏蜂綋淇℃伅
@@ -847,80 +819,6 @@
         #endregion
 
         #region 淇敼璁惧mac鍚嶇О
-        ///<summary >
-        /// 淇敼璁惧mac鍚嶇О
-        /// <para>macName:璁惧鍚嶇О</para>
-        /// </summary>
-        public async System.Threading.Tasks.Task<RenameDeviceMacNameAllData> RenameDeviceMacNameAsync(string deviceAddr, int deviceEpoint, string macName)
-        {
-            if (Gateway == null)
-            {
-                return null;
-            }
-            return await System.Threading.Tasks.Task.Run(async () =>
-            {
-                RenameDeviceMacNameAllData d = null;
-                Action<string, string> action = (topic, message) =>
-                {
-                    var gatewayID = topic.Split('/')[0];
-                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-
-                    if (topic == gatewayID + "/" + "Error_Respon")
-                    {
-                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
-
-                        if (temp == null)
-                        {
-                            d = new RenameDeviceMacNameAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
-                        }
-                        else
-                        {
-                            d = new RenameDeviceMacNameAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
-                        }
-                    }
-
-                    if (topic == gatewayID + "/" + "MacRename_Respon")
-                    {
-                        var deviceID = jobject.Value<int>("Device_ID");
-                        d = new RenameDeviceMacNameAllData { renameDeviceMacNameData = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.RenameDeviceMacNameData>(jobject["Data"].ToString()) };
-                    }
-                };
-                Gateway.Actions += action;
-                System.Console.WriteLine("MacRename_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
-                try
-                {
-                    var bytes = new byte[64];
-                    var reamarkGwBytes = Encoding.UTF8.GetBytes(macName);
-                    System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 64 < reamarkGwBytes.Length ? 64 : reamarkGwBytes.Length);
-                    macName = Encoding.UTF8.GetString(bytes);
-
-                    var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 100 } };
-                    var data = new JObject { { "MacName", macName } };
-                    jObject.Add("Data", data);
-                    Gateway?.Send(("MacRename"), jObject.ToString());
-                }
-                catch { }
-
-                var dateTime = DateTime.Now;
-                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
-                {
-                    await System.Threading.Tasks.Task.Delay(10);
-                    if (d != null)
-                    {
-                        break;
-                    }
-                }
-
-                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
-                {
-                    d = new RenameDeviceMacNameAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
-                }
-
-                Gateway.Actions -= action;
-                System.Console.WriteLine("MacRename_Action閫�鍑�" + System.DateTime.Now.ToString());
-                return d;
-            });
-        }
 
         /// <summary>
         /// 淇敼璁惧mac鍚嶇О鏁版嵁,缃戝叧鍙嶉鍏蜂綋淇℃伅
@@ -949,6 +847,109 @@
             /// 淇敼鍚庣殑璁惧鍚嶇О
             /// </summary>
             public string MacName;
+        }
+        #endregion
+
+        #region 涓�閿洿鏂板洓瀵稿睆鎸夐敭灞炴��
+        /// <summary>
+        /// 鍚屾璁惧鍔熻兘
+        /// </summary>
+        /// <returns></returns>
+        public async System.Threading.Tasks.Task<SynchronizationDeviceResponseAllData> SyncMsgToBindSource(string deviceAddr, int deviceEpoint)
+        {
+            if (Gateway == null)
+            {
+                return null;
+            }
+
+            return await System.Threading.Tasks.Task.Run(async () =>
+            {
+                SynchronizationDeviceResponseAllData resContent = null;
+                Action<string, string> action = (topic, message) =>
+                {
+                    var gatewayID = topic.Split('/')[0];
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+
+                    if (topic == gatewayID + "/" + "Error_Respon")
+                    {
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
+
+                        if (temp == null)
+                        {
+                            resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+                        }
+                        else
+                        {
+                            resContent = new SynchronizationDeviceResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                        }
+                    }
+
+                    if (topic == gatewayID + "/" + "Bind/SyncMsgToBindSourceRespon")
+                    {
+                        var res = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
+                        if (res == null)
+                        {
+                            resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                        }
+                        else
+                        {
+                            resContent = new SynchronizationDeviceResponseAllData { result = res };
+                            System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
+                        }
+                    }
+                };
+                Gateway.Actions = action;
+                DebugPrintLog("Bind/SyncMsgToBindSourceRespon_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
+
+                try
+                {
+                    var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5010 } };
+                    Gateway.Send("Bind/SyncMsgToBindSource", jObject.ToString());
+                }
+                catch { }
+
+                var dateTime = DateTime.Now;
+                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
+                {
+                    await System.Threading.Tasks.Task.Delay(10);
+                    if (resContent != null)
+                    {
+                        break;
+                    }
+                }
+                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
+                {
+                    resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                }
+                Gateway.Actions -= action;
+                DebugPrintLog("Bind/SyncMsgToBindSource_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+
+                return resContent;
+            });
+
+        }
+
+        /// <summary>
+        /// 鍚屾璁惧,缃戝叧鍙嶉鍏蜂綋淇℃伅
+        /// </summary>
+        [System.Serializable]
+        public class SynchronizationDeviceResponseAllData
+        {
+            /// <summary>
+            /// 閿欒淇℃伅
+            /// </summary>
+            public string errorMessageBase;
+            /// <summary>
+            /// 缃戝叧淇℃伅閿欒鍙嶉
+            /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para>
+            /// </summary>
+            public ErrorResponData errorResponData;
+            /// <summary>
+            /// 鍚屾缁撴灉
+            /// 0:鎴愬姛锛氱綉鍏冲唴閮ㄨ嚜鍔ㄥ啓鍏ヨ澶囩洰鏍囧悕瀛椼�佽澶囩洰鏍囧姛鑳界被鍨嬨�佸満鏅洰鏍囧悕瀛椼�乽tc鏃堕棿鍐欏叆4瀵稿睆
+            /// 1:澶辫触
+            /// </summary>
+            public int result;
         }
         #endregion
 
@@ -1002,7 +1003,7 @@
                     }
                 };
                 Gateway.Actions += action;
-                System.Console.WriteLine("RemoveDevice_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
+                DebugPrintLog("RemoveDevice_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
 
                 try
                 {
@@ -1040,7 +1041,7 @@
                     d = new RemoveDeviceResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
                 }
                 Gateway.Actions -= action;
-                System.Console.WriteLine("RemoveDevice_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+                DebugPrintLog("RemoveDevice_Actions 閫�鍑�" + System.DateTime.Now.ToString());
 
                 return d;
             });

--
Gitblit v1.8.0