| | |
| | | /// 设备的总回路(keys:Mac地址 value:全部端口号)
|
| | | /// </summary>
|
| | | private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>(); |
| | | /// <summary>
|
| | | /// 物理设备属于哪个房间的记录
|
| | | /// </summary>
|
| | | private Dictionary<string, string> dicDeviceRoomId = null; |
| | | |
| | | #endregion
|
| | | |
| | |
| | | //成员身份的时候,删除掉非法的网关文件 |
| | | this.DeleteGatewayFileByMemberModel(); |
| | | //初始化物理设备所属房间的记录 |
| | | this.InitRealDeviceRoomId(); |
| | | HdlRoomLogic.Current.InitRealDeviceRoomId(); |
| | | |
| | | #if DEBUG
|
| | | if (UserCenterResourse.HideOption.CenterHideMenu == 1) |
| | |
| | | if (listDeleteMac.Count > 0) |
| | | { |
| | | //将真实物理设备从房间中移除 |
| | | this.DeleteRealDeviceFromRoom(listDeleteMac); |
| | | HdlRoomLogic.Current.DeleteRealDeviceFromRoom(listDeleteMac); |
| | | } |
| | | |
| | | return statu; |
| | |
| | | { |
| | | this.DeleteMemmoryDevice(device); |
| | | } |
| | | |
| | | if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true) |
| | | { |
| | | //移除真实设备的房间索引 |
| | | this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr); |
| | | this.SaveRealDeviceRoomId(null, null); |
| | | } |
| | | HdlRoomLogic.Current.DeleteRealDeviceFromRoom(listdevice[0]); |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | //面板的温度探头叫 面板名字+温度 |
| | | return deviceInfoType.DeviceDefultName + Language.StringByID(R.MyInternationalizationString.uTemperature); |
| | | } |
| | | else if (deviceInfoType.BeloneType == DeviceBeloneType.A空气质量) |
| | | { |
| | | |
| | | //空气质量传感器的温度探头叫空气质量传感器+温度 |
| | | return deviceInfoType.DeviceDefultName + Language.StringByID(R.MyInternationalizationString.TemperatureSensor); |
| | | } |
| | | else if (((TemperatureSensor)device).SensorDiv == 1) |
| | | { |
| | | //温度传感器 |
| | |
| | | { |
| | | bool temperatrue = false; |
| | | bool humidity = false; |
| | | bool airQualitySensor = false; |
| | | //获取全部的回路 |
| | | var listTemp = this.GetDevicesByMac(listdevice[0].DeviceAddr, false); |
| | | foreach (var device in listTemp) |
| | | { |
| | | if (device is TemperatureSensor) |
| | | { |
| | | //空气质量传感器 |
| | | if (device.isAirQualitySensor(device)) |
| | | { |
| | | airQualitySensor = true; |
| | | } |
| | | //温度传感器 |
| | | if (((TemperatureSensor)device).SensorDiv == 1) |
| | | { |
| | |
| | | info.ConcreteType = DeviceConcreteType.Sensor_Humidity; |
| | | } |
| | | info.ObjectTypeName = this.dicDeviceModelIdEnum["A411"].A类型名字;//传感器 |
| | | |
| | | //空气质量传感器 |
| | | if (airQualitySensor == true) |
| | | { |
| | | info.ConcreteText = this.dicDeviceModelIdEnum["A422"].A官方名字; |
| | | info.BeloneType = DeviceBeloneType.A空气质量; |
| | | info.ConcreteType = DeviceConcreteType.AirQualitySensor; |
| | | info.ObjectTypeName = this.dicDeviceModelIdEnum["A422"].A类型名字; |
| | | } |
| | | } |
| | | //14新风设备 |
| | | else if (dicType.ContainsKey(DeviceType.FreshAir) == true) |
| | |
| | | info.BeloneType = DeviceBeloneType.A晾衣架; |
| | | info.ConcreteType = DeviceConcreteType.Airer; |
| | | info.ObjectTypeName = this.dicDeviceModelIdEnum["A421"].A类型名字; |
| | | } |
| | | //18空气质量传感器 |
| | | else if (dicType.ContainsKey(DeviceType.AirQualitySensor) == true) |
| | | { |
| | | info.ConcreteText = this.dicDeviceModelIdEnum["A422"].A官方名字; |
| | | info.BeloneType = DeviceBeloneType.A空气质量; |
| | | info.ConcreteType = DeviceConcreteType.AirQualitySensor; |
| | | info.ObjectTypeName = this.dicDeviceModelIdEnum["A422"].A类型名字; |
| | | } |
| | | |
| | | //设备所属类型的翻译名字 |
| | |
| | | info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow; |
| | | info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uSensorDoorWindow); |
| | | } |
| | | } |
| | | |
| | | #endregion
|
| | | |
| | | #region ■ 物理设备所属房间___________________
|
| | | |
| | | /// <summary>
|
| | | /// 初始化物理设备所属房间的记录
|
| | | /// </summary>
|
| | | private void InitRealDeviceRoomId() |
| | | { |
| | | this.dicDeviceRoomId = new Dictionary<string, string>(); |
| | | string fullName = DirNameResourse.DeviceRoomIdFile; |
| | | var strData = HdlFileLogic.Current.ReadFileTextContent(fullName); |
| | | if (strData != null) |
| | | { |
| | | this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData); |
| | | } |
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 获取全部物理设备所属房间的记录
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public Dictionary<string, string> GetAllRealDeviceRoomData() |
| | | { |
| | | return this.dicDeviceRoomId; |
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 保存物理设备所属房间的记录
|
| | | /// </summary>
|
| | | /// <param name="listDevice">需要保存的设备对象</param>
|
| | | /// <param name="roomId">需要保存的哪个设备的房间ID</param>
|
| | | /// <param name="saveRoadDevice">如果只有一个回路,是否把回路的房间一起修改</param>
|
| | | public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true) |
| | | { |
| | | if (listDevice == null || listDevice.Count == 0) |
| | | { |
| | | return; |
| | | } |
| | | //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了 |
| | | if (saveRoadDevice == true && listDevice.Count == 1) |
| | | { |
| | | if ((listDevice[0] is OTADevice) == false) |
| | | { |
| | | //ota设备不需要处理 |
| | | HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false); |
| | | } |
| | | } |
| | | bool save = false; |
| | | if (roomId == string.Empty) |
| | | { |
| | | //选择的是未分配 |
| | | this.dicDeviceRoomId.Remove(listDevice[0].DeviceAddr); |
| | | save = true; |
| | | } |
| | | else |
| | | { |
| | | if (this.dicDeviceRoomId.ContainsKey(listDevice[0].DeviceAddr) == false) |
| | | { |
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId; |
| | | save = true; |
| | | } |
| | | else |
| | | { |
| | | //2020.05.18追加:如果记录的房间ID是不存在的话,则重新覆盖 |
| | | var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[listDevice[0].DeviceAddr]); |
| | | if (room == null || this.dicDeviceRoomId[listDevice[0].DeviceAddr] != roomId) |
| | | { |
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId; |
| | | save = true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (save == true) |
| | | { |
| | | //保存记录 |
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId); |
| | | |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile); |
| | | } |
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 获取真实物理设备的房间名字
|
| | | /// </summary>
|
| | | /// <param name="device">设备的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public string GeteRealDeviceRoomName(CommonDevice device) |
| | | { |
| | | if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false) |
| | | { |
| | | //未分配区域 |
| | | return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom); |
| | | } |
| | | var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]); |
| | | return HdlRoomLogic.Current.GetRoomName(room); |
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 获取真实物理设备属于哪个房间
|
| | | /// </summary>
|
| | | /// <param name="device">设备的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public Room GeteRealDeviceRoom(CommonDevice device) |
| | | { |
| | | if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false) |
| | | { |
| | | return null; |
| | | } |
| | | return HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]); |
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 将真实物理设备从房间中移除
|
| | | /// </summary>
|
| | | /// <param name="device">随便一个回路</param>
|
| | | public void DeleteRealDeviceFromRoom(CommonDevice device) |
| | | { |
| | | //将真实物理设备从房间中移除 |
| | | this.DeleteRealDeviceFromRoom(new List<string>() { device.DeviceAddr }); |
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 将真实物理设备从房间中移除
|
| | | /// </summary>
|
| | | /// <param name="listMac">设备Mac地址</param>
|
| | | public void DeleteRealDeviceFromRoom(List<string> listMac) |
| | | { |
| | | bool save = false; |
| | | foreach (var deviceMacAddr in listMac) |
| | | { |
| | | if (this.dicDeviceRoomId.ContainsKey(deviceMacAddr) == true) |
| | | { |
| | | this.dicDeviceRoomId.Remove(deviceMacAddr); |
| | | save = true; |
| | | } |
| | | } |
| | | if (save == false) |
| | | { |
| | | //没有改变,不需要保存 |
| | | return; |
| | | } |
| | | //保存记录 |
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId); |
| | | |
| | | //添加自动备份 |
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile); |
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 根据房间ID,移除指定的真实物理设备的所属房间记录
|
| | | /// </summary>
|
| | | /// <param name="i_RoomId"></param>
|
| | | public void DeleteRealDeviceByRoomId(string i_RoomId) |
| | | { |
| | | var listDeleteKey = new List<string>(); |
| | | foreach (var deviceAddr in this.dicDeviceRoomId.Keys) |
| | | { |
| | | if (this.dicDeviceRoomId[deviceAddr] == i_RoomId |
| | | && listDeleteKey.Contains(deviceAddr) == false) |
| | | { |
| | | listDeleteKey.Add(deviceAddr); |
| | | } |
| | | } |
| | | //将真实物理设备从房间中移除 |
| | | this.DeleteRealDeviceFromRoom(listDeleteKey); |
| | | } |
| | | |
| | | #endregion
|
| | |
| | | return list; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 晾衣架设备时间配置___________________________ |
| | | /// <summary> |
| | | /// 设置晾衣架风干,烘干和消毒时间(设置失败时,会显示信息) |
| | | /// time:设置的分钟 |
| | | /// </summary> |
| | | /// <param name="litdevice">设备对象(MAC地址必须要相同)</param> |
| | | public async Task<bool> SetAirerTimeDevice(List<CommonDevice> listdevice, Airer airer, int time, int controlEpoint) |
| | | { |
| | | //虚拟住宅的话,不需要 |
| | | if (Config.Instance.Home.IsVirtually == false) |
| | | { |
| | | foreach (var dev in listdevice) |
| | | { |
| | | //设置属性信息 |
| | | CommonDevice.SetWritableValueData dataT = new CommonDevice.SetWritableValueData(); |
| | | dataT.Undivided = 0; |
| | | dataT.AttributeId = 16385; |
| | | dataT.AttributeDataType = 33; |
| | | dataT.AttributeData = time; |
| | | dev.DeviceEpoint = controlEpoint;//暂时换成晾衣架对应的控制端点 |
| | | var result = await dev.SetWritableValueAsync(6, dataT); |
| | | if (result == null || result.setWritableValueResponData == null || result.setWritableValueResponData.Status != 0) |
| | | { |
| | | //设置失败 |
| | | if (dev.DeviceEpoint == 3) |
| | | { |
| | | if (airer.WindTime != 0) |
| | | { |
| | | airer.WindTime = 0; |
| | | } |
| | | string msg = Language.StringByID(R.MyInternationalizationString.AirerWindTimeFailed); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); |
| | | dev.DeviceEpoint = 1;//将晾衣架对应的控制端点还原成1端点 |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | if (dev.DeviceEpoint == 4) |
| | | { |
| | | if (airer.DryTime != 0) |
| | | { |
| | | airer.DryTime = 0; |
| | | } |
| | | string msg = Language.StringByID(R.MyInternationalizationString.AirerDryTimeFailed); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); |
| | | dev.DeviceEpoint = 1;//将晾衣架对应的控制端点还原成1端点 |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | if (dev.DeviceEpoint == 5) |
| | | { |
| | | if (airer.DisinfectTime != 0) |
| | | { |
| | | airer.DisinfectTime = 0; |
| | | } |
| | | string msg = Language.StringByID(R.MyInternationalizationString.AirerDisinfectTimeFailed); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); |
| | | this.ShowErrorMsg(msg); |
| | | dev.DeviceEpoint = 1;//将晾衣架对应的控制端点还原成1端点 |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | #endregion
|
| | | |
| | | #region ■ 一般方法___________________________
|
| | |
| | | }); |
| | | } |
| | | |
| | | #region ■ 晾衣架设备时间配置___________________________
|
| | | /// <summary>
|
| | | /// 设置晾衣架风干,烘干和消毒时间(设置失败时,会显示信息)
|
| | | /// time:设置的分钟
|
| | | /// </summary>
|
| | | /// <param name="litdevice">设备对象(MAC地址必须要相同)</param>
|
| | | public async Task<bool> SetAirerTimeDevice(List<CommonDevice> listdevice, Airer airer, int time, int controlEpoint) |
| | | { |
| | | //虚拟住宅的话,不需要 |
| | | if (Config.Instance.Home.IsVirtually == false) |
| | | { |
| | | foreach (var dev in listdevice) |
| | | { |
| | | //设置属性信息 |
| | | CommonDevice.SetWritableValueData dataT = new CommonDevice.SetWritableValueData(); |
| | | dataT.Undivided = 0; |
| | | dataT.AttributeId = 16385; |
| | | dataT.AttributeDataType = 33; |
| | | dataT.AttributeData = time; |
| | | dev.DeviceEpoint = controlEpoint;//暂时换成晾衣架对应的控制端点 |
| | | var result = await dev.SetWritableValueAsync(6, dataT); |
| | | if (result == null || result.setWritableValueResponData == null || result.setWritableValueResponData.Status != 0) |
| | | { |
| | | //设置失败 |
| | | if (dev.DeviceEpoint == 3) |
| | | { |
| | | if (airer.WindTime != 0) |
| | | { |
| | | airer.WindTime = 0; |
| | | } |
| | | string msg = Language.StringByID(R.MyInternationalizationString.AirerWindTimeFailed); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); |
| | | dev.DeviceEpoint = 1;//将晾衣架对应的控制端点还原成1端点 |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | if (dev.DeviceEpoint == 4) |
| | | { |
| | | if (airer.DryTime != 0) |
| | | { |
| | | airer.DryTime = 0; |
| | | } |
| | | string msg = Language.StringByID(R.MyInternationalizationString.AirerDryTimeFailed); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); |
| | | dev.DeviceEpoint = 1;//将晾衣架对应的控制端点还原成1端点 |
| | | this.ShowErrorMsg(msg); |
| | | return false; |
| | | } |
| | | if (dev.DeviceEpoint == 5) |
| | | { |
| | | if (airer.DisinfectTime != 0) |
| | | { |
| | | airer.DisinfectTime = 0; |
| | | } |
| | | string msg = Language.StringByID(R.MyInternationalizationString.AirerDisinfectTimeFailed); |
| | | //拼接上【网关回复超时】的Msg |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); |
| | | this.ShowErrorMsg(msg); |
| | | dev.DeviceEpoint = 1;//将晾衣架对应的控制端点还原成1端点 |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | #endregion
|
| | | #endregion
|
| | | |
| | | //----------------------------------分割线(自定义接口)--------------------------------------------- |