old mode 100644
new mode 100755
| | |
| | | this.dicDeviceEpoint.Clear();
|
| | |
|
| | | //初始化设备枚举
|
| | | this.InitDeviceModelIdEnum(); |
| | | this.InitDeviceModelIdEnum();
|
| | | |
| | | //获取本地全部的设备文件 |
| | | List<string> listFile = this.GetAllDeviceFile(); |
| | |
| | | {
|
| | | CommonDevice device = null;
|
| | | //反序列化为指定的类,不然数据会丢失而导致无法强转
|
| | | try |
| | | try
|
| | | {
|
| | | device = CommonDevice.CommonDeviceByFilePath(file);
|
| | | //读取它的内容
|
| | | var fileData = HdlFileLogic.Current.ReadFileTextContent(System.IO.Path.Combine(Config.Instance.FullPath, file));
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(fileData);
|
| | | if (jobject.Property("DeviceID") == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | device = CommonDevice.CommonDeviceByByteString(Convert.ToInt32(jobject["DeviceID"].ToString()), fileData);
|
| | | }
|
| | | catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
|
| | |
|
| | |
| | | }
|
| | | this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint);
|
| | |
|
| | | //对应旧版本的设备文件 Device_OnoffOutput_abcdfrtgg_01
|
| | | bool bolSave = file.Split(new string[] { "_" }, StringSplitOptions.None).Length == 4;
|
| | | if (bolSave == true)
|
| | | {
|
| | | //删掉这个文件,重新生成
|
| | | HdlAutoBackupLogic.DeleteFile(file);
|
| | | Global.DeleteFilebyHomeId(file);
|
| | | }
|
| | |
|
| | | //检测Ui图片是否正确,这个图片本地是否存在?
|
| | | if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(device.IconPath)) == true)
|
| | | {
|
| | | //不存在的话,重新生成
|
| | | device.IconPath = string.Empty;
|
| | | device.ReSave();
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | |
|
| | | bolSave = false;
|
| | | }
|
| | | //重新生成文件
|
| | | if (bolSave == true)
|
| | | {
|
| | | device.ReSave();
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | | }
|
| | |
| | | this.DeleteGatewayFileByMemberModel(); |
| | | //初始化物理设备所属房间的记录 |
| | | this.InitRealDeviceRoomId(); |
| | |
|
| | | #if DEBUG
|
| | | if (UserCenterResourse.HideOption.CenterHideMenu == 1)
|
| | | {
|
| | | //检测一些代码配置(debug)
|
| | | this.CheckOhtherSettion();
|
| | | }
|
| | | #endif
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | {
|
| | | //这个网关对于当前这个成员来说是非法的
|
| | | HdlGatewayLogic.Current.DeleteGatewayFile(gwId);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测一些代码配置(debug)
|
| | | /// </summary>
|
| | | private void CheckOhtherSettion()
|
| | | {
|
| | | foreach (var item in Enum.GetValues(typeof(DeviceType)))
|
| | | {
|
| | | string itemName = item.ToString();
|
| | | int itemValue = (int)item;
|
| | | if (itemName == "UnKown" || itemName == "ZbGateway")
|
| | | {
|
| | | continue;
|
| | | }
|
| | | var device = this.NewDeviceObjectByDeviceId((DeviceType)itemValue);
|
| | | string strMsg = string.Empty;
|
| | | if (device == null)
|
| | | {
|
| | | strMsg = itemName + "没有实装(1)";
|
| | | }
|
| | | device = CommonDevice.CommonDeviceByByteString(itemValue, "{}");
|
| | | if (device == null)
|
| | | {
|
| | | strMsg += "\r\n" + itemName + "没有实装(2)";
|
| | | }
|
| | | if (strMsg != string.Empty)
|
| | | {
|
| | | this.ShowErrorMsg(strMsg);
|
| | | return;
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | dicExist.Remove(maikey);
|
| | | }
|
| | | //获取设备的固定属性
|
| | | HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device);
|
| | | if (HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device) == true)
|
| | | {
|
| | | System.Threading.Thread.Sleep(200);
|
| | | }
|
| | | //对未命名的虚拟设备重新命名
|
| | | if (device.DriveCode > 0 && this.GetSimpleEpointName(device) == string.Empty)
|
| | | {
|
| | | listDriveDevice.Add(device);
|
| | | }
|
| | | }
|
| | | if (listDriveDevice.Count > 0)
|
| | | {
|
| | | //如果虚拟设备还没有名字的话
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //如果不这样放在一个线程里,有可能对Dictionary产生影响
|
| | | foreach (var myDevice in listDriveDevice)
|
| | | {
|
| | | //根据设备类型获取名称
|
| | | var dName = this.GetDeviceObjectText(new List<CommonDevice>() { myDevice }, false);
|
| | | //在端点名字的后面附加【回路】字样
|
| | | dName += "(" + myDevice.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
|
| | | this.ReName(myDevice, dName, ShowErrorMode.NO);
|
| | | }
|
| | | });
|
| | | }
|
| | | //设置虚拟设备的默认名字
|
| | | this.SetDriveDeviceDefultName(listDriveDevice);
|
| | |
|
| | | //只有完全获取的时候,才会去处理删除的问题
|
| | | if (statu != 1)
|
| | |
| | | public void AddVirtualDeviceToMemory(CommonDevice device)
|
| | | {
|
| | | string mainKeys = this.GetDeviceMainKeys(device);
|
| | | if (device is OTADevice)
|
| | | {
|
| | | this.dicOTADevice[mainKeys] = (OTADevice)device;
|
| | | device.ReSave();
|
| | | return;
|
| | | }
|
| | | this.dicAllDevice[mainKeys] = device;
|
| | |
|
| | | //设备回路收集
|
| | |
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置虚拟设备的默认名字
|
| | | /// </summary>
|
| | | /// <param name="listDriveDevice">虚拟设备列表</param>
|
| | | private void SetDriveDeviceDefultName(List<CommonDevice> listDriveDevice)
|
| | | {
|
| | | if (listDriveDevice.Count == 0)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //如果虚拟设备还没有名字的话
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //如果不这样放在一个线程里,有可能对Dictionary产生影响
|
| | | foreach (var myDevice in listDriveDevice)
|
| | | {
|
| | | string dName = string.Empty;
|
| | | if (this.IsMiniLight(myDevice) == true)
|
| | | {
|
| | | //Mini夜灯
|
| | | dName = Language.StringByID(R.MyInternationalizationString.uMiniNightLight);
|
| | | }
|
| | | else
|
| | | {
|
| | | //根据设备类型获取名称
|
| | | dName = this.GetDeviceObjectText(new List<CommonDevice>() { myDevice }, false);
|
| | | //在端点名字的后面附加【回路】字样
|
| | | dName += "(" + myDevice.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
|
| | | }
|
| | | this.ReName(myDevice, dName, ShowErrorMode.NO);
|
| | |
|
| | | System.Threading.Thread.Sleep(100);
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | ///<summary >
|
| | | /// 修改设备mac名称
|
| | | /// <para>macName:设备名称</para>
|
| | |
| | | //如果当前是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | return Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceMacName(device, macName, "MacRename");
|
| | | return Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceMacName(device, macName);
|
| | | }
|
| | |
|
| | | //获取编辑设备Mac名字的命令字符
|
| | |
| | | return null;
|
| | | }
|
| | | //加缓存
|
| | | Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceMacName(device, macName, "MacRename");
|
| | | Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceMacName(device, macName);
|
| | |
|
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RenameDeviceMacNameData>(result.ReceiptData);
|
| | | return new CommonDevice.RenameDeviceMacNameAllData { renameDeviceMacNameData = tempData };
|
| | |
| | | //如果当前是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | return Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceEpointName(device, deviceName, "DeviceRename");
|
| | | return Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceEpointName(device, deviceName);
|
| | | }
|
| | | //获取编辑设备端点名字的命令字符
|
| | | var sendData = this.GetReDeviceEpointNameCommandText(device.DeviceAddr, device.DeviceEpoint, deviceName);
|
| | |
| | | return null;
|
| | | }
|
| | | //加缓存
|
| | | Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceEpointName(device, deviceName, "DeviceRename");
|
| | | Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceEpointName(device, deviceName);
|
| | |
|
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceRenameResponseData>(result.ReceiptData);
|
| | | return new CommonDevice.DeviceRenameAllData { deviceRenameData = tempData };
|
| | |
| | | this.dicDeviceEpoint[device.DeviceAddr].Remove(device.DeviceEpoint);
|
| | | }
|
| | | }
|
| | | //删除模板数据
|
| | | Phone.TemplateData.TemplateCommonLogic.Current.DeleteDevice(device);
|
| | |
|
| | | //删除设备文件
|
| | | string filePath = device.FilePath;
|
| | |
| | | /// <summary>
|
| | | /// 发送定位指令到设备
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | public void SetFixedPositionCommand(CommonDevice device)
|
| | | /// <param name="device">设备回路</param>
|
| | | /// <param name="isRealDevice">是否是定位真实设备</param>
|
| | | public void SetFixedPositionCommand(CommonDevice device, bool isRealDevice = false)
|
| | | {
|
| | | //如果当前住宅不是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == false)
|
| | | {
|
| | | device.IdentifyControl(device.DeviceAddr, device.DeviceEpoint, 5);
|
| | | int epoint = device.DeviceEpoint;
|
| | | //如果是定位真实设备的话
|
| | | if (isRealDevice == true)
|
| | | {
|
| | | var myType = this.GetMyDeviceEnumInfo(new List<CommonDevice> { device });
|
| | | if (myType.ConcreteType == DeviceConcreteType.DimmableLight_OneLoad)
|
| | | {
|
| | | //一路调光器需要发8回路
|
| | | epoint = 8;
|
| | | }
|
| | | }
|
| | | device.IdentifyControl(device.DeviceAddr, epoint, 5);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | //门锁没有定位功能
|
| | | return false;
|
| | | }
|
| | | var myTypeInfo = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
|
| | | if (device.Type == DeviceType.IASZone)
|
| | | {
|
| | | var myTypeInfo = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
|
| | | if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_Pir)
|
| | | {
|
| | | //传感器除了Pir都没有定位功能
|
| | |
| | | //球型移动传感器虽然是电池设备,但是它有定位功能
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | | //温湿度传感器没有定位功能
|
| | | if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_TemperatureHumidity)
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
|
| | |
| | | /// <returns></returns>
|
| | | public bool SendDeviceFunctionTypeToGateway(CommonDevice device, DeviceFunctionType functionType)
|
| | | {
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 110 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "FunctionType", (int)functionType } };
|
| | | jObject.Add("Data", data);
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Device/SetEPDeviceFunctionType", jObject.ToString(), "Device/SetEPDeviceFunctionTypeRespon");
|
| | | //如果是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | device.DfunctionType = functionType;
|
| | | return true;
|
| | | }
|
| | | //获取命令字符
|
| | | var sendCommond = this.GetDeviceFunctionTypeCommandText(device, functionType);
|
| | | var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Device/SetEPDeviceFunctionType", sendCommond, "Device/SetEPDeviceFunctionTypeRespon");
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return false;
|
| | |
| | | return resultData["Result"].ToString() == "0";
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取更改设备功能类型的命令文本
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | /// <param name="functionType"></param>
|
| | | /// <returns></returns>
|
| | | public string GetDeviceFunctionTypeCommandText(CommonDevice device, DeviceFunctionType functionType)
|
| | | {
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 110 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "FunctionType", (int)functionType } };
|
| | | jObject.Add("Data", data);
|
| | | return jObject.ToString();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | else
|
| | | {
|
| | | var infoContent = this.GetDeviceModelIdNameInfo("A419");
|
| | | return infoContent != null ? infoContent.A官方名字 : string.Empty;
|
| | | return infoContent != null ? infoContent.A官方名字 + epointNo : string.Empty;
|
| | | }
|
| | | }
|
| | | else if (device.Type == DeviceType.FreshAirHumiditySensor)
|
| | |
| | | {
|
| | | if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir
|
| | | || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment
|
| | | || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueEnvironment
|
| | | || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
|
| | | {
|
| | | //新风面板/简约多功能/简约环境面板 温度传感器
|
| | | //新风面板/简约多功能/简约/方悦环境面板 温度传感器
|
| | | return deviceInfoType.DeviceDefultName + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
|
| | | }
|
| | | else if (deviceInfoType.BeloneType == DeviceBeloneType.A按键面板)
|
| | | {
|
| | | //面板的温度探头叫 面板名字+温度
|
| | | return deviceInfoType.DeviceDefultName + Language.StringByID(R.MyInternationalizationString.uTemperature);
|
| | | }
|
| | | else if (((TemperatureSensor)device).SensorDiv == 1)
|
| | | {
|
| | | //温度传感器
|
| | | return Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
|
| | | }
|
| | | else if (((TemperatureSensor)device).SensorDiv == 2)
|
| | | {
|
| | | //湿度传感器
|
| | | return Language.StringByID(R.MyInternationalizationString.HumiditySensor);
|
| | | }
|
| | | }
|
| | | //其他情况,使用它的默认名称
|
| | |
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="macName">Mac名字</param>
|
| | | /// <returns></returns>
|
| | | private void SetMacName(CommonDevice device, string macName)
|
| | | public void SetMacName(CommonDevice device, string macName)
|
| | | {
|
| | | device.DeviceName = macName;
|
| | | }
|
| | |
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="epointName">端点名字</param>
|
| | | /// <returns></returns>
|
| | | private void SetEpointName(CommonDevice device, string epointName)
|
| | | public void SetEpointName(CommonDevice device, string epointName)
|
| | | {
|
| | | device.DeviceEpointName = epointName;
|
| | | }
|
| | |
| | | /// <summary>
|
| | | /// 获取【设备功能类型】的菜单图标
|
| | | /// </summary>
|
| | | /// <param name="specificType">自定义设备类型</param>
|
| | | /// <param name="deviceEnumInfo">自定义设备类型</param>
|
| | | /// <param name="unSelectPath">图片地址</param>
|
| | | /// <param name="selectPath">图片地址</param>
|
| | | /// <returns></returns>
|
| | | public void GetDeviceFunctionTypeMenuIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath)
|
| | | public void GetDeviceFunctionTypeMenuIcon(DeviceEnumInfo deviceEnumInfo, ref string unSelectPath, ref string selectPath)
|
| | | {
|
| | | //新风小模块
|
| | | if (specificType == DeviceConcreteType.Relay_FangyueFreshAirModul)
|
| | | if (deviceEnumInfo.ConcreteType == DeviceConcreteType.Relay_FangyueFreshAirModul)
|
| | | {
|
| | | unSelectPath = "Device/FreshAirEpoint.png";
|
| | | selectPath = "Device/FreshAirEpointSelected.png";
|
| | | return;
|
| | | }
|
| | | //PM2.5空气质量传感器
|
| | | else if (specificType == DeviceConcreteType.Sensor_PMTwoPointFive)
|
| | | else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.Sensor_PMTwoPointFive)
|
| | | {
|
| | | unSelectPath = "Device/AirQualitySensorEpoint.png";
|
| | | selectPath = "Device/AirQualitySensorEpointSelected.png";
|
| | | return;
|
| | | }
|
| | | else if (deviceEnumInfo.BeloneType == DeviceBeloneType.A窗帘)
|
| | | {
|
| | | unSelectPath = "ZigeeLogic/curtain.png";
|
| | | selectPath = "ZigeeLogic/selectedcurtain.png";
|
| | | return;
|
| | | }
|
| | | //上面需要特殊处理
|
| | |
|
| | | //获取【设备类型】的图标
|
| | | this.GetDeviceObjectIcon(specificType, ref unSelectPath, ref selectPath);
|
| | | this.GetDeviceObjectIcon(deviceEnumInfo.ConcreteType, ref unSelectPath, ref selectPath);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | info.ObjectTypeName = this.dicDeviceModelIdEnum["A418"].A类型名字;//调光模块
|
| | | }
|
| | | else if (info.BeloneType == DeviceBeloneType.A传感器
|
| | | || device.Type == DeviceType.TemperatureSensor)
|
| | | || device.Type == DeviceType.TemperatureSensor
|
| | | || device.Type == DeviceType.FreshAirHumiditySensor)
|
| | | {
|
| | | //传感器合并
|
| | | info.ConcreteType = DeviceConcreteType.Sensor;
|
| | |
| | | info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow;
|
| | | info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uSensorDoorWindow);
|
| | | }
|
| | | else if (iasZone.IasDeviceType == 541)
|
| | | {
|
| | | //球型移动传感器
|
| | | info.ConcreteType = DeviceConcreteType.Sensor_SphericalMotion;
|
| | | info.ConcreteText = this.dicDeviceModelIdEnum["MSPIRB-ZB.10"].A官方名字;
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <param name="saveRoadDevice">如果只有一个回路,是否把回路的房间一起修改</param>
|
| | | public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true)
|
| | | {
|
| | | if (listDevice == null)
|
| | | if (listDevice == null || listDevice.Count == 0)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
|
| | | if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1)
|
| | | if (saveRoadDevice == true && listDevice.Count == 1)
|
| | | {
|
| | | if (listDevice[0] is OTADevice)
|
| | | if ((listDevice[0] is OTADevice) == false)
|
| | | {
|
| | | //单纯只是Ota设备则不处理
|
| | | return;
|
| | | //ota设备不需要处理
|
| | | HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false);
|
| | | }
|
| | | HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false);
|
| | | }
|
| | | bool save = false;
|
| | | if (roomId == string.Empty)
|
| | |
| | | //新风的湿度传感器不显示
|
| | | return false;
|
| | | }
|
| | | if (((int)i_device.Type).ToString() == i_device.Type.ToString())
|
| | | {
|
| | | //此设备id在DeviceType里面还没有注册,则不能显示出来
|
| | | return false;
|
| | | }
|
| | |
|
| | | //如果是新风面板或环境面板,则都不显示任何回路
|
| | | var myInfoTypeTemp = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
|
| | | var myInfoTypeTemp = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
|
| | | if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir || myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment)
|
| | | {
|
| | | return false;
|
| | |
| | | {
|
| | | if (this.dicDeviceModelIdEnum.ContainsKey(strKey) == false)
|
| | | {
|
| | | return null;
|
| | | return new DeviceNameContent();
|
| | | }
|
| | | return this.dicDeviceModelIdEnum[strKey];
|
| | | }
|
| | |
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var contr = new ShowMsgControl(ShowMsgType.Error, msg);
|
| | | var contr = new ShowMsgControl(Phone.ShowMsgType.Error, msg);
|
| | | contr.Show();
|
| | | });
|
| | | }
|
| | |
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | var contr = new ShowMsgControl(Phone.ShowMsgType.Tip, msg);
|
| | | contr.Show();
|
| | | });
|
| | | }
|
| | |
| | | listCheck.Add(mainkeys);
|
| | | //刷新一下本地缓存
|
| | | var localDevice = this.GetDevice(mainkeys);
|
| | | if (localDevice != null)
|
| | | var tempDevice = localDevice == null ? device : localDevice;
|
| | |
|
| | | //如果这个设备ID变更了的话
|
| | | bool typeNotEquals = localDevice != null && deviceID != localDevice.Type;
|
| | | if (typeNotEquals == true)
|
| | | {
|
| | | //刷新属性
|
| | | this.SetDeviceInfoToMain(localDevice, device);
|
| | | if (this.RefreshDeviceFunctionType(localDevice, device, false) == true)
|
| | | {
|
| | | //需要发送功能类型给网关
|
| | | listFucDevice.Add(localDevice);
|
| | | }
|
| | | //重新New这个对象
|
| | | typeNotEquals = this.ReNewDeviceOnTypeIsChanged(localDevice, deviceID);
|
| | | //重新再次获取对象
|
| | | tempDevice = this.GetDevice(mainkeys);
|
| | | }
|
| | |
|
| | | //刷新属性
|
| | | this.SetDeviceInfoToMain(tempDevice, device);
|
| | | if (this.RefreshDeviceFunctionType(tempDevice, device, false) == true)
|
| | | {
|
| | | //需要发送功能类型给网关
|
| | | listFucDevice.Add(tempDevice);
|
| | | }
|
| | | if (typeNotEquals == true)
|
| | | {
|
| | | //重新生成缓存
|
| | | tempDevice.ReSave();
|
| | | HdlAutoBackupLogic.AddOrEditorFile(tempDevice.FilePath);
|
| | | //全部主页菜单需要刷新
|
| | | Phone.UserView.UserPage.Instance.RefreshAllForm = true;
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | return listDevice; |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 在设备Type变更时,重新New这个设备对象(仅限在刷新设备列表使用,并且本地需要存在)
|
| | | /// </summary>
|
| | | /// <param name="oldLocalDevice">原来的本地对象</param>
|
| | | /// <param name="newDeviceType">新的设备Type</param>
|
| | | private bool ReNewDeviceOnTypeIsChanged(CommonDevice oldLocalDevice, DeviceType newDeviceType)
|
| | | {
|
| | | //先获取本地这个旧设备对象的json
|
| | | string oldFile = System.IO.Path.Combine(Config.Instance.FullPath, oldLocalDevice.FilePath);
|
| | | var deviceData = HdlFileLogic.Current.ReadFileTextContent(oldFile);
|
| | | if (deviceData == null)
|
| | | {
|
| | | //应该不会
|
| | | return false;
|
| | | }
|
| | | //根据新Type重新New对象
|
| | | var newDevice = CommonDevice.CommonDeviceByByteString((int)newDeviceType, deviceData);
|
| | | if (newDevice == null)
|
| | | {
|
| | | //好像有点可能
|
| | | return false;
|
| | | }
|
| | | //删除本地文件
|
| | | HdlFileLogic.Current.DeleteFile(oldFile);
|
| | | HdlAutoBackupLogic.DeleteFile(oldLocalDevice.FilePath);
|
| | |
|
| | | //重新生成文件
|
| | | if (newDevice.IsCustomizeImage == false)
|
| | | {
|
| | | newDevice.IconPath = string.Empty;
|
| | | }
|
| | | string mainkey = this.GetDeviceMainKeys(newDevice);
|
| | | lock (dicAllDevice)
|
| | | {
|
| | | this.dicAllDevice[mainkey] = newDevice;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 创建新设备对象相关_________________
|
| | |
| | | /// <param name="device">设置源设备对象</param>
|
| | | public void SetDeviceInfoToMain(CommonDevice mainDevice, CommonDevice device)
|
| | | {
|
| | | if (string.IsNullOrEmpty(device.DeviceInfo.MacName) == false)
|
| | | {
|
| | | mainDevice.DeviceName = device.DeviceInfo.MacName;
|
| | | }
|
| | | if (string.IsNullOrEmpty(device.DeviceInfo.DeviceName) == false)
|
| | | {
|
| | | mainDevice.DeviceEpointName = device.DeviceInfo.DeviceName;
|
| | | }
|
| | | mainDevice.DeviceName = device.DeviceInfo.MacName;
|
| | | mainDevice.DeviceEpointName = device.DeviceInfo.DeviceName;
|
| | | mainDevice.CurrentGateWayId = device.CurrentGateWayId;
|
| | | mainDevice.ZigbeeType = device.DeviceInfo.ZigbeeType;
|
| | | mainDevice.IsOnline = device.DeviceInfo.IsOnline;
|
| | |
| | | mainDevice.IasDeviceType = device.DeviceInfo.DeviceType;
|
| | | mainDevice.Profile = device.DeviceInfo.Profile;
|
| | | mainDevice.Type = device.Type;
|
| | | mainDevice.DeviceID = (int)device.Type;
|
| | |
|
| | | //固件版本
|
| | | mainDevice.ImgVersion = device.DeviceInfo.ImgVersion;
|
| | |
| | | mainDevice.InClusterList.AddRange(device.DeviceInfo.InClusterList);
|
| | | mainDevice.OutClusterList.Clear();
|
| | | mainDevice.OutClusterList.AddRange(device.DeviceInfo.OutClusterList);
|
| | | mainDevice.AttributeStatus.Clear();
|
| | | mainDevice.AttributeStatus.AddRange(device.DeviceInfo.AttributeStatus);
|
| | |
|
| | | //如果是温度传感器
|
| | | if (mainDevice.Type == DeviceType.TemperatureSensor)
|
| | |
| | | /// <returns></returns>
|
| | | public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType)
|
| | | {
|
| | | CommonDevice device = null;
|
| | |
|
| | | //根据设备类型创建设备对象的实例
|
| | | if (deviceType == DeviceType.ColorDimmableLight) { device = new ColorDimmableLight(); }
|
| | | else if (deviceType == DeviceType.DimmableLight) { device = new DimmableLight(); }
|
| | | else if (deviceType == DeviceType.ColorDimmerSwitch) { device = new ColorDimmerSwitch(); }
|
| | | else if (deviceType == DeviceType.LevelControlSwitch) { device = new LevelControlSwitch(); }
|
| | | else if (deviceType == DeviceType.OnOffSwitch) { device = new Panel(); }
|
| | | else if (deviceType == DeviceType.OnOffOutput) { device = new ToggleLight(); }
|
| | | else if (deviceType == DeviceType.AirSwitch) { device = new AirSwitch(); }
|
| | | else if (deviceType == DeviceType.WindowCoveringDevice) { device = new Rollershade(); }
|
| | | else if (deviceType == DeviceType.WindowCoveringController) { device = new WindowCoveringController(); }
|
| | | else if (deviceType == DeviceType.IASZone) { device = new IASZone(); }
|
| | | else if (deviceType == DeviceType.Repeater) { device = new Repeater(); }
|
| | | else if (deviceType == DeviceType.Thermostat) { device = new AC(); }
|
| | | else if (deviceType == DeviceType.FreshAir) { device = new FreshAir(); }
|
| | | else if (deviceType == DeviceType.DoorLock) { device = new DoorLock(); }
|
| | | else if (deviceType == DeviceType.TemperatureSensor) { device = new TemperatureSensor(); }
|
| | | else if (deviceType == DeviceType.PMSensor) { device = new PMSensor(); }
|
| | | else if (deviceType == DeviceType.FreshAirHumiditySensor) { device = new HumiditySensor(); }
|
| | | else if (deviceType == DeviceType.ColorTemperatureLight) { device = new ColorTemperatureLight(); }
|
| | | else if (deviceType == DeviceType.Buzzer) { device = new Buzzer(); }
|
| | | else if (deviceType == DeviceType.OtaDevice || deviceType == DeviceType.OtaPanelDevice) { device = new OTADevice(); }
|
| | | else { return null; }
|
| | | var device = CommonDevice.CommonDeviceByByteString((int)deviceType, "{\"DeviceID\":" + (int)deviceType + "}");
|
| | | if (device == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
|
| | | device.DeviceEpointName = string.Empty;
|
| | | device.DeviceName = string.Empty;
|
| | |
| | | mainDevice.IconPath = "Device/Light.png";
|
| | | }
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A灯光;
|
| | | if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | {
|
| | | //调光器固定灯光
|
| | | if (sendFucType == true)
|
| | |
| | | mainDevice.IconPath = "Device/ColorLightTemperature.png";
|
| | | }
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A灯光;
|
| | | if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | {
|
| | | //色温灯固定灯光
|
| | | if (sendFucType == true)
|
| | |
| | | if (mainDevice.DfunctionType == DeviceFunctionType.A未定义)
|
| | | {
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A灯光;
|
| | | if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | {
|
| | | //继电器默认为灯光
|
| | | if (sendFucType == true)
|
| | |
| | | if (mainDevice.DfunctionType == DeviceFunctionType.A未定义)
|
| | | {
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A开关;
|
| | | if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A开关)
|
| | | if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A开关)
|
| | | {
|
| | | //空气开关默认为开关
|
| | | if (sendFucType == true)
|
| | |
| | | mainDevice.IconPath = "Device/ColorLight.png";
|
| | | }
|
| | | mainDevice.DfunctionType = DeviceFunctionType.A灯光;
|
| | | if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
|
| | | {
|
| | | //彩灯默认为开关
|
| | | if (sendFucType == true)
|
| | |
| | | this.dicPictrueShard["ButtonPanel_SimpleTwo"] = "ButtonPanel_Two";//简约2按键面板 沿用 2按键的图标
|
| | | this.dicPictrueShard["IntelligentLocks_Sone"] = "IntelligentLocks_H06C";//S-one的门锁图片 沿用 H06C的图标
|
| | | this.dicPictrueShard["Relay_FangyueFreshAirModul"] = "Relay_ThreeLoad";//方悦新风小模块图片 沿用 3路继电器的图标
|
| | | this.dicPictrueShard["ButtonPanel_FourButtonScene"] = "ButtonPanel_Four";//简约4按键场景面板 沿用 4按键面板的图标
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | System.IO.StreamReader streamReader = null;
|
| | | var listText = new List<string>();
|
| | | try
|
| | | { |
| | | #if iOS |
| | | string textFile = Foundation.NSBundle.MainBundle.PathForResource("DeviceName.ini", null); |
| | | streamReader = new System.IO.StreamReader(textFile, Encoding.UTF8); |
| | | {
|
| | | #if iOS
|
| | | string textFile = Foundation.NSBundle.MainBundle.PathForResource("DeviceName.ini", null);
|
| | | streamReader = new System.IO.StreamReader(textFile, Encoding.UTF8);
|
| | | string text;
|
| | | while ((text = streamReader.ReadLine()) != null)
|
| | | {
|
| | | listText.Add(text.Trim());
|
| | | }
|
| | | return listText; |
| | | #endif |
| | | #if Android |
| | | return listText;
|
| | | #endif
|
| | | #if Android
|
| | | var stream = Application.Activity.Assets.Open("DeviceName.ini");
|
| | | streamReader = new System.IO.StreamReader(stream, Encoding.UTF8);
|
| | | string text;
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | | #endregion
|
| | | }
|
| | |
|
| | | #region ■ 自定义设备类型_________________________
|
| | | #region ■ 自定义设备类型_________________________
|
| | |
|
| | | /// <summary>
|
| | | /// <para>设备的具体【设备类型】,变量名可以作为【设备类型】图片,这个值是瞎写的,没什么特殊意义</para>
|
| | |
| | | /// PM2.5空气质量传感器
|
| | | /// </summary>
|
| | | Sensor_PMTwoPointFive = 1307,
|
| | | /// <summary>
|
| | | /// 温湿度传感器(这个单词拼错了,但是错了就错了呗,就这样了)
|
| | | /// </summary>
|
| | | Sensor_TemperatureHumidity = 1308,
|
| | |
|
| | | /// <summary>
|
| | | /// 运动传感器
|
| | |
| | | /// </summary>
|
| | | Sensor_Keyfob = -1307,
|
| | | /// <summary>
|
| | | /// 温湿度传感器
|
| | | /// </summary>
|
| | | Sensor_TemperatureHumidity = -1308,
|
| | | /// <summary>
|
| | | /// 温度传感器
|
| | | /// 温度传感器(这个单词拼错了,但是错了就错了呗,就这样了)
|
| | | /// </summary>
|
| | | Sensor_Temperature = -1309,
|
| | | /// <summary>
|
| | |
| | | /// 方悦新风小模块 镜像id:2310
|
| | | /// </summary>
|
| | | Relay_FangyueFreshAirModul = 2310,
|
| | | |
| | | /// <summary>
|
| | | /// 国标3路10A继电器小模块 镜像id:2311(临时)
|
| | | /// </summary>
|
| | | Relay_NationalThreeLoadTenA = 2311,
|
| | | /// <summary>
|
| | | /// 欧标2路5A继电器小模块 镜像id:2312(临时)
|
| | | /// </summary>
|
| | | Relay_EuropeanTwoLoadFiveA = 2312,
|
| | | /// <summary>
|
| | | /// 欧标14路干接点小模块 镜像id:2313(临时)
|
| | | /// </summary>
|
| | | Relay_EuropeanFourteenLoadDryContact = 2313,
|
| | |
|
| | | //=========★★调光器类(2500-2799)★★=========
|
| | | /// <summary>
|
| | | /// 调光器
|
| | |
| | | A干接点 = 16,
|
| | | }
|
| | |
|
| | | #endregion
|
| | | #endregion
|
| | | }
|