From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 30 八月 2022 09:37:38 +0800
Subject: [PATCH] 合并了IOS的代码

---
 ZigbeeApp/Shared/Common/Device.cs |  109 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 101 insertions(+), 8 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 78875ab..5ff29c8 100644
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -1648,6 +1648,12 @@
                     //闈㈡澘鐨勬俯搴︽帰澶村彨  闈㈡澘鍚嶅瓧+娓╁害
                     return deviceInfoType.DeviceDefultName + Language.StringByID(R.MyInternationalizationString.uTemperature);
                 }
+                else if (deviceInfoType.BeloneType == DeviceBeloneType.A绌烘皵璐ㄩ噺)
+                {
+
+                    //绌烘皵璐ㄩ噺浼犳劅鍣ㄧ殑娓╁害鎺㈠ご鍙┖姘旇川閲忎紶鎰熷櫒+娓╁害
+                    return deviceInfoType.DeviceDefultName + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
+                }
                 else if (((TemperatureSensor)device).SensorDiv == 1)
                 {
                     //娓╁害浼犳劅鍣�
@@ -2334,12 +2340,18 @@
             {
                 bool temperatrue = false;
                 bool humidity = false;
+                bool airQualitySensor = false;
                 //鑾峰彇鍏ㄩ儴鐨勫洖璺�
                 var listTemp = this.GetDevicesByMac(listdevice[0].DeviceAddr, false);
                 foreach (var device in listTemp)
                 {
                     if (device is TemperatureSensor)
                     {
+                        //绌烘皵璐ㄩ噺浼犳劅鍣�
+                        if (device.isAirQualitySensor(device))
+                        {
+                            airQualitySensor = true;
+                        }
                         //娓╁害浼犳劅鍣�
                         if (((TemperatureSensor)device).SensorDiv == 1)
                         {
@@ -2374,6 +2386,15 @@
                     info.ConcreteType = DeviceConcreteType.Sensor_Humidity;
                 }
                 info.ObjectTypeName = this.dicDeviceModelIdEnum["A411"].A绫诲瀷鍚嶅瓧;//浼犳劅鍣�
+
+                //绌烘皵璐ㄩ噺浼犳劅鍣�
+                if (airQualitySensor == true)
+                {
+                    info.ConcreteText = this.dicDeviceModelIdEnum["A422"].A瀹樻柟鍚嶅瓧;
+                    info.BeloneType = DeviceBeloneType.A绌烘皵璐ㄩ噺;
+                    info.ConcreteType = DeviceConcreteType.AirQualitySensor;
+                    info.ObjectTypeName = this.dicDeviceModelIdEnum["A422"].A绫诲瀷鍚嶅瓧;
+                }
             }
             //14鏂伴璁惧
             else if (dicType.ContainsKey(DeviceType.FreshAir) == true)
@@ -2406,14 +2427,6 @@
                 info.BeloneType = DeviceBeloneType.A鏅捐。鏋�;
                 info.ConcreteType = DeviceConcreteType.Airer;
                 info.ObjectTypeName = this.dicDeviceModelIdEnum["A421"].A绫诲瀷鍚嶅瓧;
-            }
-            //18绌烘皵璐ㄩ噺浼犳劅鍣�
-            else if (dicType.ContainsKey(DeviceType.AirQualitySensor) == true)
-            {
-                info.ConcreteText = this.dicDeviceModelIdEnum["A422"].A瀹樻柟鍚嶅瓧;
-                info.BeloneType = DeviceBeloneType.A绌烘皵璐ㄩ噺;
-                info.ConcreteType = DeviceConcreteType.AirQualitySensor;
-                info.ObjectTypeName = this.dicDeviceModelIdEnum["A422"].A绫诲瀷鍚嶅瓧;
             }
 
             //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧
@@ -2839,6 +2852,58 @@
             });
         }
 
+        /// <summary>
+        /// 澶勭悊缃戝叧杩斿洖鐨勬箍搴﹀��
+        /// </summary>
+        /// <param name="value">缃戝叧杩斿洖鐨勫睘鎬у��</param>
+        public decimal AdjustHumidityValue(int value)
+        {
+            if (value == 0)
+            {
+                //0%
+                return 0;
+            }
+            //涓嶄細鍑虹幇璐熸暟
+            else
+            {
+                //灏忔暟鐐归渶瑕佷竴浣�
+                string strValue = value.ToString();
+                strValue = strValue.Substring(0, strValue.Length - 1);
+                //璁板綍娓╁害
+                return strValue == string.Empty ? 0m : Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
+            }
+        }
+
+        /// <summary>
+        /// 澶勭悊缃戝叧杩斿洖鐨勬俯搴﹀��
+        /// </summary>
+        /// <param name="value">缃戝叧杩斿洖鐨勫睘鎬у��</param>
+        public decimal AdjustTemperatrueValue(int value)
+        {
+            if (value == 0)
+            {
+                //0鈩�
+                return 0;
+            }
+            else if (value > 32767)
+            {
+                //璐熸暟(鐗规畩澶勭悊)
+                string strValue = (value - 65536).ToString();
+                //灏忔暟鐐归渶瑕佷竴浣�
+                strValue = strValue.Substring(0, strValue.Length - 1);
+                //璁板綍娓╁害
+                return strValue == string.Empty ? 0m : Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
+            }
+            else
+            {
+                //灏忔暟鐐归渶瑕佷竴浣�
+                string strValue = value.ToString();
+                strValue = strValue.Substring(0, strValue.Length - 1);
+                //璁板綍娓╁害
+                return strValue == string.Empty ? 0m : Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
+            }
+        }
+
         #endregion
 
         //----------------------------------鍒嗗壊绾�(鑷畾涔夋帴鍙�)---------------------------------------------
@@ -3236,6 +3301,34 @@
                         ((TemperatureSensor)mainDevice).SensorDiv = 1;
                     }
                 }
+                if (((TemperatureSensor)mainDevice).SensorDiv == 1)
+                {
+                    //鍙樻洿涓�涓嬫俯搴︾殑鍊�
+                    foreach (var data in mainDevice.AttributeStatus)
+                    {
+                        if (data.ClusterId == 1026
+                           && data.AttributeId == (int)AttriButeId.MeasuredValue)
+                        {
+                            //澶勭悊缃戝叧杩斿洖鐨勬俯搴﹀��
+                            decimal temperatrue = this.AdjustTemperatrueValue(data.AttributeData);
+                            ((TemperatureSensor)mainDevice).currentTemperature = temperatrue;
+                        }
+                    }
+                }
+                else if (((TemperatureSensor)mainDevice).SensorDiv == 2)
+                {
+                    //鍙樻洿涓�涓嬫箍搴︾殑鍊�
+                    foreach (var data in mainDevice.AttributeStatus)
+                    {
+                        if (data.ClusterId == 1029
+                           && data.AttributeId == (int)AttriButeId.MeasuredValue)
+                        {
+                            //澶勭悊缃戝叧杩斿洖鐨勬俯搴﹀��
+                            decimal humidity = this.AdjustHumidityValue(data.AttributeData);
+                            ((TemperatureSensor)mainDevice).currentHumidity = humidity;
+                        }
+                    }
+                }
             }
         }
 

--
Gitblit v1.8.0