old mode 100755
new mode 100644
| | |
| | | /// </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> |
| | | /// 房间里所有的设备列表 |
| | |
| | | /// 注:分享过来的房间不能删除,不能编辑该房间,不能对设备(功能)、场景进行增删改 |
| | | /// </summary> |
| | | public bool IsSharedRoom = false; |
| | | |
| | | /// <summary> |
| | | /// 是否可以刷新房间数据了 |
| | | /// 需要等初始化本地设备数据后在可以初始化房间数据 |
| | | /// </summary> |
| | | public static bool CanInitAllRoom; |
| | | |
| | | /// <summary> |
| | | /// 获取喜爱房间的所有设备路径 |
| | |
| | | get |
| | | { |
| | | List<DeviceUI> deviceList = new List<DeviceUI>(); |
| | | foreach (var room in Lists) |
| | | { |
| | | for (int i = 0; i < Lists.Count; i++) |
| | | {
|
| | | var room = Lists[i]; |
| | | if (room.IsSharedRoom) |
| | | { |
| | | continue; |
| | |
| | | { |
| | | continue; |
| | | } |
| | | foreach (var device in room.DeviceUIList) |
| | | for (int j = 0; j < room.DeviceUIList.Count; j++) |
| | | { |
| | | var device = room.DeviceUIList[j]; |
| | | if (device == null || device.CommonDevice == null) |
| | | { |
| | | continue; |
| | |
| | | /// </summary> |
| | | public static void InitAllRoom() |
| | | { |
| | | if (CanInitAllRoom == false) |
| | | { |
| | | return; |
| | | } |
| | | Lists.Clear(); |
| | | 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 = LoveRoomId }; |
| | | love.Save(true); |
| | | var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "RoomIcon/0.JPG", Id = LoveRoomId }; |
| | | love.Save(false); |
| | | //添加到house 房间路径列表 |
| | | var currentHome = Config.Instance.Home; |
| | | currentHome.RoomFilePathList.Insert(0, love.FileName); |
| | | currentHome.Save(); |
| | | currentHome.Save(false); |
| | | } |
| | | foreach (var roomFilePath in Config.Instance.Home.RoomFilePathList) |
| | | { |
| | |
| | | { |
| | | if (room.IsSharedRoom) |
| | | { |
| | | room.Name = $"({Language.StringByID(R.MyInternationalizationString.Shared)}){room.Name}"; |
| | | room.Name = $"{room.Name}"; |
| | | } |
| | | Lists.Add(room); |
| | | |
| | | } |
| | | } |
| | | Config.Instance.Home.InitFloor(); |
| | | } |
| | | |
| | | /// <summary>
|
| | |
| | | }
|
| | | }
|
| | | homeTemp.Save(false);
|
| | | CanInitAllRoom = true;
|
| | | InitAllRoom();
|
| | | } |
| | | |
| | |
| | | /// <param name="roomId">房间ID</param> |
| | | public Room GetRoomById(string roomId) |
| | | { |
| | | if (string.IsNullOrEmpty(roomId)) |
| | | { |
| | | return null; |
| | | } |
| | | return Lists.Find((obj) => obj.Id == roomId); |
| | | } |
| | | |
| | |
| | | /// <param name="device">设备对象</param> |
| | | public Room GetRoomByDevice(CommonDevice device) |
| | | { |
| | | var deviceUI = new DeviceUI { };
|
| | | deviceUI.DeviceAddr = device.DeviceAddr;
|
| | | deviceUI.DeviceEpoint = device.DeviceEpoint; |
| | | |
| | | return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceUI.FileName)); |
| | | string deviceFile = device.FilePath; |
| | | return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceFile)); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | foreach (var r in Lists) |
| | | { |
| | | if (r.IsLove) |
| | | { |
| | | continue; |
| | | } |
| | | foreach (var scene in r.SceneUIList) |
| | | { |
| | | if (scene.Id == sceneId) |
| | |
| | | /// <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; |
| | |
| | | /// </summary> |
| | | /// <param name="device">设备对象</param> |
| | | /// <param name="roomId">新房间Id</param> |
| | | public void ChangedRoom(CommonDevice device, string roomId) |
| | | /// <param name="saveRealRoom">是否修改真实物理设备的房间,不出意外,这个值默认为true即可</param> |
| | | public void ChangedRoom(CommonDevice device, string roomId, bool saveRealRoom = true) |
| | | { |
| | | //房间是否修改 |
| | | if (this.IsRoomChanged(device, roomId) == false) |
| | |
| | | var room = this.GetRoomById(roomId); |
| | | if (room != null)
|
| | | {
|
| | | room.AddDevice(device);
|
| | | room.AddDevice(device, saveRealRoom);
|
| | | } |
| | | }
|
| | |
|
| | |
| | | #region ◆ 添加设备________________________ |
| | | |
| | | /// <summary> |
| | | /// 添加设备 |
| | | /// 添加设备(此方法目前只给【我的喜爱】使用) |
| | | /// </summary> |
| | | /// <param name="deviceUIFilePath">Device UIF ile path.</param> |
| | | public void AddDevice(string deviceUIFilePath) |
| | |
| | | { |
| | | return; |
| | | } |
| | | var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(deviceUIFilePath)); |
| | | var deviceUI = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceUI>(jsonInfo); |
| | | if (null == deviceUI || null == deviceUI.CommonDevice) |
| | | var deviceUI = Common.LocalDevice.Current.GetDeviceUI(deviceUIFilePath); |
| | | if (null == deviceUI.CommonDevice) |
| | | { |
| | | //当前对象数据无效 |
| | | return; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加设备 |
| | | /// 添加设备(此方法目前只给Room里面使用) |
| | | /// </summary> |
| | | /// <param name="device">要添加的设备对象</param> |
| | | public void AddDevice(CommonDevice device) |
| | | /// <param name="saveRealRoom">是否修改真实物理设备的房间,不出意外,这个值默认为true即可</param> |
| | | public void AddDevice(CommonDevice device, bool saveRealRoom) |
| | | { |
| | | if (device == null) |
| | | { |
| | |
| | | //设备信息保存到本地 |
| | | device.Save(); |
| | | |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); |
| | | |
| | | DeviceUI deviceUI = Common.LocalDevice.Current.GetDeviceUI(device); |
| | | var deviceUI = Common.LocalDevice.Current.GetDeviceUI(device); |
| | | if (DeviceUIFilePathList.Contains(deviceUI.FileName) == false) |
| | | { |
| | | DeviceUIFilePathList.Add(deviceUI.FileName); |
| | |
| | | |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(FileName); |
| | | if (saveRealRoom == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1)
|
| | | {
|
| | | //如果只有一个回路,则修改真实物理设备的房间
|
| | | LocalDevice.Current.SaveRealDeviceRoomId(new List<CommonDevice>() { device }, this.Id, false);
|
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | public void DeleteDevice(string deviceUIFilePath) |
| | | { |
| | | if (deviceUIFilePath == null) return; |
| | | if (DeviceUIFilePathList.Contains(deviceUIFilePath) && Global.IsExistsByHomeId(deviceUIFilePath)) |
| | | if (DeviceUIFilePathList.Contains(deviceUIFilePath)) |
| | | { |
| | | DeviceUIFilePathList.Remove(deviceUIFilePath); |
| | | DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUIFilePath); |
| | | HdlAutoBackupLogic.DeleteFile(deviceUIFilePath); |
| | | Save(); |
| | | } |
| | | } |
| | |
| | | { |
| | | return; |
| | | } |
| | | DeviceUI deviceUI = new DeviceUI(); |
| | | deviceUI.DeviceAddr = device.DeviceAddr;
|
| | | deviceUI.DeviceEpoint = device.DeviceEpoint; |
| | | |
| | | //根据设备,获取所在的房间 |
| | | var room = this.GetRoomByDevice(device); |
| | | if (room == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | string deviceFile = device.FilePath;
|
| | | //移除缓存
|
| | | if (room.DeviceUIFilePathList.Contains(deviceUI.FileName) == false)
|
| | | if (room.DeviceUIFilePathList.Contains(deviceFile) == false)
|
| | | {
|
| | | return;
|
| | | }
|
| | | room.DeviceUIFilePathList.Remove(deviceUI.FileName);
|
| | | room.DeviceUIFilePathList.Remove(deviceFile);
|
| | |
|
| | | room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUI.FileName);
|
| | | room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceFile);
|
| | | room.Save();
|
| | | //更改自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(room.FileName); |
| | |
| | | }
|
| | | listDevice.Add(device.CommonDevice);
|
| | | }
|
| | | if (listDevice.Count == 0)
|
| | | {
|
| | | return listDevice;
|
| | | }
|
| | | return Common.LocalDevice.Current.SortDevice(listDevice);
|
| | | return listDevice;
|
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | Save(); |
| | | Global.DeleteFilebyHomeId(sceneUI.FileName); |
| | | HdlAutoBackupLogic.DeleteFile(sceneUI.FileName); |
| | | HdlAutoBackupLogic.AddOrEditorFile(FileName); |
| | | } |
| | | |
| | | #endregion |
| | |
| | | { |
| | | foreach (var r in Lists) |
| | | { |
| | | if (r.IsLove) |
| | | { |
| | | continue; |
| | | } |
| | | foreach (var sceneUI in r.SceneUIList) |
| | | { |
| | | if (sceneUI.Id == sceneId) |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取该楼层所有场景 |
| | | /// </summary> |