From 18b93d511dc764b469d7c4a7e755f7274f89cdb4 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期一, 27 四月 2020 17:55:14 +0800
Subject: [PATCH] 2020-4-27-1

---
 ZigbeeApp/Shared/Phone/Device/CommonForm/RoomView.cs |  194 ++++++++++++++++++------------------------------
 1 files changed, 72 insertions(+), 122 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/CommonForm/RoomView.cs b/ZigbeeApp/Shared/Phone/Device/CommonForm/RoomView.cs
index a843033..0c3df7d 100755
--- a/ZigbeeApp/Shared/Phone/Device/CommonForm/RoomView.cs
+++ b/ZigbeeApp/Shared/Phone/Device/CommonForm/RoomView.cs
@@ -1,13 +1,11 @@
 锘縰sing System;
 using Shared.Common;
-using Shared.Phone.Device.DeviceLogic;
 using Shared.Phone.UserCenter;
-using Shared.Phone.UserView;
 using ZigBee.Device;
 
 namespace Shared.Phone.Device.CommonForm
 {
-    public class RoomView:FrameLayout, ZigBee.Common.IStatus
+    public class RoomView : FrameLayout
     {
         /// <summary>
         /// Room
@@ -23,114 +21,14 @@
         Button temperatureText;
 
         Button humidityText;
-
-        CommonDevice temperDevice;
-
-        CommonDevice humidDevice;
-
-        #region 鈼� 鎺ュ彛__________________________
-      
-        /// <summary>
-        /// 璁惧鐘舵�佹洿鏂版帴鍙�
-        /// <para>type锛氬鏋滀负 DeviceInComingRespon:璁惧鏂颁笂鎶�</para>
-        /// <para>type锛氬鏋滀负 IASInfoReport:RemoveDeviceRespon</para>
-        /// <para>type锛氬鏋滀负 DeviceStatusReport:璁惧涓婃姤</para>
-        /// <para>type锛氬鏋滀负 IASInfoReport:IAS瀹夐槻淇℃伅涓婃姤</para>
-        /// <para>type锛氬鏋滀负 OnlineStatusChange: 璁惧鍦ㄧ嚎鐘舵�佹洿鏂�</para>
+        /// <summary>
+        /// 娓╁害璁惧
         /// </summary>
-        /// <param name="common">Common.</param>
-        /// <param name="typeTag">Type tag.</param>
-        public void DeviceInfoChange(CommonDevice common, string typeTag)
-        {
-            if (typeTag == "DeviceStatusReport")
-            {
-                Application.RunOnMainThread(() =>
-                {
-                    try
-                    {
-                        if (common.DeviceStatusReport.AttriBute == null || common.DeviceStatusReport.AttriBute.Count == 0)
-                        {
-                            return;
-                        }
-                        //鏄惁涓哄綋鍓嶈澶�
-                        if ((temperDevice?.DeviceEpoint != common.DeviceEpoint || temperDevice?.DeviceAddr != common.DeviceAddr) && (humidDevice?.DeviceEpoint != common.DeviceEpoint || humidDevice?.DeviceAddr != common.DeviceAddr) )
-                        {
-                            return;
-                        }
-
-                        //if (common.Type == DeviceType.TemperatureSensor)
-                        //{
-                        if (common.DeviceStatusReport.CluterID == 1026)
-                        {
-                            foreach (var data in common.DeviceStatusReport.AttriBute)
-                            {
-                                if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue)
-                                {
-                                    if (data.AttriButeData == 0)
-                                    {
-                                        //0鈩�
-                                        temperatureText.Text = "0.0鈩�";
-                                        room.Temperatrue = 0;
-                                    }
-                                    else if (data.AttriButeData > 32767)
-                                    {
-                                        //璐熸暟(鐗规畩澶勭悊)
-                                        string strValue = (data.AttriButeData - 65536).ToString();
-                                        //灏忔暟鐐归渶瑕佷竴浣�
-                                        strValue = strValue.Substring(0, strValue.Length - 1);
-                                        temperatureText.Text = strValue.Insert(strValue.Length - 1, ".") + "鈩�";
-                                        room.Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
-                                    }
-                                    else
-                                    {
-                                        //灏忔暟鐐归渶瑕佷竴浣�
-                                        string strValue = data.AttriButeData.ToString();
-                                        strValue = strValue.Substring(0, strValue.Length - 1);
-                                        temperatureText.Text = strValue.Insert(strValue.Length - 1, ".") + "鈩�";
-                                        room.Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
-                                    }
-                                }
-                            }
-                        }
-                        else if (common.DeviceStatusReport.CluterID == 1029)
-                        {
-                            foreach (var data in common.DeviceStatusReport.AttriBute)
-                            {
-                                if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue)
-                                {
-                                    if (data.AttriButeData == 0)
-                                    {
-                                        //0
-                                        humidityText.Text = "--%";
-                                        room.Humidity = 0;
-                                    }
-                                    else
-                                    {
-                                        //灏忔暟鐐归渶瑕佷竴浣�(婀垮害娌℃湁璐熸暟)
-                                        string strValue = data.AttriButeData.ToString();
-                                        strValue = strValue.Substring(0, strValue.Length - 1);
-                                        humidityText.Text = strValue.Insert(strValue.Length - 1, ".") + "%";
-                                        room.Humidity = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
-                                    }
-                                }
-                            }
-                        }
-                        //}
-                    }
-                    catch (Exception ex)
-                    {
-                        System.Console.WriteLine($"Error:{ex.Message}");
-                    }
-                });
-            }
-        }
-        #endregion
-
-        public override void RemoveFromParent()
-        {
-            ZbGateway.StatusList.Remove(this);
-            base.RemoveFromParent();
-        }
+        private CommonDevice temperDevice = null;
+        /// <summary>
+        /// 婀垮害璁惧
+        /// </summary>
+        private CommonDevice humidDevice = null;
 
         /// <summary>
         /// RoomView
@@ -143,7 +41,6 @@
             Y = Application.GetRealHeight(y);
             Width = Application.GetRealWidth(717);
             Height = Application.GetRealHeight(478);
-            ZbGateway.StatusList.Add(this);
         }
 
         /// <summary>
@@ -164,14 +61,16 @@
             {
                 Width = Application.GetRealWidth(717),
                 Height = Application.GetRealHeight(478),
-                Radius = (uint)Application.GetRealHeight(17)
+                Radius = (uint)Application.GetRealHeight(17),
+                Tag = "R"
             };
             AddChidren(roomBackView);
 
             var roomImg = new ImageView()
             {
                 ImagePath = room.BackgroundImageType == 0 ? room.BackgroundImage : System.IO.Path.Combine(Config.Instance.FullPath, room.BackgroundImage),
-                Radius = (uint)Application.GetRealHeight(17)
+                Radius = (uint)Application.GetRealHeight(17),
+                Tag = "R"
             };
             roomBackView.AddChidren(roomImg);
 
@@ -179,8 +78,8 @@
             var frameBackGroudTemp = new FrameLayout();
             frameBackGroudTemp.Width = roomBackView.Width;
             frameBackGroudTemp.Height = roomBackView.Height;
-            frameBackGroudTemp.Radius = roomBackView.Radius;
-            frameBackGroudTemp.BackgroundColor = 0x12000000;
+            frameBackGroudTemp.Radius = (uint)Application.GetRealHeight(17);
+            frameBackGroudTemp.BackgroundColor = UserCenterColor.Current.PictrueZhezhaoColor;
             roomBackView.AddChidren(frameBackGroudTemp);
 
             roomNameBackground = new FrameLayout
@@ -201,7 +100,7 @@
                 Text = room.Name,
                 TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                 TextSize = 10,
-                TextAlignment=TextAlignment.CenterLeft,
+                TextAlignment = TextAlignment.CenterLeft,
                 IsBold = true
             };
             roomNameBackground.AddChidren(roomName);
@@ -235,10 +134,11 @@
                 Width = Application.GetRealWidth(120),
                 Text = "--鈩�",
                 TextSize = 14,
-                TextAlignment=TextAlignment.CenterLeft
+                TextAlignment = TextAlignment.CenterLeft
             };
-            if (string.IsNullOrEmpty(room.TemperatrueDevice) == false)
+            if (LocalDevice.Current.GetDevice(room.TemperatrueDevice) != null)
             {
+                //杩欎釜璁惧瑕佸瓨鍦ㄦ湰鍦版墠琛�
                 temperatureText.Text = room.Temperatrue == 0 ? "0.0鈩�" : room.Temperatrue.ToString() + "鈩�";
             }
             roomTemperatureBackground.AddChidren(temperatureText);
@@ -262,8 +162,9 @@
                 TextSize = 14,
                 TextAlignment = TextAlignment.CenterLeft
             };
-            if (string.IsNullOrEmpty(room.HumidityDevice) == false)
+            if (LocalDevice.Current.GetDevice(room.HumidityDevice) != null)
             {
+                //杩欎釜璁惧瑕佸瓨鍦ㄦ湰鍦版墠琛�
                 humidityText.Text = room.Humidity == 0 ? "0.0%" : room.Humidity.ToString() + "%";
             }
             roomTemperatureBackground.AddChidren(humidityText);
@@ -274,13 +175,13 @@
             {
                 //鍙戦�佽幏鍙栨俯搴︾殑鍛戒护
                 var dev = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice);
-                ReadDeviceAttributeLogic.Instance.SendTemperatureStatuComand(dev);
+                HdlDeviceAttributeLogic.Current.SendTemperatureStatuComand(dev);
             }
 
             if (string.IsNullOrEmpty(room.HumidityDevice) == false)
             {
-                var dev = Common.LocalDevice.Current.GetDevice(room.HumidityDevice);
-                ReadDeviceAttributeLogic.Instance.SendHumidityStatuComand(dev);
+                var dev = Common.LocalDevice.Current.GetDevice(room.HumidityDevice);
+                HdlDeviceAttributeLogic.Current.SendHumidityStatuComand(dev);
             }
 
             roomListBtn = new Button()
@@ -305,6 +206,46 @@
                     this.Init(this.room);
                 };
             };
+            //璁惧灞炴�т笂鎶�
+            HdlGatewayReceiveLogic.Current.AddAttributeEvent("RoomView" + this.room.Id, ReceiveComandDiv.A璁惧灞炴�т笂鎶�, (report) =>
+            {
+                if (this.temperDevice != null)
+                {
+                    //娓╁害璁惧
+                    if (report.DeviceAddr == temperDevice.DeviceAddr && report.DeviceEpoint == temperDevice.DeviceEpoint)
+                    {
+                        HdlThreadLogic.Current.RunMain(() =>
+                        {
+                            if (((TemperatureSensor)temperDevice).Temperatrue == 0)
+                            {
+                                temperatureText.Text = "0.0鈩�";
+                            }
+                            else
+                            {
+                                temperatureText.Text = ((TemperatureSensor)temperDevice).Temperatrue + "鈩�";
+                            }
+                        }, ShowErrorMode.NO);
+                    }
+                }
+                if (this.humidDevice != null)
+                {
+                    //婀垮害璁惧
+                    if (report.DeviceAddr == humidDevice.DeviceAddr && report.DeviceEpoint == humidDevice.DeviceEpoint)
+                    {
+                        HdlThreadLogic.Current.RunMain(() =>
+                        {
+                            if (((TemperatureSensor)temperDevice).Humidity == 0)
+                            {
+                                humidityText.Text = "--%";
+                            }
+                            else
+                            {
+                                humidityText.Text = ((TemperatureSensor)temperDevice).Humidity + "%";
+                            }
+                        }, ShowErrorMode.NO);
+                    }
+                }
+            });
         }
 
         /// <summary>
@@ -313,6 +254,15 @@
         public void HideName(bool statu)
         {
             roomNameBackground.Visible = roomTemperatureBackground.Visible = roomListBtn.Visible = !statu;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public override void RemoveFromParent()
+        {
+            HdlGatewayReceiveLogic.Current.RemoveEvent("RoomView" + this.room.Id);
+            base.RemoveFromParent();
         }
     }
 }

--
Gitblit v1.8.0