From 427d1c7ecd04b03419eae157e32fe3367d8dffea Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期四, 28 十一月 2019 09:53:25 +0800 Subject: [PATCH] 2019.11.28 --- ZigbeeApp/Shared/Common/Room.cs | 67 +++++++++++++++++++++++---------- 1 files changed, 46 insertions(+), 21 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Room.cs b/ZigbeeApp/Shared/Common/Room.cs old mode 100755 new mode 100644 index fd52a18..c344624 --- 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(); @@ -582,9 +602,9 @@ /// </summary> /// <param name="id"></param> /// <returns></returns> - public List<Room> GetRoomsByFloorId(string id) + public List<Room> GetRoomsByFloorId(string id) { - return Lists.FindAll((obj) => obj.FloorId==id); + return Lists.FindAll((obj) => obj.FloorId == id); } /// <summary> /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂村悕绉� @@ -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