From b800fbdf874cdc75ddc137ea2c22ac2c25d8b45c Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期二, 26 十一月 2019 10:10:37 +0800
Subject: [PATCH] 2019.11.26

---
 ZigbeeApp/Shared/Common/Room.cs |   63 ++++++++++++++++++++++---------
 1 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Room.cs b/ZigbeeApp/Shared/Common/Room.cs
old mode 100755
new mode 100644
index fd52a18..d410ead
--- a/ZigbeeApp/Shared/Common/Room.cs
+++ b/ZigbeeApp/Shared/Common/Room.cs
@@ -76,10 +76,26 @@
         /// </summary>
         public string HumidityDevice = string.Empty;
 
+        /// <summary>
+        /// 褰撳墠閫夋嫨鐨勬埧闂�
+        /// </summary>
+        private static Room m_CurrentRoom = null;
         /// <summary>
         /// 褰撳墠閫夋嫨鐨勬埧闂�
         /// </summary>
-        public static Room CurrentRoom;
+        [Newtonsoft.Json.JsonIgnore]
+        public static Room CurrentRoom
+        {
+            get
+            {
+                if (m_CurrentRoom == null && Lists.Count > 0)
+                {
+                    return Lists[0];
+                }
+                return m_CurrentRoom;
+            }
+            set { m_CurrentRoom = value; }
+        }
 
         /// <summary>
         /// 鎴块棿閲屾墍鏈夌殑璁惧鍒楄〃
@@ -114,12 +130,6 @@
         /// 娉細鍒嗕韩杩囨潵鐨勬埧闂翠笉鑳藉垹闄わ紝涓嶈兘缂栬緫璇ユ埧闂达紝涓嶈兘瀵硅澶囷紙鍔熻兘锛夈�佸満鏅繘琛屽鍒犳敼
         /// </summary>
         public bool IsSharedRoom = false;
-
-        /// <summary>
-        /// 鏄惁鍙互鍒锋柊鎴块棿鏁版嵁浜�
-        /// 闇�瑕佺瓑鍒濆鍖栨湰鍦拌澶囨暟鎹悗鍦ㄥ彲浠ュ垵濮嬪寲鎴块棿鏁版嵁
-        /// </summary>
-        public static bool CanInitAllRoom;
 
         /// <summary>
         /// 鑾峰彇鍠滅埍鎴块棿鐨勬墍鏈夎澶囪矾寰�
@@ -266,10 +276,6 @@
         /// </summary>
         public static void InitAllRoom()
         {
-            if (CanInitAllRoom == false)
-            {
-                return;
-            }
             Lists.Clear();
             if (Config.Instance.Home.RoomFilePathList.Contains("Room_Favorite.json") == false)
             {
@@ -289,11 +295,13 @@
                 {
                     if (room.IsSharedRoom)
                     {
-                        room.Name = $"({Language.StringByID(R.MyInternationalizationString.Shared)}){room.Name}";
+                        room.Name = $"{room.Name}";
                     }
                     Lists.Add(room);
+                   
                 }
             }
+            Config.Instance.Home.InitFloor();
         }
 
         /// <summary>
@@ -323,7 +331,6 @@
                 }
             }
             homeTemp.Save(false);
-            CanInitAllRoom = true;
             InitAllRoom();
         }
 
@@ -429,8 +436,21 @@
                     //璁惧锛坉eviceUI锛�
                     beforeRoom.DeviceUIList.Clear();
                     foreach (var deviceFilePath in beforeRoom.DeviceUIFilePathList)
-                    {
-                        beforeRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFilePath));
+                    {
+                        var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(deviceFilePath));
+                        var tempDeviceUI = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceUI>(jsonInfo);
+                        if (tempDeviceUI != null)
+                        {
+                            var delCommon = tempDeviceUIList.Find((obj) => obj.CommonDevice != null && tempDeviceUI.CommonDevice != null && obj.CommonDevice.Type == tempDeviceUI.CommonDevice.Type && obj.CommonDevice.CommonDeviceAddrEpoint == tempDeviceUI.CommonDevice.CommonDeviceAddrEpoint);
+                            if (delCommon != null)
+                            {
+                                beforeRoom.DeviceUIList.Add(delCommon);
+                            }
+                            else
+                            {
+                                beforeRoom.AddDevice(deviceFilePath);
+                            }
+                        }
                     }
                     //鍦烘櫙(SceneUI)
                     beforeRoom.SceneUIList.Clear();
@@ -622,6 +642,10 @@
         /// <returns></returns>
         public  List<Room> GetRoomsByCurrentFloorIdAppendLoveRoom()
         {
+            if(Config.Instance.Home.FloorDics.Count==0)
+            {
+                return Lists;
+            }
             var r = Lists.FindAll((obj) => obj.FloorId == Config.Instance.Home.CurrentFloorId);
             r.Insert(0, GetLoveRoom());
             return r;
@@ -745,8 +769,9 @@
         public void AddDevice(string deviceUIFilePath)
         {
             if (string.IsNullOrEmpty(deviceUIFilePath))
-            {
-                return;
+
+             {
+                 return;
             }
             var deviceUI = Common.LocalDevice.Current.GetDeviceUI(deviceUIFilePath);
             if (null == deviceUI.CommonDevice)
@@ -974,7 +999,7 @@
                     return -1;
                 }
             }
-            
+
             var getSceneIdAllData = await ZigBee.Device.Scene.GetSceneNewIdAsync(sceneName);
             if (getSceneIdAllData == null || getSceneIdAllData.getSceneIdData == null)
             {
@@ -1460,6 +1485,6 @@
         }
 
         #endregion
-       
+
     }
 }

--
Gitblit v1.8.0