黄学彪
2019-10-24 31497bb69602433d94c8a28ea01c3ee3c7cc8576
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceBindLogic.cs
@@ -76,7 +76,7 @@
        /// </summary>
        /// <param name="mainDevice">设备对象</param>
        /// <param name="listDevice">要绑定的目标设备</param>
        /// <param name="BindCluster">要绑定的目标设备</param>
        /// <param name="BindCluster">BindCluster</param>
        /// <returns></returns>
        public async Task<List<CommonDevice>> BindDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDevice, int BindCluster = 6)
        {
@@ -191,7 +191,7 @@
        /// </summary>
        /// <param name="mainDevice">设备对象</param>
        /// <param name="deleteDevice">要删除的绑定目标设备</param>
        /// <param name="BindCluster">要绑定的目标设备</param>
        /// <param name="BindCluster">BindCluster</param>
        /// <returns></returns>
        public async Task<bool> DeleteDeviceTarget(CommonDevice mainDevice, CommonDevice deleteDevice, int BindCluster = 6)
        {
@@ -201,7 +201,7 @@
            deleteData.Epoint = mainDevice.DeviceEpoint;
            var info = new IASZone.RemoveBindListObj();
            info.BindCluster = 6;
            info.BindCluster = BindCluster;
            info.BindMacAddr = deleteDevice.DeviceAddr;
            info.BindEpoint = deleteDevice.DeviceEpoint;
            info.BindType = 0;
@@ -271,6 +271,101 @@
            return false;
        }
        /// <summary>
        /// 删除设备绑定的目标
        /// </summary>
        /// <param name="mainDevice">设备对象</param>
        /// <param name="listDeleteDevice">要删除的绑定目标设备</param>
        /// <param name="BindCluster">BindCluster</param>
        /// <returns>返回的是成功删除的设备</returns>
        public async Task<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 = (BindObj.DelDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "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);
                }
                //4:未知,由节点设备反馈发送“Bind/BindResult”主题消息确定是否成功
                else if (data.Result == 4)
                {
                    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;
        }
        #endregion
        #region ■ 一般方法___________________________