黄学彪
2019-10-15 2bf5ec775cb57d8015bee58c745a1e48081ff1b1
ZigbeeApp/Shared/Common/Room.cs
@@ -38,12 +38,22 @@
        /// </summary>
        public string FloorId = string.Empty;
        /// <summary>
        /// 楼层名称
        /// </summary>
        public string FloorName
        {
            get
            {
               return GetFloorNameById(FloorId);
            }
        }
        /// <summary>
        /// 房间名
        /// </summary>
        public string Name = string.Empty;
        /// <summary>
        /// 房间的时候背景图
        /// 房间背景图
        /// </summary>
        public string BackgroundImage = string.Empty;
@@ -56,6 +66,15 @@
        /// 楼层--备用
        /// </summary>
        public Dictionary<string, string> FloorList = new Dictionary<string, string> { };
        /// <summary>
        /// 温度传感器(设备主键)
        /// </summary>
        public string TemperatrueDevice = string.Empty;
        /// <summary>
        /// 湿度传感器(设备主键)
        /// </summary>
        public string HumidityDevice = string.Empty;
        /// <summary>
        /// 当前选择的房间
@@ -73,6 +92,11 @@
        public readonly List<string> DeviceUIFilePathList = new List<string>();
        /// <summary>
        /// 喜爱房间id
        /// </summary>
        public const string LoveRoomId= "Favorite";
        /// <summary>
        /// 是否是默认喜爱房间
        /// </summary>
        /// <value><c>true</c> if is love; otherwise, <c>false</c>.</value>
@@ -81,7 +105,7 @@
        {
            get
            {
                return Id == "Favorite";
                return Id == LoveRoomId;
            }
        }
@@ -110,8 +134,7 @@
                {
                    return new List<string> { };
                }
                var loveRoom = Lists[0];
                return loveRoom.DeviceUIFilePathList;
                return GetLoveRoom().DeviceUIFilePathList;
            }
        }
@@ -204,7 +227,7 @@
            if (Config.Instance.Home.RoomFilePathList.Contains("Room_Favorite.json") == false)
            {
                //默认添加喜爱的房间--禁止修改房间名
                var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "Room/r0.png", Id = "Favorite" };
                var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "Room/r0.png", Id = LoveRoomId };
                love.Save(true);
                //添加到house 房间路径列表
                var currentHome = Config.Instance.Home;
@@ -323,6 +346,15 @@
        #region ◆ 获取房间________________________
        /// <summary>
        /// 获取喜爱房间
        /// </summary>
        /// <returns></returns>
        public static Room GetLoveRoom()
        {
            return CurrentRoom.GetRoomById(LoveRoomId);
        }
        /// <summary>
        /// 通过路径获取房间
        /// </summary>
        /// <returns>The room by file path.</returns>
@@ -350,21 +382,8 @@
                    //设备(deviceUI)
                    beforeRoom.DeviceUIList.Clear();
                    foreach (var deviceFilePath in beforeRoom.DeviceUIFilePathList)
                    {
                        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);
                            }
                        }
                    {
                        beforeRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFilePath));
                    }
                    //场景(SceneUI)
                    beforeRoom.SceneUIList.Clear();
@@ -786,6 +805,28 @@
            }
        }
        /// <summary>
        /// 获取当前房间下的全部设备
        /// </summary>
        /// <returns></returns>
        public List<CommonDevice> GetRoomListDevice()
        {
            var listDevice = new List<CommonDevice>();
            foreach (var device in this.DeviceUIList)
            {
                if (device == null || device.CommonDevice == null)
                {
                    continue;
                }
                listDevice.Add(device.CommonDevice);
            }
            if (listDevice.Count == 0)
            {
                return listDevice;
            }
            return Common.LocalDevice.Current.SortDevice(listDevice);
        }
        #endregion
        #region ◆ 添加场景_________________________
@@ -895,6 +936,28 @@
            Save();
        }
        #endregion
        #region ◆ 设备是否收藏______________________
        /// <summary>
        /// 是否是收藏设备
        /// </summary>
        /// <param name="room"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public bool IsCollectInRoom(Room room,string filePath)
        {
            if(room.IsLove)
            {
                return true;
            }
            if (GetLoveRoom().DeviceUIFilePathList.Find((obj) => obj == filePath) == null)
            {
                return false;
            }
            return true;
        }
        #endregion
        #region ◆ 修改场景________________________
@@ -1121,7 +1184,7 @@
            var dicRoom = new Dictionary<string, Common.Room>();
            foreach (var room in Common.Room.Lists)
            {
                if (room.FloorId != i_floorKeys)
                if (room.FloorId != i_floorKeys || room.IsLove == true)
                {
                    //不是同一个楼层
                    continue;
@@ -1237,6 +1300,8 @@
            //克隆属性
            newRoom.Id = this.Id;
            newRoom.FloorId = this.FloorId;
            newRoom.TemperatrueDevice = this.TemperatrueDevice;
            newRoom.HumidityDevice = this.HumidityDevice;
            newRoom.Name = this.Name;
            newRoom.BackgroundImage = this.BackgroundImage;
            newRoom.BackgroundImageType = this.BackgroundImageType;
@@ -1245,5 +1310,33 @@
        }
        #endregion
        #region ◆ 楼层___________________________
        /// <summary>
        /// 获取楼层名称
        /// </summary>
        /// <param name="floorId"></param>
        /// <returns></returns>
        public string GetFloorNameById(string floorId)
        {
            if (Config.Instance.Home.FloorDics.Count == 0)
            {
                return null;
            }
            foreach (var floor in Config.Instance.Home.FloorDics)
            {
                if (floorId == floor.Key)
                {
                    return floor.Value;
                }
            }
            return null;
        }
        #endregion
    }
}