From 9c16d3614d9b88c637f967518a329f239fcd3aaf Mon Sep 17 00:00:00 2001
From: lss <316519258@qq.com>
Date: 星期五, 12 六月 2020 09:22:04 +0800
Subject: [PATCH] 2020.06.12

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs |  181 +++++++--------------------------------------
 1 files changed, 29 insertions(+), 152 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
index a572e70..2e80273 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
@@ -108,7 +108,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 +199,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);
                 }
 
@@ -291,6 +296,14 @@
             {
                 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 { return null; }
             //鑳藉皯瀛樹竴涓彉閲忓氨灏戝瓨涓�涓�
             device.Type = (DeviceType)device.DeviceID;
@@ -360,6 +373,11 @@
                 {
                     //璋冨厜鍣�
                     IconPath = "Device/Light.png";
+                }
+                else if (this.Type == DeviceType.ColorTemperatureLight)
+                {
+                    //鑹叉俯鐏�
+                    IconPath = "Device/ColorLightTemperature.png";
                 }
                 else if (this.Type == DeviceType.OnOffOutput)
                 {
@@ -375,6 +393,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 +485,8 @@
             /// 娓╁害娴嬮噺鍔熻兘鐨勮澶囧锛氭俯搴︿紶鎰熷櫒銆傘�傘��
             /// <para>1029:Relative Humidity Measurement,璁惧鏀寔鈥滄箍搴︽祴閲忓姛鑳解��</para>
             /// 婀垮害娴嬮噺鍔熻兘鐨勮澶囧锛氭箍搴︿紶鎰熷櫒銆傘�傘��
+            /// <para>1066:Pm2.5  Measurement,璁惧鏀寔鈥減m2.5娴嬮噺鍔熻兘鈥�</para>
+            /// Pm2.5娴嬮噺鍔熻兘鐨勮澶囧锛歅m2.5浼犳劅鍣ㄣ�傘�傘��
             /// </summary>
             public int InCluster;
         }
@@ -732,80 +757,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 +798,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鍚嶇О鏁版嵁,缃戝叧鍙嶉鍏蜂綋淇℃伅

--
Gitblit v1.8.0