HDL Home App 第二版本 旧平台金堂用 正在使用
wjc
2022-12-01 351bdda734832d821a9764b0cde8be5d83c4ec50
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;
                        }
                    }
                }
            }
        }