From fe3b2466c68b5db70d38e78039703add3b8b1dfe Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 31 十二月 2020 19:29:43 +0800
Subject: [PATCH] 合并了代码

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs |   89 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 69 insertions(+), 20 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
index 5d8ca7d..5bb5fac 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 using Newtonsoft.Json.Linq;
+using Shared;
 
 namespace ZigBee.Device
 {
@@ -354,6 +355,10 @@
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmerSwitch>(strDeviceByte);
             }
+            else if (intDeviceType == (int)DeviceType.Airer)
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<Airer>(strDeviceByte);
+            }
             else
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice>(strDeviceByte);
@@ -406,6 +411,43 @@
                 return;
             }
             Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
+        }
+
+        /// <summary>
+        /// 鍒ゆ柇鏄惁鏄┖姘旇川閲忎紶鎰熷櫒
+        /// </summary>
+        /// <param name="dev"></param>
+        /// <returns></returns>
+        public bool isAirQualitySensor(CommonDevice dev)
+        {
+            bool hasT = false;
+            bool hasH = false;
+            bool hasPM = false;
+            bool hasCo2 = false;
+            foreach (var clu in dev.InClusterList)
+            {
+                switch (clu.InCluster)
+                {
+                    case 1026:
+                        hasT = true;
+                        break;
+                    case 1029:
+                        hasH = true;
+                        break;
+                    case 1037:
+                        hasCo2 = true;
+                        break;
+                    case 1066:
+                        hasPM = true;
+                        break;
+                }
+            }
+
+            if (hasT == true && hasH == true && hasPM == true && hasCo2 == true)
+            {
+                return true;
+            }
+            return false;
         }
 
         /// <summary>
@@ -462,15 +504,23 @@
                 }
                 else if (this.Type == DeviceType.TemperatureSensor)
                 {
-                    if (((TemperatureSensor)this).SensorDiv == 1)
+                    if (isAirQualitySensor(this))
                     {
-                        //娓╁害浼犳劅鍣�
-                        IconPath = "Device/SensorTemperature.png";
+                        //绌烘皵璐ㄩ噺浼犳劅鍣�
+                        IconPath = "Device/AirQualitySensorEpoint.png";
                     }
-                    else if (((TemperatureSensor)this).SensorDiv == 2)
+                    else
                     {
-                        //婀垮害浼犳劅鍣�
-                        IconPath = "Device/SensorHumidity.png";
+                        if (((TemperatureSensor)this).SensorDiv == 1)
+                        {
+                            //娓╁害浼犳劅鍣�
+                            IconPath = "Device/SensorTemperature.png";
+                        }
+                        else if (((TemperatureSensor)this).SensorDiv == 2)
+                        {
+                            //婀垮害浼犳劅鍣�
+                            IconPath = "Device/SensorHumidity.png";
+                        }
                     }
                 }
                 else if (this.Type != DeviceType.UnKown)
@@ -478,7 +528,7 @@
                     //鍏朵粬鐨勫浘鏍囨湁鐐圭壒娈�
                     string unSelectPic = string.Empty;
                     string selectPic = string.Empty;
-                    Shared.Phone.HdlDeviceCommonLogic.Current.GetDeviceObjectIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic);
+                    Shared.Common.LocalDevice.Current.GetDeviceObjectIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic);
                     IconPath = unSelectPic;
                 }
                 Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
@@ -1302,12 +1352,11 @@
         /// 璁剧疆鍙啓灞炴�х殑鍊�
         /// </summary>
         /// <returns>The writable value async.</returns>
-        /// <param name="gateway">Gateway.</param>
         /// <param name="clusterID">瑕侀厤缃殑灞炴�ф墍鍦ㄧ殑cluster.</param>
         /// <param name="setWritableValue">璁剧疆鍙啓灞炴�х殑鏁版嵁</param>
-        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetWritableValueAsync(ZigBee.Device.ZbGateway gateway, int clusterID, SetWritableValueData setWritableValue)
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetWritableValueAsync(int clusterID, SetWritableValueData setWritableValue)
         {
-            if (gateway == null || setWritableValue == null)
+            if (Gateway == null || setWritableValue == null)
             {
                 return null;
             }
@@ -1348,7 +1397,7 @@
                         }
                     }
                 };
-                gateway.Actions += action;
+                Gateway.Actions += action;
                 System.Console.WriteLine("SetWritableValue_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
 
                 try
@@ -1356,7 +1405,7 @@
                     var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", clusterID }, { "Command", 120 } };
                     var data = new JObject { { "Undivided", setWritableValue.Undivided }, { "AttributeId", setWritableValue.AttributeId }, { "AttributeDataType", setWritableValue.AttributeDataType }, { "AttributeData", setWritableValue.AttributeData } };
                     jObject.Add("Data", data);
-                    gateway.Send("SetWritableValue", jObject.ToString());
+                    Gateway.Send("SetWritableValue", jObject.ToString());
                 }
                 catch { }
 
@@ -1373,7 +1422,7 @@
                 {
                     d = new SetWritableValueResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
                 }
-                gateway.Actions -= action;
+                Gateway.Actions -= action;
                 System.Console.WriteLine("SetWritableValue_Actions 閫�鍑�" + System.DateTime.Now.ToString());
 
                 return d;
@@ -2450,13 +2499,13 @@
         public static void DebugPrintLog(string msg, bool flage = true)
         {
 #if DEBUG
-            if (flage == true)
-            {
-                if (msg.Contains("DeviceStatusReport") == false)
-                {
-                    System.Console.WriteLine(msg + "  " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond);
-                }
-            }
+      if (flage == true)
+      {
+        if (msg.Contains("DeviceStatusReport") == false)
+        {
+          System.Console.WriteLine(msg + "  " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond);
+        }
+      }
 #endif
         }
 

--
Gitblit v1.8.0