| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using Com.Amap.Api.Location; |
| | | using Shared.Common; |
| | | using ZigBee.Device; |
| | | using static ZigBee.Device.BindObj; |
| | |
| | | /// 按键配置的目标列表 |
| | | /// </summary> |
| | | List<CommonDevice> targetList = new List<CommonDevice>(); |
| | | /// <summary> |
| | | /// 新的按键配置目标列表中,目标实际存在按键中,此时要删掉的数据 |
| | | /// </summary> |
| | | List<CommonDevice> oldTargetList = new List<CommonDevice>(); |
| | | List<Room> roomList = new List<Room>(); |
| | | int currentClusterID = 6; |
| | | public Action<List<BindListResponseObj>> action; |
| | |
| | | |
| | | btnFinifh.MouseUpEventHandler += async (sender, e) => |
| | | { |
| | | oldTargetList.Clear(); |
| | | bool isFinish = false; |
| | | btnFinifh.Enable = false; |
| | | btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect; |
| | | if (oldModeID != 65535 && oldModeID != currentModeID) |
| | | try |
| | | { |
| | | var bindResult = await currentKey.ClearBindInfoAsync(); |
| | | if (bindResult.clearBindInfoResponseData != null) |
| | | CommonPage.Loading.Start(""); |
| | | //1、清空所有目标 |
| | | if (currentKey.bindList != null) |
| | | { |
| | | if (bindResult.clearBindInfoResponseData.Result != 0) |
| | | var bindResult = await currentKey.ClearBindInfoAsync(); |
| | | |
| | | if (bindResult != null && bindResult.clearBindInfoResponseData != null) |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | CommonPage.Loading.Hide(); |
| | | this.RemoveFromParent(); |
| | | btnFinifh.Enable = true; |
| | | return; |
| | | if (bindResult.clearBindInfoResponseData.Result != 0) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | }); |
| | | CommonPage.Loading.Hide(); |
| | | this.RemoveFromParent(); |
| | | btnFinifh.Enable = true; |
| | | btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | currentKey.bindList.Clear(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | currentKey.bindList.Clear(); |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | }); |
| | | CommonPage.Loading.Hide(); |
| | | btnFinifh.Enable = true; |
| | | btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | foreach (var bindedDev in currentKey.bindList) |
| | | //if (oldModeID != 65535 && oldModeID != currentModeID) |
| | | //{ |
| | | //var bindResult = await currentKey.ClearBindInfoAsync(); |
| | | //if (bindResult.clearBindInfoResponseData != null) |
| | | //{ |
| | | // if (bindResult.clearBindInfoResponseData.Result != 0) |
| | | // { |
| | | // Application.RunOnMainThread(() => |
| | | // { |
| | | // new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | // }); |
| | | // CommonPage.Loading.Hide(); |
| | | // this.RemoveFromParent(); |
| | | // btnFinifh.Enable = true; |
| | | // return; |
| | | // } |
| | | // else |
| | | // { |
| | | // currentKey.bindList.Clear(); |
| | | // } |
| | | //} |
| | | //} |
| | | //else |
| | | //{ |
| | | // foreach (var bindedDev in currentKey.bindList) |
| | | // { |
| | | // for (int i = 0; i < targetList.Count; i++) |
| | | // { |
| | | // var de = targetList[i]; |
| | | // if (de.DeviceAddr == bindedDev.BindMacAddr && de.DeviceEpoint == bindedDev.BindEpoint) |
| | | // { |
| | | // oldTargetList.Add(de); |
| | | // targetList.RemoveAt(i); |
| | | // i--; |
| | | // } |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | //2、配置模式 |
| | | Panel.SetWritableValueResponAllData temp = null; |
| | | switch (currentModeID) |
| | | { |
| | | for (int i = 0; i < targetList.Count; i++) |
| | | case 100: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_On); |
| | | break; |
| | | case 101: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_oFF); |
| | | break; |
| | | case 102: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_OnOff); |
| | | break; |
| | | case 200: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Up); |
| | | break; |
| | | case 201: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Down); |
| | | break; |
| | | case 203: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up); |
| | | break; |
| | | case 204: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Down); |
| | | break; |
| | | case 205: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up_Down); |
| | | break; |
| | | case 300: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up); |
| | | break; |
| | | case 301: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down); |
| | | break; |
| | | case 302: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Stop); |
| | | break; |
| | | case 303: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up_Stop); |
| | | break; |
| | | case 304: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down_Stop); |
| | | break; |
| | | } |
| | | if (temp != null && temp.setWritableValueResponData != null && temp.setWritableValueResponData.Status == 0) |
| | | { |
| | | ////删除被勾掉的数据 |
| | | //foreach (var delDev in oldTargetList) |
| | | //{ |
| | | // var delDev1 = new BindObj.BindListResponseObj(); |
| | | // delDev1.BindType = 0; |
| | | // delDev1.BindCluster = currentClusterID; |
| | | // delDev1.BindMacAddr = delDev.DeviceAddr; |
| | | // delDev1.BindEpoint = delDev.DeviceEpoint; |
| | | // var result = await BindInfo.RemoveTargets(delDev1, currentKey); |
| | | |
| | | // if (result == 0) |
| | | // { |
| | | // var bindSc = currentKey.bindList.Find(obj => |
| | | // (obj.BindType == 0 |
| | | // && obj.BindCluster == currentClusterID |
| | | // && obj.BindMacAddr == delDev.DeviceAddr |
| | | // && obj.BindEpoint == delDev.DeviceEpoint |
| | | // )); |
| | | // currentKey.bindList.Remove(bindSc); |
| | | // } |
| | | //} |
| | | |
| | | //3、绑定新的数据 |
| | | var addBindeDev = new AddBindData(); |
| | | addBindeDev.DeviceAddr = currentKey.DeviceAddr; |
| | | addBindeDev.Epoint = currentKey.DeviceEpoint; |
| | | |
| | | foreach (var de in targetList) |
| | | { |
| | | var de = targetList[i]; |
| | | if (de.DeviceAddr == bindedDev.BindMacAddr && de.DeviceEpoint == bindedDev.BindEpoint) |
| | | if (de.DeviceAddr != null) |
| | | { |
| | | targetList.RemoveAt(i); |
| | | i--; |
| | | var addBindInfo = new AddBindListObj(); |
| | | addBindInfo.BindType = 0; |
| | | addBindInfo.BindCluster = currentClusterID; |
| | | addBindInfo.BindMacAddr = de.DeviceAddr; |
| | | addBindInfo.BindEpoint = de.DeviceEpoint; |
| | | addBindeDev.BindList.Add(addBindInfo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | var temp = new Panel.SetWritableValueResponAllData(); |
| | | switch (currentModeID) |
| | | { |
| | | case 100: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_On); |
| | | break; |
| | | case 101: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_oFF); |
| | | break; |
| | | case 102: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_OnOff); |
| | | break; |
| | | case 200: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Up); |
| | | break; |
| | | case 201: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Down); |
| | | break; |
| | | case 203: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up); |
| | | break; |
| | | case 204: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Down); |
| | | break; |
| | | case 205: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up_Down); |
| | | break; |
| | | case 300: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up); |
| | | break; |
| | | case 301: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down); |
| | | break; |
| | | case 302: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Stop); |
| | | break; |
| | | case 303: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up_Stop); |
| | | break; |
| | | case 304: |
| | | temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down_Stop); |
| | | break; |
| | | } |
| | | if (temp.setWritableValueResponData?.Status != 0) |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh); |
| | | btnFinifh.Enable = true; |
| | | btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | var addBindeDev = new AddBindData(); |
| | | addBindeDev.DeviceAddr = currentKey.DeviceAddr; |
| | | addBindeDev.Epoint = currentKey.DeviceEpoint; |
| | | |
| | | foreach (var de in targetList) |
| | | { |
| | | if (de.DeviceAddr != null) |
| | | { |
| | | var addBindInfo = new AddBindListObj(); |
| | | addBindInfo.BindType = 0; |
| | | addBindInfo.BindCluster = currentClusterID; |
| | | addBindInfo.BindMacAddr = de.DeviceAddr; |
| | | addBindInfo.BindEpoint = de.DeviceEpoint; |
| | | addBindeDev.BindList.Add(addBindInfo); |
| | | } |
| | | } |
| | | bool isFinish = false; |
| | | try |
| | | { |
| | | CommonPage.Loading.Start(""); |
| | | var dev = new AddedDeviceBindResponseAllData(); |
| | | dev = await currentKey.AddDeviceBindAsync(addBindeDev); |
| | | foreach (var ab in dev.addedDeviceBindResponseData?.BindList) |
| | | if (dev.addedDeviceBindResponseData == null) |
| | | { |
| | | switch (ab.Result) |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | case 0: |
| | | currentKey.bindList.Add((BindListResponseObj)ab); |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | }); |
| | | btnFinifh.Enable = true; |
| | | btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; |
| | | } |
| | | else |
| | | { |
| | | foreach (var ab in dev.addedDeviceBindResponseData?.BindList) |
| | | { |
| | | switch (ab.Result) |
| | | { |
| | | case 0: |
| | | currentKey.bindList.Add((BindListResponseObj)ab); |
| | | |
| | | for (int i = 0; i < targetList.Count; i++) |
| | | { |
| | | var de = targetList[i]; |
| | | var sc1 = new SceneUI(); |
| | | if (de.DeviceAddr == null) |
| | | for (int i = 0; i < targetList.Count; i++) |
| | | { |
| | | sc1 = (SceneUI)de; |
| | | var de = targetList[i]; |
| | | var sc1 = new SceneUI(); |
| | | if (de.DeviceAddr == null) |
| | | { |
| | | sc1 = (SceneUI)de; |
| | | |
| | | if (sc1.Id == ab.BindScenesId) |
| | | { |
| | | targetList.RemoveAt(i); |
| | | i--; |
| | | } |
| | | } |
| | | } |
| | | isFinish = true; |
| | | break; |
| | | case 1: |
| | | new Tip() |
| | | { |
| | | MaxWidth = 150, |
| | | Text = Language.StringByID(R.MyInternationalizationString.BindErrorAbsence), |
| | | Direction = AMPopTipDirection.Up, |
| | | CloseTime = 1 |
| | | }.Show(btnFinifh); |
| | | break; |
| | | case 2: |
| | | var abr = dev.addBindResultResponseData?.Result; |
| | | switch (dev.addBindResultResponseData?.Result) |
| | | { |
| | | case 0: |
| | | currentKey.bindList.Add((BindListResponseObj)ab); |
| | | for (int i = 0; i < targetList.Count; i++) |
| | | { |
| | | var de = targetList[i]; |
| | | if (de.DeviceAddr == ab.BindMacAddr && de.DeviceEpoint == ab.BindEpoint) |
| | | if (sc1.Id == ab.BindScenesId) |
| | | { |
| | | targetList.RemoveAt(i); |
| | | i--; |
| | | } |
| | | } |
| | | isFinish = true; |
| | | break; |
| | | case 140: |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | break; |
| | | default: |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | break; |
| | | } |
| | | break; |
| | | case 3: |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindErrorExisted), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | break; |
| | | case 4: |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | isFinish = true; |
| | | break; |
| | | case 1: |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() |
| | | { |
| | | MaxWidth = 150, |
| | | Text = Language.StringByID(R.MyInternationalizationString.BindErrorAbsence), |
| | | Direction = AMPopTipDirection.Up, |
| | | CloseTime = 1 |
| | | }.Show(btnFinifh); |
| | | }); |
| | | break; |
| | | case 2: |
| | | var abr = dev.addBindResultResponseData?.Result; |
| | | switch (dev.addBindResultResponseData?.Result) |
| | | { |
| | | case 0: |
| | | currentKey.bindList.Add((BindListResponseObj)ab); |
| | | for (int i = 0; i < targetList.Count; i++) |
| | | { |
| | | var de = targetList[i]; |
| | | if (de.DeviceAddr == ab.BindMacAddr && de.DeviceEpoint == ab.BindEpoint) |
| | | { |
| | | targetList.RemoveAt(i); |
| | | i--; |
| | | } |
| | | } |
| | | isFinish = true; |
| | | break; |
| | | case 140: |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | }); |
| | | break; |
| | | default: |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | }); |
| | | break; |
| | | } |
| | | break; |
| | | case 3: |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindErrorExisted), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | }); |
| | | break; |
| | | case 4: |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | }); |
| | | break; |
| | | default: |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); |
| | | }); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | | finally |
| | | else |
| | | { |
| | | if (isFinish) |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | if (action != null) |
| | | { |
| | | action(currentKey.bindList); |
| | | |
| | | } |
| | | this.RemoveFromParent(); |
| | | } |
| | | else |
| | | { |
| | | this.RemoveFromParent(); |
| | | } |
| | | CommonPage.Loading.Hide(); |
| | | new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh); |
| | | }); |
| | | btnFinifh.Enable = true; |
| | | btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; |
| | | } |
| | | } |
| | | catch { } |
| | | finally |
| | | { |
| | | if (isFinish) |
| | | { |
| | | if (action != null) |
| | | { |
| | | action(currentKey.bindList); |
| | | |
| | | } |
| | | this.RemoveFromParent(); |
| | | } |
| | | else |
| | | { |
| | | this.RemoveFromParent(); |
| | | } |
| | | CommonPage.Loading.Hide(); |
| | | btnFinifh.Enable = true; |
| | | btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; |
| | | } |
| | | }; |
| | | #endregion |
| | | } |