黄学彪
2019-10-18 97e259d966cb5cb5d73c105d5dbaadcc1f920614
ZigbeeApp/Shared/Common/Room.cs
@@ -36,7 +36,7 @@
        /// 楼层Id
        /// 新增时使用Guid
        /// </summary>
        public string FloorId = "Floor1";
        public string FloorId = string.Empty;
        /// <summary>
        /// 楼层名称
        /// </summary>
@@ -44,7 +44,7 @@
        {
            get
            {
               return GetFloorNameById(FloorId);
               return Config.Instance.Home.GetFloorNameById(FloorId);
            }
        }
        /// <summary>
@@ -66,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>
        /// 当前选择的房间
@@ -125,7 +134,7 @@
                {
                    return new List<string> { };
                }
                return GetLoveRoom().DeviceUIFilePathList;
                return CurrentRoom.GetLoveRoom().DeviceUIFilePathList;
            }
        }
@@ -340,7 +349,7 @@
        /// 获取喜爱房间
        /// </summary>
        /// <returns></returns>
        public static Room GetLoveRoom()
        public Room GetLoveRoom()
        {
            return CurrentRoom.GetRoomById(LoveRoomId);
        }
@@ -373,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();
@@ -451,6 +447,16 @@
        public Room GetRoomById(string roomId)
        {
            return Lists.Find((obj) => obj.Id == roomId);
        }
        /// <summary>
        /// 根据房间名字,获取房间对象
        /// </summary>
        /// <returns>The room by name.</returns>
        /// <param name="roomName">房间名</param>
        public Room GetRoomByName(string roomName)
        {
            return Lists.Find((obj) => obj.Name == roomName);
        }
        /// <summary>
@@ -523,6 +529,55 @@
            return null;
        }
        /// <summary>
        /// 获取当前楼层的房间
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  List<Room> GetRoomsByFloorId(string id)
        {
            return Lists.FindAll((obj) => obj.FloorId==id);
        }
        /// <summary>
        /// 获取当前楼层的房间名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  List<string> GetRoomNamesByFloorId(string id)
        {
            List<string> names = new List<string> { };
            foreach(var r in Lists)
            {
                if(r.FloorId==id)
                {
                    names.Add(r.Name);
                }
            }
            return names;
        }
        /// <summary>
        /// 获取当前楼层的房间(拼接了【常用】在第一位)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  List<Room> GetRoomsByFloorIdAppendLoveRoom(string id)
        {
            var r= Lists.FindAll((obj) => obj.FloorId == id);
            r.Insert(0, GetLoveRoom());
            return r;
        }
        /// <summary>
        /// 获取当前楼层的房间(拼接了【常用】在第一位)
        /// </summary>
        /// <returns></returns>
        public  List<Room> GetRoomsByCurrentFloorIdAppendLoveRoom()
        {
            var r = Lists.FindAll((obj) => obj.FloorId == Config.Instance.Home.CurrentFloorId);
            r.Insert(0, GetLoveRoom());
            return r;
        }
        #endregion
@@ -693,7 +748,6 @@
        #endregion
        #region ◆ 删除设备_________________________
        /// <summary>
        /// 删除功能-设备
        /// </summary>
@@ -808,6 +862,78 @@
                }
            }
        }
        /// <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);
        }
        /// <summary>
        /// 获取房间设备类型
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        public static List<DeviceType> GetdeviceTypes(Room room)
        {
            List<DeviceType> typeList = new List<DeviceType> { };
            foreach (var deviceUI in room.DeviceUIList)
            {
                if (deviceUI == null || deviceUI.CommonDevice == null)
                {
                    continue;
                }
                if (!typeList.Contains(deviceUI.CommonDevice.Type))
                {
                    typeList.Add(deviceUI.CommonDevice.Type);
                }
            }
            return typeList;
        }
        /// <summary>
        /// 获取该类型的设备
        /// </summary>
        /// <param name="room"></param>
        /// <param name="deviceType"></param>
        /// <returns></returns>
        public static List<DeviceUI> GetDeviceUIs(Room room ,DeviceType deviceType)
        {
            List<DeviceUI> typeList = new List<DeviceUI> { };
            foreach (var deviceUI in room.DeviceUIList)
            {
                if (deviceUI == null || deviceUI.CommonDevice == null)
                {
                    continue;
                }
                if(deviceUI.CommonDevice.Type!=deviceType)
                {
                    continue;
                }
                if (!typeList.Contains(deviceUI))
                {
                    typeList.Add(deviceUI);
                }
            }
            return typeList;
        }
        #endregion
@@ -1282,6 +1408,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;
@@ -1290,33 +1418,6 @@
        }
        #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
       
    }
}