黄学彪
2019-12-17 5986f63b75bd81c6cef262c670e9251c038cbf5d
ZigbeeApp/Shared/Phone/Device/Category/Category.cs
@@ -149,6 +149,10 @@
                {
                    try
                    {
                        if (common.DeviceStatusReport.AttriBute == null || common.DeviceStatusReport.AttriBute.Count == 0)
                        {
                            return;
                        }
                        for (int i = 0; deviceListScrolView != null && i < deviceListScrolView.ChildrenCount; i++)
                        {
                            var rowLayout = deviceListScrolView.GetChildren(i) as RowLayout;
@@ -169,10 +173,6 @@
                                    {
                                        var light = deviceUI.CommonDevice as ToggleLight;
                                        light.DeviceStatusReport = common.DeviceStatusReport;
                                        if (light.DeviceStatusReport.AttriBute == null || light.DeviceStatusReport.AttriBute.Count == 0)
                                        {
                                            continue;
                                        }
                                        light.OnOffStatus = light.DeviceStatusReport.AttriBute[0].AttriButeData;
                                        var row = rowLayout.GetChildren(0) as CategoryFunctionRow;
                                        row.SetStatu(light.OnOffStatus == 1);
@@ -194,10 +194,6 @@
                                    {
                                        var airSwitch = deviceUI.CommonDevice as ZigBee.Device.AirSwitch;
                                        airSwitch.DeviceStatusReport = common.DeviceStatusReport;
                                        if (airSwitch.DeviceStatusReport.AttriBute == null || airSwitch.DeviceStatusReport.AttriBute.Count == 0)
                                        {
                                            return;
                                        }
                                        airSwitch.OnOffStatus = airSwitch.DeviceStatusReport.AttriBute[0].AttriButeData;
                                        var row = rowLayout.GetChildren(0) as CategoryFunctionRow;
                                        row.SetStatu(airSwitch.OnOffStatus == 1);
@@ -249,57 +245,47 @@
                                    if (common.DeviceStatusReport.CluterID == 513)
                                    {
                                        var attriButeList = common.DeviceStatusReport.AttriBute;
                                        if (attriButeList == null || attriButeList.Count == 0)
                                        {
                                            return;
                                        }
                                        var ac = deviceUI.CommonDevice as ZigBee.Device.AC;
                                        ac.DeviceStatusReport = common.DeviceStatusReport;
                                        var curTemp = (attriButeList[0].AttriButeData / 100 < ACControlBase.Temperature_High || attriButeList[0].AttriButeData / 100 > ACControlBase.Temperature_Low) ? attriButeList[0].AttriButeData / 100 : ACControlBase.Temperature_Default;
                                        switch (attriButeList[0].AttributeId)
                                        foreach(var attList in attriButeList)
                                        {
                                            var curTemp = (attList.AttriButeData / 100 < ACControlBase.Temperature_High && attList.AttriButeData / 100 > ACControlBase.Temperature_Low) ? attList.AttriButeData / 100 : ACControlBase.Temperature_Default;
                                            switch (attList.AttributeId)
                                        {
                                            case 0:
                                                ac.currentLocalTemperature = curTemp;
                                                ac.LastDateTime = DateTime.Now;
                                                break;
                                            case 17:
                                                ac.currentCoolingSetpoint = curTemp;
                                                ac.LastDateTime = DateTime.Now;
                                                break;
                                            case 18:
                                                ac.currentHeatingSetpoint = curTemp;
                                                ac.LastDateTime = DateTime.Now;
                                                break;
                                            case 4096:
                                                ac.currentAutoSetpoint = curTemp;
                                                ac.LastDateTime = DateTime.Now;
                                                break;
                                            case 28:
                                                //此属性描述恒温设备正处于哪种模式
                                                ac.currentSystemMode = attriButeList[0].AttriButeData;
                                                    ac.currentSystemMode = attList.AttriButeData;
                                                ac.LastDateTime = DateTime.Now;
                                                break;
                                            case 4099:
                                                var value = Convert.ToString(attriButeList[0].AttriButeData, 2).PadLeft(16, '0');
                                                    var value = Convert.ToString(attList.AttriButeData, 2).PadLeft(16, '0');
                                                var modeStr = value.Substring(value.Length - 5, 5);
                                                for (int j = 0; j < modeStr.Length; j++)
                                                {
                                                    ac.listSupportMode[j] = Convert.ToInt32(modeStr[j]) == 49 ? 1 : 0;
                                                }
                                                break;
                                            case 4097:
                                                //过虑网清洗标志:42
                                                ac.CleanStatu = attriButeList[0].AttriButeData == 42;
                                                    ac.CleanStatu = attList.AttriButeData == 42;
                                                break;
                                        }
                                        }
                                        var row = rowLayout.GetChildren(0) as CategoryFunctionRow;
                                        row.SetStatu(ac.currentSystemMode != 0);
                                        row.SetStatuText(deviceUI.GetDeviceStatu());
@@ -309,21 +295,20 @@
                                    {
                                        var ac = deviceUI.CommonDevice as ZigBee.Device.AC;
                                        var attriButeList = common.DeviceStatusReport.AttriBute;
                                        if (attriButeList == null || attriButeList.Count == 0)
                                        {
                                            return;
                                        }
                                        ac.DeviceStatusReport = common.DeviceStatusReport;
                                        switch (attriButeList[0].AttributeId)
                                        foreach(var attList in attriButeList)
                                        {
                                            switch (attList.AttributeId)
                                        {
                                            case 0:
                                                ac.currentFanMode = attriButeList[0].AttriButeData;
                                                    ac.currentFanMode = attList.AttriButeData;
                                                ac.LastDateTime = DateTime.Now;
                                                break;
                                            case 4096:
                                                ac.currentFanSwingMode = attriButeList[0].AttriButeData;
                                                    ac.currentFanSwingMode = attList.AttriButeData;
                                                ac.LastDateTime = DateTime.Now;
                                                break;
                                            }
                                        }
                                        var row = rowLayout.GetChildren(0) as CategoryFunctionRow;
                                        row.SetStatu(ac.currentSystemMode != 0);
@@ -345,12 +330,17 @@
                                    {
                                        var dimmableLight = deviceUI.CommonDevice as DimmableLight;
                                        dimmableLight.DeviceStatusReport = common.DeviceStatusReport;
                                        //记录、更新状态
                                        if (dimmableLight.DeviceStatusReport.AttriBute == null || dimmableLight.DeviceStatusReport.AttriBute.Count == 0)
                                        {
                                            continue;
                                        }
                                        dimmableLight.OnOffStatus = dimmableLight.DeviceStatusReport.AttriBute[0].AttriButeData;
                                        var row = rowLayout.GetChildren(0) as CategoryFunctionRow;
                                        row.SetStatu(dimmableLight.OnOffStatus == 1);
                                        row.SetStatuText(deviceUI.GetDeviceStatu());
                                        dimmableLight.LastDateTime = DateTime.Now;
                                    }
                                    if (common.DeviceStatusReport.CluterID == 8)
                                    {
                                        var dimmableLight = deviceUI.CommonDevice as DimmableLight;
                                        dimmableLight.DeviceStatusReport = common.DeviceStatusReport;
                                        dimmableLight.Level = dimmableLight.DeviceStatusReport.AttriBute[0].AttriButeData;
                                        var row = rowLayout.GetChildren(0) as CategoryFunctionRow;
                                        row.SetStatu(dimmableLight.OnOffStatus == 1);
                                        row.SetStatuText(deviceUI.GetDeviceStatu());
@@ -530,7 +520,7 @@
            functionBtn.Init();
            functionBtn.SetTitle(R.MyInternationalizationString.Function);
            //自动化
            automationBtn = new ButtonLineForm(CommonFormResouce.X_Left + 150 * 2 + 20, 34, 150, 68);
            automationBtn = new ButtonLineForm(CommonFormResouce.X_Left + 150 * 2 + 20+50, 34, 150, 68);
            automationBtn.Init();
            automationBtn.SetTitle(R.MyInternationalizationString.Automation);
            //隐藏自动化
@@ -869,14 +859,21 @@
                            }
                        }
                    }
                    foreach (var deviceUI in sameTypeList)
                    for (int i=0;i<sameTypeList.Count;i++)
                    {
                        var deviceUI = sameTypeList[i];
                        new System.Threading.Thread(() =>
                        {
                            Application.RunOnMainThread(() =>
                            {
                                try
                    {
                        //删除设备
                        EventHandler<MouseEventArgs> delEvent = (delSender, delE) =>
                        {
                            var alert = new CustomAlert();
                            AddChidren(alert);
                            alert.Show(Language.StringByID(R.MyInternationalizationString.ConfirmDelete));
                                        alert.Show(Language.StringByID(R.MyInternationalizationString.DeleteFunction));
                            alert.ResultEventHandler += (e2) =>
                            {
                                if (e2)
@@ -904,11 +901,11 @@
                        {
                            //灯
                            var light = deviceUI.CommonDevice as ToggleLight;
                            //补上非远程
                            if (light.Gateway == null)
                                        if (light.Gateway != null)
                            {
                                continue;
                            }
                                            new System.Threading.Thread(() =>
                                            {
                                                System.Threading.Thread.Sleep(100 * i);
                            if (light.Gateway.IsVirtual)
                            {
                                UserHomeView.ReadStatus(light, () =>
@@ -924,6 +921,8 @@
                                    ReadDeviceAttributeLogic.Instance.SendLightStatuComand(deviceUI.CommonDevice);
                                }
                            }
                                            })
                                            { IsBackground = true }.Start();
                            var deviceTypeRowLayout = new RowLayout()
                            {
@@ -1006,7 +1005,7 @@
                                Tag = deviceUI,
                                Radius = 0
                            };
                            var delBtn = new Device.CommonForm.RowLayoutDeleteButton()
                                            var delBtn = new CommonForm.RowLayoutDeleteButton()
                            {
                                Tag = deviceUI,
                                Radius = 0
@@ -1019,15 +1018,16 @@
                                delBtn.MouseUpEventHandler += delEvent;
                            }
                        }
                        else if (deviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.AirSwitch)
                                    }
                                    else if (deviceUI.CommonDevice.Type == DeviceType.AirSwitch)
                        {
                            //空气开关
                            var airSwitch = deviceUI.CommonDevice as ZigBee.Device.AirSwitch;
                            //补上非远程
                            if (airSwitch.Gateway == null)
                                        var airSwitch = deviceUI.CommonDevice as AirSwitch;
                                        if (airSwitch.Gateway != null)
                            {
                                continue;
                            }
                                            new System.Threading.Thread(() =>
                                            {
                                                System.Threading.Thread.Sleep(100 * i);
                            if (airSwitch.Gateway.IsVirtual)
                            {
                                UserHomeView.ReadStatus(airSwitch, () =>
@@ -1042,6 +1042,8 @@
                                    ReadDeviceAttributeLogic.Instance.SendLightStatuComand(deviceUI.CommonDevice);
                                }
                            }
                                            })
                                            { IsBackground = true }.Start();
                            var deviceTypeRowLayout = new RowLayout()
                            {
@@ -1106,7 +1108,7 @@
                                Tag = deviceUI,
                                Radius = 0
                            };
                            var delBtn = new Device.CommonForm.RowLayoutDeleteButton()
                                            var delBtn = new CommonForm.RowLayoutDeleteButton()
                            {
                                Tag = deviceUI,
                                Radius = 0
@@ -1118,17 +1120,17 @@
                                deviceTypeRowLayout.AddRightView(delBtn);
                                delBtn.MouseUpEventHandler += delEvent;
                            }
                        }
                        else if (deviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.DimmableLight)
                                    }
                                    else if (deviceUI.CommonDevice.Type == DeviceType.DimmableLight)
                        {
                            //调光灯
                            var dimmableLight = deviceUI.CommonDevice as ZigBee.Device.DimmableLight;
                            //补上非远程
                            if (dimmableLight.Gateway == null)
                                        if (dimmableLight.Gateway != null)
                            {
                                continue;
                            }
                                            new System.Threading.Thread(() =>
                                            {
                                                System.Threading.Thread.Sleep(100 * i);
                            if (dimmableLight.Gateway.IsVirtual)
                            {
                                UserHomeView.ReadStatus(dimmableLight, () =>
@@ -1143,6 +1145,8 @@
                                    ReadDeviceAttributeLogic.Instance.SendDimmableLightStatuComand(deviceUI.CommonDevice);
                                }
                            }
                                            })
                                            { IsBackground = true }.Start();
                            var deviceTypeRowLayout = new RowLayout()
                            {
@@ -1220,15 +1224,16 @@
                                delBtn.MouseUpEventHandler += delEvent;
                            }
                        }
                        else if (deviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.Thermostat)
                                    }
                                    else if (deviceUI.CommonDevice.Type == DeviceType.Thermostat)
                        {
                            //空调
                            var ac = deviceUI.CommonDevice as ZigBee.Device.AC;
                            //补上非远程
                            if (ac.Gateway == null)
                                        if (ac.Gateway != null)
                            {
                                continue;
                            }
                                            new System.Threading.Thread(() =>
                                            {
                                                System.Threading.Thread.Sleep(100 * i);
                            if (ac.Gateway.IsVirtual)
                            {
                                //发送读取状态命令
@@ -1245,6 +1250,8 @@
                                    ReadDeviceAttributeLogic.Instance.SendACStatuComand(deviceUI.CommonDevice);
                                }
                            }
                                            })
                                            { IsBackground = true }.Start();
                            var deviceTypeRowLayout = new RowLayout()
                            {
@@ -1299,7 +1306,7 @@
                                Tag = deviceUI,
                                Radius = 0
                            };
                            var delBtn = new Device.CommonForm.RowLayoutDeleteButton()
                                            var delBtn = new CommonForm.RowLayoutDeleteButton()
                            {
                                Tag = deviceUI,
                                Radius = 0
@@ -1322,15 +1329,16 @@
                                acControl.Show(deviceUI, room);
                            };
                        }
                        else if (deviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.WindowCoveringDevice)
                                    }
                                    else if (deviceUI.CommonDevice.Type == DeviceType.WindowCoveringDevice)
                        {
                            //卷帘
                            var rollerShade = deviceUI.CommonDevice as ZigBee.Device.Rollershade;
                            //不上非远程
                            if (rollerShade.Gateway == null)
                                        if (rollerShade.Gateway != null)
                            {
                                continue;
                            }
                                            new System.Threading.Thread(() =>
                                            {
                                                System.Threading.Thread.Sleep(100 * i);
                            if (rollerShade.Gateway.IsVirtual)
                            {
                                UserHomeView.ReadStatus(rollerShade, () =>
@@ -1346,6 +1354,8 @@
                                    ReadDeviceAttributeLogic.Instance.SendCurtainStatuComand(deviceUI.CommonDevice);
                                }
                            }
                                            })
                                            { IsBackground = true }.Start();
                            var deviceTypeRowLayout = new RowLayout()
                            {
@@ -1409,7 +1419,8 @@
                                rollerShadeControl.Show(deviceUI, room);
                            };
                        }
                        else if(deviceUI.CommonDevice.Type == ZigBee.Device.DeviceType.DoorLock)
                                    }
                                    else if (deviceUI.CommonDevice.Type == DeviceType.DoorLock)
                        {
                            var deviceTypeRowLayout = new RowLayout()
                            {
@@ -1426,7 +1437,6 @@
                            deviceRow.SetStatuText(deviceUI.GetDeviceStatu());
                            deviceRow.HideSwitchBtn(true);
                            deviceTypeRowLayout.AddChidren(deviceRow);
                            deviceRow.ClickBtn.MouseUpEventHandler += (send2, e2) =>
                            {
@@ -1487,6 +1497,14 @@
                            }
                        }
                    }
                                catch
                                {
                                }
                            });
                        })
                        { IsBackground=true}.Start();
                    }
                };
                foreach (var deviceType in Common.Room.GetdeviceTypes(room))
@@ -1507,7 +1525,6 @@
                    typeRowLayout.AddChidren(functionTypeIMG);
                    functionTypeIMG.ClickBtn.MouseUpEventHandler += ShowSameTypeFunction;
                    if (deviceType == room.DeviceUIList[0].CommonDevice.Type)
                    {
@@ -1675,9 +1692,7 @@
        /// GetDelayScene
        /// </summary>
        /// <param name="scrolViewLayout"></param>
        private void GetDelayScene(VerticalScrolViewLayout scrolViewLayout)
        {
            new System.Threading.Thread(async () =>
        private async void GetDelayScene(VerticalScrolViewLayout scrolViewLayout)
            {
                var catDelaySceneResponseAllData = await Scene.CatDelaySceneAsync();
                if (catDelaySceneResponseAllData == null)
@@ -1691,8 +1706,6 @@
                }
                var delayList = catDelaySceneResponseData.DelayScenesList;
                Application.RunOnMainThread(() =>
                {
                    for (int i = 0; scrolViewLayout != null && i < scrolViewLayout.ChildrenCount; i++)
                    {
                        var sceneView = scrolViewLayout.GetChildren(i) as SceneCategoryView;
@@ -1701,31 +1714,31 @@
                            if (delayScenesListResponseInfo.ScenesId == sceneView.scene.Id)
                            {
                                sceneView.scene.RemainTime = delayScenesListResponseInfo.RemainTime;
                        var remainTime= delayScenesListResponseInfo.RemainTime;
                        if (remainTime > 0)
                        {
                                new System.Threading.Thread(() =>
                                {
                                    while (sceneView.scene.RemainTime > 0)
                                while (remainTime-- > 0)
                                    {
                                        System.Threading.Thread.Sleep(1000);
                                        Application.RunOnMainThread(() =>
                                        {
                                            sceneView.SetTimeText(CommonFormResouce.GetTimeString(sceneView.scene.RemainTime));
                                        sceneView.SetTimeText(CommonFormResouce.GetTimeString(remainTime));
                                        });
                                        sceneView.scene.RemainTime -= 1;
                                    }
                                    Application.RunOnMainThread(() =>
                                    {
                                    sceneView.scene.RemainTime = 0;
                                        sceneView.SetTimeImage();
                                    });
                                })
                                { IsBackground = true }.Start();
                        }
                                break;
                            }
                        }
                    }
                });
            })
            { IsBackground = true }.Start();
        }
        /// <summary>