HDL Home App 第二版本 旧平台金堂用 正在使用
xm
2020-06-19 ce1feeeb0aaa2e53bca4e8d64953edaba2b41106
Home0618/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs
old mode 100755 new mode 100644
@@ -316,368 +316,371 @@
            return false;
        }
        /// <summary>
        /// 删除设备绑定的目标
        /// </summary>
        /// <param name="mainDevice">设备对象</param>
        /// <param name="listDeleteDevice">要删除的绑定目标设备</param>
        /// <param name="BindCluster">BindCluster</param>
        /// <returns>返回的是成功删除的设备</returns>
        public List<CommonDevice> DeleteDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDeleteDevice, int BindCluster = 6)
        {
            //组装数据
            var deleteData = new IASZone.DelDeviceBindData();
            deleteData.DeviceAddr = mainDevice.DeviceAddr;
            deleteData.Epoint = mainDevice.DeviceEpoint;
        #endregion
            var dicDevice = new Dictionary<string, CommonDevice>();
            foreach (var device in listDeleteDevice)
            {
                var info = new IASZone.RemoveBindListObj();
                info.BindCluster = BindCluster;
                info.BindMacAddr = device.DeviceAddr;
                info.BindEpoint = device.DeviceEpoint;
                info.BindType = 0;
        #region ■ 删除设备绑定的目标_________________
                deleteData.RemoveBindList.Add(info);
                //返回成功设备的时候使用
                string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
                dicDevice[mainkeys] = device;
            }
            var listSuccess = new List<CommonDevice>();
            var result = this.DelDeviceBindAsync(deleteData);
            if (result == null || result.delDeviceBindResponseData == null)
            {
                //删除绑定目标失败
                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
                //拼接上【网关回复超时】的Msg
                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
                this.ShowErrorMsg(msg);
                return listSuccess;
            }
            foreach (var data in result.delDeviceBindResponseData.RemoveBindList)
            {
                string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint);
                //0:成功  1:设备不在绑定列表中 ,也可以代表成功
                if (data.Result == 0 || data.Result == 1)
                {
                    listSuccess.Add(dicDevice[mainkeys]);
                }
                //3:失败,在等待节点设备确认是否解除绑定成功
                else if (data.Result == 3)
                {
                    //设备名称 其他绑定目标正在删除中,请稍后再试
                    string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
                    msg += Language.StringByID(R.MyInternationalizationString.uOtherBindTargetsIsDelettingPleaseWait);
                    this.ShowErrorMsg(msg);
                }
                //2:未知,由节点设备反馈发送“Bind/BindResult”主题消息确定是否成功
                else if (data.Result == 2)
                {
                    if (result.removeBindResultResponseData == null)
                    {
                        //设备名称 删除绑定目标失败
                        string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
                        msg += Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
                        this.ShowErrorMsg(msg);
                    }
                    else
                    {
                        //成功
                        if (result.removeBindResultResponseData.Result == 0)
                        {
                            listSuccess.Add(dicDevice[mainkeys]);
                        }
                        //136:控制设备本地绑定列表中无此绑定
                        else if (result.removeBindResultResponseData.Result == 136)
                        {
                            //这个可以当做成功
                            listSuccess.Add(dicDevice[mainkeys]);
                        }
                        else
                        {
                            //设备名称 删除绑定目标失败
                            string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
                            msg += Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
                            this.ShowErrorMsg(msg);
                        }
                    }
                }
            }
            return listSuccess;
        }
        /// <summary>
        /// 删除设备的绑定目标
        /// </summary>
        /// <param name="delDeviceBindData"></param>
        /// <returns></returns>
        public BindObj.DelDeviceBindResponseAllData DelDeviceBindAsync(BindObj.DelDeviceBindData delDeviceBindData)
        {
            //如果当前住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return ModelData.DeviceModelDataLogic.Current.DeleteDeviceBindList(delDeviceBindData);
            }
            var device = Common.LocalDevice.Current.GetDevice(delDeviceBindData.DeviceAddr, delDeviceBindData.Epoint);
            //获取需要发送的数据
            var sendData = this.GetDeleteDeviceBindCommandText(delDeviceBindData);
            //发送命令
            var result = this.SendDeleteBindJobjectDataToGateway(device, "Bind/RemoveBind",
                sendData, new List<string>() { "Bind/RemoveBind_Respon", "Bind/RemoveBindResult" }, 6);
            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
            {
                return null;
            }
            var responseData = new BindObj.DelDeviceBindResponseAllData();
            if (result.listReceiptData[0] != null)
            {
                var tempData1 = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.DelDeviceBindResponseData>(result.listReceiptData[0]);
                responseData.delDeviceBindResponseData = tempData1;
            }
            if (result.listReceiptData[1] != null)
            {
                var tempData2 = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.RemoveBindResultResponseData>(result.listReceiptData[1]);
                responseData.removeBindResultResponseData = tempData2;
            }
            //修改缓存
            ModelData.DeviceModelDataLogic.Current.DeleteDeviceBindList(delDeviceBindData);
            return responseData;
        }
        /// <summary>
        ///删除一个控制设备所有绑定信息
        /// </summary>
        public BindObj.ClearBindInfoResponseAllData ClearBindInfoAsync(CommonDevice device)
        {
            //如果当前住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return ModelData.DeviceModelDataLogic.Current.ClearDeviceAllBind(device);
            }
            var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5006 } };
            var sendData = jObject.ToString();
            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/ClearBindInfo", sendData, "Bind/ClearBindInfo_Respon", 25);
            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
            {
                return null;
            }
            //修改缓存
            ModelData.DeviceModelDataLogic.Current.ClearDeviceAllBind(device);
            var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.ClearBindInfoResponseData>(result.ReceiptData);
            return new BindObj.ClearBindInfoResponseAllData { clearBindInfoResponseData = tempData };
        }
        /// <summary>
        /// 获取删除设备绑定列表的命令字符
        /// </summary>
        /// <param name="delDeviceBindData"></param>
        /// <returns></returns>
        public string GetDeleteDeviceBindCommandText(BindObj.DelDeviceBindData delDeviceBindData)
        {
            var jObject = new JObject { { "DeviceAddr", delDeviceBindData.DeviceAddr }, { "Epoint", delDeviceBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5003 } };
            var removeBindList = new JArray { };
            foreach (var removeBindInfo in delDeviceBindData.RemoveBindList)
            {
                //删除设备
                if (removeBindInfo.BindType == 0)
                {
                    var dInfo = new JObject{{ "BindMacAddr",removeBindInfo.BindMacAddr},{ "BindEpoint", removeBindInfo.BindEpoint} ,
                         { "BindCluster", removeBindInfo.BindCluster} ,{ "BindType",removeBindInfo.BindType}};
                    removeBindList.Add(dInfo);
                }
                //删除场景
                else if (removeBindInfo.BindType == 1)
                {
                    var dInfo = new JObject{{ "BindCluster", removeBindInfo.BindCluster} ,{ "BindType",removeBindInfo.BindType},
                         { "BindScenesId", removeBindInfo.BindScenesId}};
                    removeBindList.Add(dInfo);
                }
            }
            var data = new JObject { { "RemoveBindList", removeBindList } };
            jObject.Add("Data", data);
            return jObject.ToString();
        }
        /// <summary>
        /// 发送删除绑定的数据到网关,并接受网关返回的数据,listReceiptData为返回值(删除绑定的接口很特殊,需要独立出来)
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="sendTopic">发送的主题</param>
        /// <param name="sendData">需要发送的数据  JObject.ToString()的东西</param>
        /// <param name="listReceiptTopic">指定接收哪些主题</param>
        /// <param name="waitTime">超时时间(秒)</param>
        /// <returns>网关返回的数据</returns>
        private ReceiptGatewayResult SendDeleteBindJobjectDataToGateway(CommonDevice device, string sendTopic, string sendData, List<string> listReceiptTopic, int waitTime = 3)
        {
            var reResult = new ReceiptGatewayResult();
            reResult.listReceiptData = new string[listReceiptTopic.Count];
            var myGateway = device.Gateway;
            if (myGateway == null)
            {
                //获取网关对象失败
                reResult.ErrorMsg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail);
                reResult.ErrorMsgDiv = -1;
                return reResult;
            }
            //网关ID
            string gatewayID = HdlGatewayLogic.Current.GetGatewayId(device.Gateway);
            //错误主题
            string errorTopic = gatewayID + "/" + "Error_Respon";
            //检测对象的主题
            for (int i = 0; i < listReceiptTopic.Count; i++)
            {
                listReceiptTopic[i] = gatewayID + "/" + listReceiptTopic[i];
            }
            bool canbreak = false;
            BindObj.DelDeviceBindResponseData delDeviceBindData = null;
            BindObj.RemoveBindResultResponseData removeBindResult = null;
            Action<string, string> receiptAction = (topic, message) =>
            {
                var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
                //网关回复错误
                if (topic == errorTopic)
                {
                    var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                    reResult.ErrorMsg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
                }
                //如果是指定的主题
                for (int i = 0; i < listReceiptTopic.Count; i++)
                {
                    if (topic == listReceiptTopic[i])
                    {
                        string deviceMac = jobject["DeviceAddr"].ToString();
                        int deviceEpoint = Convert.ToInt32(jobject["Epoint"].ToString());
                        if (device.DeviceAddr != deviceMac)
                        {
                            //不是同一个东西Mac
                            return;
                        }
                        if (device.DeviceEpoint != deviceEpoint && deviceEpoint != 200)
                        {
                            //不是同一个东西,这里应该需要特殊处理200端点
                            return;
                        }
                        reResult.listReceiptData[i] = jobject["Data"].ToString();
                        if (i == 0)
                        {
                            //"Bind/RemoveBind_Respon"主题
                            delDeviceBindData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.DelDeviceBindResponseData>(reResult.listReceiptData[i]);
                        }
                        else if (i == 1)
                        {
                            //"Bind/RemoveBindResult"主题
                            removeBindResult = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.RemoveBindResultResponseData>(reResult.listReceiptData[i]);
                        }
                        if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 1).Count)
                        {
                            //这种情况是按键中不存在绑定目标,没有第二种种情况返回
                            canbreak = true;
                        }
                        else if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 3).Count)
                        {
                            if (removeBindResult != null)
                            {
                                canbreak = true;
                            }
                        }
                        else if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 2).Count)
                        {
                            if (removeBindResult != null)
                            {
                                canbreak = true;
                            }
                        }
                        else
                        {
                            canbreak = true;
                        }
                    }
                }
            };
            myGateway.Actions += receiptAction;
            //发送数据
            myGateway.Send(sendTopic, sendData);
            //超时时间
            int TimeOut = 0;
            waitTime = 20 * waitTime;
            while (canbreak == false && TimeOut < waitTime)
            {
                //全部接收才退出
                System.Threading.Thread.Sleep(50);
                TimeOut++;
            }
            myGateway.Actions -= receiptAction;
            receiptAction = null;
            if (canbreak == false)
            {
                //超时
                reResult.ErrorMsgDiv = 0;
            }
            else
            {
                //正常接收到网关返回的数据
                if (reResult.listReceiptData.Length == 1)
                {
                    //如果只有一个主题,则替换变量
                    reResult.ReceiptData = reResult.listReceiptData[0];
                    reResult.listReceiptData = null;
                }
            }
            return reResult;
        }
        #endregion
        #region ■ 配置面板功能_______________________
        ///<summary >
        ///配置面板功能
        ///<para>value:给面板配置的模式</para>
        /// </summary>
        public CommonDevice.SetWritableValueResponAllData ConfigureHdlKeyValueAsync(CommonDevice device, Panel.KeyMode value, int clusterID = 6)
        {
            //如果当前住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return ModelData.DeviceModelDataLogic.Current.ConfigurePanelKeyModel(device, value, clusterID, "SetWritableValue");
            }
            //获取发送数据
            var sendData = this.GetConfigureHdlKeyCommandText(device.DeviceAddr, device.DeviceEpoint, value, clusterID);
            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
            {
                return null;
            }
            //修改缓存
            ModelData.DeviceModelDataLogic.Current.ConfigurePanelKeyModel(device, value, clusterID, "SetWritableValue");
            var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
            return new CommonDevice.SetWritableValueResponAllData { setWritableValueResponData = tempData };
        }
        /// <summary>
        /// 删除设备绑定的目标
        /// </summary>
        /// <param name="mainDevice">设备对象</param>
        /// <param name="listDeleteDevice">要删除的绑定目标设备</param>
        /// <param name="BindCluster">BindCluster</param>
        /// <returns>返回的是成功删除的设备</returns>
        public List<CommonDevice> DeleteDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDeleteDevice, int BindCluster = 6)
        {
            //组装数据
            var deleteData = new IASZone.DelDeviceBindData();
            deleteData.DeviceAddr = mainDevice.DeviceAddr;
            deleteData.Epoint = mainDevice.DeviceEpoint;
            var dicDevice = new Dictionary<string, CommonDevice>();
            foreach (var device in listDeleteDevice)
            {
                var info = new IASZone.RemoveBindListObj();
                info.BindCluster = BindCluster;
                info.BindMacAddr = device.DeviceAddr;
                info.BindEpoint = device.DeviceEpoint;
                info.BindType = 0;
                deleteData.RemoveBindList.Add(info);
                //返回成功设备的时候使用
                string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
                dicDevice[mainkeys] = device;
            }
            var listSuccess = new List<CommonDevice>();
            var result = this.DelDeviceBindAsync(deleteData);
            if (result == null || result.delDeviceBindResponseData == null)
            {
                //删除绑定目标失败
                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
                //拼接上【网关回复超时】的Msg
                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
                this.ShowErrorMsg(msg);
                return listSuccess;
            }
            foreach (var data in result.delDeviceBindResponseData.RemoveBindList)
            {
                string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint);
                //0:成功  1:设备不在绑定列表中 ,也可以代表成功
                if (data.Result == 0 || data.Result == 1)
                {
                    listSuccess.Add(dicDevice[mainkeys]);
                }
                //3:失败,在等待节点设备确认是否解除绑定成功
                else if (data.Result == 3)
                {
                    //设备名称 其他绑定目标正在删除中,请稍后再试
                    string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
                    msg += Language.StringByID(R.MyInternationalizationString.uOtherBindTargetsIsDelettingPleaseWait);
                    this.ShowErrorMsg(msg);
                }
                //2:未知,由节点设备反馈发送“Bind/BindResult”主题消息确定是否成功
                else if (data.Result == 2)
                {
                    if (result.removeBindResultResponseData == null)
                    {
                        //设备名称 删除绑定目标失败
                        string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
                        msg += Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
                        this.ShowErrorMsg(msg);
                    }
                    else
                    {
                        //成功
                        if (result.removeBindResultResponseData.Result == 0)
                        {
                            listSuccess.Add(dicDevice[mainkeys]);
                        }
                        //136:控制设备本地绑定列表中无此绑定
                        else if (result.removeBindResultResponseData.Result == 136)
                        {
                            //这个可以当做成功
                            listSuccess.Add(dicDevice[mainkeys]);
                        }
                        else
                        {
                            //设备名称 删除绑定目标失败
                            string msg = Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n";
                            msg += Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail);
                            this.ShowErrorMsg(msg);
                        }
                    }
                }
            }
            return listSuccess;
        }
        /// <summary>
        /// 删除设备的绑定目标
        /// </summary>
        /// <param name="delDeviceBindData"></param>
        /// <returns></returns>
        public BindObj.DelDeviceBindResponseAllData DelDeviceBindAsync(BindObj.DelDeviceBindData delDeviceBindData)
        {
            //如果当前住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return ModelData.DeviceModelDataLogic.Current.DeleteDeviceBindList(delDeviceBindData);
            }
            var device = Common.LocalDevice.Current.GetDevice(delDeviceBindData.DeviceAddr, delDeviceBindData.Epoint);
            //获取需要发送的数据
            var sendData = this.GetDeleteDeviceBindCommandText(delDeviceBindData);
            //发送命令
            var result = this.SendDeleteBindJobjectDataToGateway(device, "Bind/RemoveBind",
                sendData, new List<string>() { "Bind/RemoveBind_Respon", "Bind/RemoveBindResult" }, 6);
            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
            {
                return null;
            }
            var responseData = new BindObj.DelDeviceBindResponseAllData();
            if (result.listReceiptData[0] != null)
            {
                var tempData1 = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.DelDeviceBindResponseData>(result.listReceiptData[0]);
                responseData.delDeviceBindResponseData = tempData1;
            }
            if (result.listReceiptData[1] != null)
            {
                var tempData2 = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.RemoveBindResultResponseData>(result.listReceiptData[1]);
                responseData.removeBindResultResponseData = tempData2;
            }
            //修改缓存
            ModelData.DeviceModelDataLogic.Current.DeleteDeviceBindList(delDeviceBindData);
            return responseData;
        }
        /// <summary>
        ///删除一个控制设备所有绑定信息
        /// </summary>
        public BindObj.ClearBindInfoResponseAllData ClearBindInfoAsync(CommonDevice device)
        {
            //如果当前住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return ModelData.DeviceModelDataLogic.Current.ClearDeviceAllBind(device);
            }
            var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5006 } };
            var sendData = jObject.ToString();
            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Bind/ClearBindInfo", sendData, "Bind/ClearBindInfo_Respon", 25);
            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
            {
                return null;
            }
            //修改缓存
            ModelData.DeviceModelDataLogic.Current.ClearDeviceAllBind(device);
            var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.ClearBindInfoResponseData>(result.ReceiptData);
            return new BindObj.ClearBindInfoResponseAllData { clearBindInfoResponseData = tempData };
        }
        /// <summary>
        /// 获取删除设备绑定列表的命令字符
        /// </summary>
        /// <param name="delDeviceBindData"></param>
        /// <returns></returns>
        public string GetDeleteDeviceBindCommandText(BindObj.DelDeviceBindData delDeviceBindData)
        {
            var jObject = new JObject { { "DeviceAddr", delDeviceBindData.DeviceAddr }, { "Epoint", delDeviceBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5003 } };
            var removeBindList = new JArray { };
            foreach (var removeBindInfo in delDeviceBindData.RemoveBindList)
            {
                //删除设备
                if (removeBindInfo.BindType == 0)
                {
                    var dInfo = new JObject{{ "BindMacAddr",removeBindInfo.BindMacAddr},{ "BindEpoint", removeBindInfo.BindEpoint} ,
                         { "BindCluster", removeBindInfo.BindCluster} ,{ "BindType",removeBindInfo.BindType}};
                    removeBindList.Add(dInfo);
                }
                //删除场景
                else if (removeBindInfo.BindType == 1)
                {
                    var dInfo = new JObject{{ "BindCluster", removeBindInfo.BindCluster} ,{ "BindType",removeBindInfo.BindType},
                         { "BindScenesId", removeBindInfo.BindScenesId}};
                    removeBindList.Add(dInfo);
                }
            }
            var data = new JObject { { "RemoveBindList", removeBindList } };
            jObject.Add("Data", data);
            return jObject.ToString();
        }
        /// <summary>
        /// 发送删除绑定的数据到网关,并接受网关返回的数据,listReceiptData为返回值(删除绑定的接口很特殊,需要独立出来)
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="sendTopic">发送的主题</param>
        /// <param name="sendData">需要发送的数据  JObject.ToString()的东西</param>
        /// <param name="listReceiptTopic">指定接收哪些主题</param>
        /// <param name="waitTime">超时时间(秒)</param>
        /// <returns>网关返回的数据</returns>
        private ReceiptGatewayResult SendDeleteBindJobjectDataToGateway(CommonDevice device, string sendTopic, string sendData, List<string> listReceiptTopic, int waitTime = 3)
        {
            var reResult = new ReceiptGatewayResult();
            reResult.listReceiptData = new string[listReceiptTopic.Count];
            var myGateway = device.Gateway;
            if (myGateway == null)
            {
                //获取网关对象失败
                reResult.ErrorMsg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail);
                reResult.ErrorMsgDiv = -1;
                return reResult;
            }
            //网关ID
            string gatewayID = device.Gateway.GwId;
            //错误主题
            string errorTopic = gatewayID + "/" + "Error_Respon";
            //检测对象的主题
            for (int i = 0; i < listReceiptTopic.Count; i++)
            {
                listReceiptTopic[i] = gatewayID + "/" + listReceiptTopic[i];
            }
            bool canbreak = false;
            BindObj.DelDeviceBindResponseData delDeviceBindData = null;
            BindObj.RemoveBindResultResponseData removeBindResult = null;
            Action<string, string> receiptAction = (topic, message) =>
            {
                var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
                //网关回复错误
                if (topic == errorTopic)
                {
                    var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                    reResult.ErrorMsg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
                }
                //如果是指定的主题
                for (int i = 0; i < listReceiptTopic.Count; i++)
                {
                    if (topic == listReceiptTopic[i])
                    {
                        string deviceMac = jobject["DeviceAddr"].ToString();
                        int deviceEpoint = Convert.ToInt32(jobject["Epoint"].ToString());
                        if (device.DeviceAddr != deviceMac)
                        {
                            //不是同一个东西Mac
                            return;
                        }
                        if (device.DeviceEpoint != deviceEpoint && deviceEpoint != 200)
                        {
                            //不是同一个东西,这里应该需要特殊处理200端点
                            return;
                        }
                        reResult.listReceiptData[i] = jobject["Data"].ToString();
                        if (i == 0)
                        {
                            //"Bind/RemoveBind_Respon"主题
                            delDeviceBindData = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.DelDeviceBindResponseData>(reResult.listReceiptData[i]);
                        }
                        else if (i == 1)
                        {
                            //"Bind/RemoveBindResult"主题
                            removeBindResult = Newtonsoft.Json.JsonConvert.DeserializeObject<BindObj.RemoveBindResultResponseData>(reResult.listReceiptData[i]);
                        }
                        if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 1).Count)
                        {
                            canbreak = true;
                        }
                        else if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 3).Count)
                        {
                            if (removeBindResult != null)
                            {
                                canbreak = true;
                            }
                        }
                        else if (0 < delDeviceBindData.RemoveBindList.FindAll((obj) => obj.BindType == 0 && obj.Result == 2).Count)
                        {
                            if (removeBindResult != null)
                            {
                                canbreak = true;
                            }
                        }
                        else
                        {
                            canbreak = true;
                        }
                    }
                }
            };
            myGateway.Actions += receiptAction;
            //发送数据
            myGateway.Send(sendTopic, sendData);
            //超时时间
            int TimeOut = 0;
            waitTime = 20 * waitTime;
            while (canbreak == false && TimeOut < waitTime)
            {
                //全部接收才退出
                System.Threading.Thread.Sleep(50);
                TimeOut++;
            }
            myGateway.Actions -= receiptAction;
            receiptAction = null;
            if (canbreak == false)
            {
                //超时
                reResult.ErrorMsgDiv = 0;
            }
            else
            {
                //正常接收到网关返回的数据
                if (reResult.listReceiptData.Length == 1)
                {
                    //如果只有一个主题,则替换变量
                    reResult.ReceiptData = reResult.listReceiptData[0];
                    reResult.listReceiptData = null;
                }
            }
            return reResult;
        }
        #endregion
        #region ■ 配置面板功能_______________________
        ///<summary >
        ///配置面板功能
        ///<para>value:给面板配置的模式</para>
        /// </summary>
        public CommonDevice.SetWritableValueResponAllData ConfigureHdlKeyValueAsync(CommonDevice device, Panel.KeyMode value, int clusterID = 6)
        {
            //如果当前住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return ModelData.DeviceModelDataLogic.Current.ConfigurePanelKeyModel(device, value, clusterID, "SetWritableValue");
            }
            //获取发送数据
            var sendData = this.GetConfigureHdlKeyCommandText(device.DeviceAddr, device.DeviceEpoint, value, clusterID);
            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon");
            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
            {
                return null;
            }
            //修改缓存
            ModelData.DeviceModelDataLogic.Current.ConfigurePanelKeyModel(device, value, clusterID, "SetWritableValue");
            var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData);
            return new CommonDevice.SetWritableValueResponAllData { setWritableValueResponData = tempData };
        }
        /// <summary>
        /// 读取面板的配置信息
        /// </summary>