From 466d9904486acf9d1d5082298f1541579fff262d Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期五, 09 七月 2021 12:24:11 +0800
Subject: [PATCH] 最后的版本

---
 ZigbeeApp/Shared/Common/Device.cs |   80 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 182d93c..5ff29c8 100644
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -2852,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
 
         //----------------------------------鍒嗗壊绾�(鑷畾涔夋帴鍙�)---------------------------------------------
@@ -3249,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