黄学彪
2020-09-01 dee21bf452a8979d0515d13e534fbb69ed9715dd
ZigbeeApp/Shared/Common/Device.cs
@@ -260,7 +260,10 @@
                    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)
                {
@@ -1275,10 +1278,15 @@
        /// <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;
@@ -1290,6 +1298,20 @@
                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
@@ -1376,9 +1398,10 @@
            {
                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按键面板)
@@ -2741,12 +2764,30 @@
                                    var localDevice = this.GetDevice(mainkeys);
                                    var tempDevice = localDevice == null ? device : localDevice;
                                    //如果这个设备ID变更了的话
                                    bool typeNotEquals = localDevice != null && deviceID != localDevice.Type;
                                    if (typeNotEquals == true)
                                    {
                                        //重新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;
                                    }
                                }
                            }
@@ -2838,6 +2879,45 @@
            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(newDeviceType.ToString(), 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 ■ 创建新设备对象相关_________________
@@ -2890,6 +2970,7 @@
            mainDevice.IasDeviceType = device.DeviceInfo.DeviceType;
            mainDevice.Profile = device.DeviceInfo.Profile;
            mainDevice.Type = device.Type;
            mainDevice.DeviceID = (int)device.Type;
            //固件版本
            mainDevice.ImgVersion = device.DeviceInfo.ImgVersion;
@@ -3434,7 +3515,19 @@
        /// 方悦新风小模块 镜像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>
        /// 调光器