HDL Home App 第二版本 旧平台金堂用 正在使用
hxb
2022-08-30 25429f085093d89d543a0b90e30d0d62d1b7dac9
ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/IndoorUnitListForm.cs
@@ -20,6 +20,14 @@
        /// 控件信息
        /// </summary>
        private Dictionary<string, RowControlInfo> dicControl = new Dictionary<string, RowControlInfo>();
        /// <summary>
        /// 激活的设备地址
        /// </summary>
        private string actionDeviceKeys = null;
        /// <summary>
        /// 接收回复的端点
        /// </summary>
        private HashSet<int> listReceivePoint = new HashSet<int>();
        #endregion
@@ -32,6 +40,11 @@
        public void ShowForm(string i_diviceMac)
        {
            this.listDevice = Common.LocalDevice.Current.GetDevicesByMac(i_diviceMac);
            //收集全部端点
            foreach (var device in this.listDevice)
            {
                listReceivePoint.Add(device.DeviceEpoint);
            }
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uIndoorUnitSettion));
@@ -53,7 +66,7 @@
            var frameTemp = new FrameLayout();
            frameTemp.Height = Application.GetRealHeight(69);
            listView.AddChidrenFrame(frameTemp);
            listView.AddChidren(frameTemp);
            HdlThreadLogic.Current.RunMainInThread(() =>
            {
@@ -64,7 +77,7 @@
                }
                var frameTemp2 = new FrameLayout();
                frameTemp2.Height = Application.GetRealHeight(29);
                listView.AddChidrenFrame(frameTemp2);
                listView.AddChidren(frameTemp2);
                //数据接收
                this.StartReceiveDataEvent();
@@ -82,21 +95,21 @@
        {
            var rowInfo = new RowControlInfo();
            var frameTable = new FrameLayoutControl();
            var frameTable = new FrameLayoutStatuControl();
            frameTable.UseClickStatu = false;
            frameTable.Width = Application.GetRealWidth(994);
            frameTable.Height = Application.GetRealHeight(337);
            frameTable.BackgroundImagePath = "Item/IndoorUnitGround.png";
            frameTable.Gravity = Gravity.CenterHorizontal;
            listView.AddChidrenFrame(frameTable);
            listView.AddChidren(frameTable);
            //设备图标
            var btnIconBack = new FrameLayout();
            btnIconBack.X = Application.GetRealWidth(46);
            btnIconBack.Y = Application.GetRealHeight(43);
            btnIconBack.Height = Application.GetMinRealAverage(112);
            btnIconBack.Width = Application.GetMinRealAverage(112);
            btnIconBack.Radius = (uint)Application.GetMinRealAverage(112) / 2;
            btnIconBack.Height = this.GetPictrueRealSize(112);
            btnIconBack.Width = this.GetPictrueRealSize(112);
            btnIconBack.Radius = (uint)this.GetPictrueRealSize(112) / 2;
            btnIconBack.BackgroundColor = 0xfff5f6fa;
            frameTable.AddChidren(btnIconBack, ChidrenBindMode.NotBind);
            rowInfo.btnIconBack = btnIconBack;
@@ -105,31 +118,43 @@
            btnIcon.Gravity = Gravity.Center;
            Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
            btnIconBack.AddChidren(btnIcon);
            frameTable.ChangedChidrenBindMode(btnIconBack, ChidrenBindMode.BindEventOnly);
            frameTable.ChangedChidrenBindMode(btnIconBack, ChidrenBindMode.BindEvent);
            rowInfo.btnIcon = btnIcon;
            //设备名称
            var btnDeviceName = new NormalViewControl(400, 60, true);
            var btnDeviceName = new NormalViewControl(700, 60, true);
            btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
            btnDeviceName.X = Application.GetRealWidth(193);
            btnDeviceName.Y = Application.GetRealHeight(45);
            frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEventOnly);
            frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEvent);
            rowInfo.btnDeviceName = btnDeviceName;
            //房间
            var btnRoom = new NormalViewControl(400, 50, true);
            btnRoom.X = btnDeviceName.X;
            btnRoom.Y = btnDeviceName.Bottom + Application.GetRealHeight(12);
            btnRoom.TextSize = 12;
            btnRoom.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnRoom.Text = Common.Room.CurrentRoom.GetRoomNameByDevice(device);
            frameTable.AddChidren(btnRoom, ChidrenBindMode.BindEventOnly);
            btnRoom.Text = HdlRoomLogic.Current.GetRoomNameByDevice(device);
            frameTable.AddChidren(btnRoom, ChidrenBindMode.BindEvent);
            rowInfo.btnRoom = btnRoom;
            //摄氏度
            var btnValue = new NormalViewControl(300, 60, true);
            btnValue.Y = Application.GetRealHeight(58);
            btnValue.X = frameTable.Width - Application.GetRealWidth(300 + 58);
            btnValue.TextAlignment = TextAlignment.CenterRight;
            btnValue.TextID = R.MyInternationalizationString.uGetting;
            frameTable.AddChidren(btnValue, ChidrenBindMode.BindEventOnly);
            frameTable.AddChidren(btnValue, ChidrenBindMode.BindEvent);
            rowInfo.btnValue = btnValue;
            //室内温度
            if (device.currentLocalTemperature == 0)
            {
                //0℃
                btnValue.Text = "0.0℃";
            }
            else
            {
                btnValue.Text = device.currentLocalTemperature + ".0℃";
            }
            //警告图标
            var btnWarningIcon = new IconViewControl(69);
            btnWarningIcon.X = btnIconBack.X;
@@ -158,31 +183,51 @@
            {
                if (btnSwitch.IsSelected == false)
                {
                    //打开空调
                    var result = await HdlDeviceAirConditionerLogic.Current.OpenAirConditioner(device);
                    if (result == false)
                    //如果不是虚拟住宅的话
                    if (Common.Config.Instance.Home.IsVirtually == false)
                    {
                        return;
                        //打开空调
                        var result = await HdlDeviceAirConditionerLogic.Current.OpenAirConditioner(device);
                        if (result == false)
                        {
                            return;
                        }
                    }
                    btnIcon.IsSelected = true;
                    btnIconBack.BackgroundColor = 0xfffef1ed;
                }
                else
                {
                    //关闭空调
                    var result = await HdlDeviceAirConditionerLogic.Current.CloseAirConditioner(device);
                    if (result == false)
                    //如果不是虚拟住宅的话
                    if (Common.Config.Instance.Home.IsVirtually == false)
                    {
                        return;
                        //关闭空调
                        var result = await HdlDeviceAirConditionerLogic.Current.CloseAirConditioner(device);
                        if (result == false)
                        {
                            return;
                        }
                    }
                    btnIcon.IsSelected = false;
                    btnIconBack.BackgroundColor = 0xfff5f6fa;
                }
                btnSwitch.IsSelected = !btnSwitch.IsSelected;
                //如果是虚拟住宅的话
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    device.currentSystemMode = btnSwitch.IsSelected == true ? 3 : 0;
                }
            };
            //如果是展示模板的话
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                btnSwitch.CanClick = false;
            }
            frameTable.ButtonClickEvent += (sender, e) =>
            {
                this.actionDeviceKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
                var form = new IndoorUnitSettionForm();
                form.AddForm(device);
            };
@@ -199,25 +244,31 @@
        /// </summary>
        private void SetReadAttributeComand()
        {
            //如果是虚拟住宅或者展示模板的话
            if (Common.Config.Instance.Home.IsShowTemplate == true || Common.Config.Instance.Home.IsVirtually == true)
            {
                return;
            }
            HdlThreadLogic.Current.RunThread(() =>
            {
                for (int i = 0; i < listDevice.Count; i++)
                while (this.listReceivePoint.Count > 0 && this.Parent != null)
                {
                    if (i != 0 && i % 5 == 0)
                    for (int i = 0; i < listDevice.Count; i++)
                    {
                        //读取5个后,间隔一段时间
                        System.Threading.Thread.Sleep(200);
                        if (this.Parent == null)
                        {
                            return;
                        }
                        //已经发送过了,就不用再发送
                        if (this.listReceivePoint.Contains(listDevice[i].DeviceEpoint) == true)
                        {
                            //读取状态
                            HdlDeviceAttributeLogic.Current.SendThermostatStatuComand(listDevice[i]);
                            System.Threading.Thread.Sleep(200);
                        }
                    }
                    //获取当前室温
                    ((AC)listDevice[i]).ReadLocalTemperature();
                    //获取开关状态(处于某种工作状态,即为打开状态)
                    ((AC)listDevice[i]).ReadSystemMode();
                    //清洗滤网
                    listDevice[i].ReadAttri(Cluster_ID.Thermostat, AttriButeId.FilterCleaningStatus);
                    //3秒后再次循环
                    System.Threading.Thread.Sleep(3000);
                }
            });
        }
@@ -238,6 +289,13 @@
                {
                    return;
                }
                var localDevice = Common.LocalDevice.Current.GetDevice(mainkeys);
                if (localDevice == null)
                {
                    return;
                }
                //已经接收到数据,则移除端点
                this.listReceivePoint.Remove(device.DeviceEpoint);
                var rowInfo = dicControl[mainkeys];
                for (int i = 0; i < device.DeviceStatusReport.AttriBute.Count; i++)
@@ -245,27 +303,19 @@
                    var data = device.DeviceStatusReport.AttriBute[i];
                    if (data.AttributeId == 0)
                    {
                        //室内温度
                        if (data.AttriButeData == 0)
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            //0℃
                            rowInfo.btnValue.Text = "0.0℃";
                        }
                        else if (data.AttriButeData > 32767)
                        {
                            //负数(特殊处理)
                            string strValue = (data.AttriButeData - 65536).ToString();
                            //小数点需要一位
                            strValue = strValue.Substring(0, strValue.Length - 1);
                            rowInfo.btnValue.Text = strValue.Insert(strValue.Length - 1, ".") + "℃";
                        }
                        else
                        {
                            //小数点需要一位
                            string strValue = data.AttriButeData.ToString();
                            strValue = strValue.Substring(0, strValue.Length - 1);
                            rowInfo.btnValue.Text = strValue.Insert(strValue.Length - 1, ".") + "℃";
                        }
                            //室内温度
                            if (((AC)localDevice).currentLocalTemperature == 0)
                            {
                                //0℃
                                rowInfo.btnValue.Text = "0.0℃";
                            }
                            else
                            {
                                rowInfo.btnValue.Text = ((AC)localDevice).currentLocalTemperature + ".0℃";
                            }
                        });
                    }
                    else if (data.AttributeId == 28)
                    {
@@ -273,9 +323,12 @@
                        //Off = 0  Auto = 1 Cool = 3 Heat = 4 FanOnly = 7  Dry = 8
                        if (data.AttriButeData != 0)
                        {
                            rowInfo.btnSwitch.IsSelected = true;
                            rowInfo.btnIcon.IsSelected = true;
                            rowInfo.btnIconBack.BackgroundColor = 0xfffef1ed;
                            HdlThreadLogic.Current.RunMain(() =>
                            {
                                rowInfo.btnSwitch.IsSelected = true;
                                rowInfo.btnIcon.IsSelected = true;
                                rowInfo.btnIconBack.BackgroundColor = 0xfffef1ed;
                            });
                        }
                    }
                    else if (data.AttributeId == 4097)
@@ -283,9 +336,12 @@
                        //42:需要清洗滤网
                        if (data.AttriButeData == 42)
                        {
                            rowInfo.btnWarningIcon.Visible = true;
                            //请注意清洗滤网哦
                            rowInfo.btnWarningMsg.TextID = R.MyInternationalizationString.uPleaseClreanACfilter;
                            HdlThreadLogic.Current.RunMain(() =>
                            {
                                rowInfo.btnWarningIcon.Visible = true;
                                //请注意清洗滤网哦
                                rowInfo.btnWarningMsg.TextID = R.MyInternationalizationString.uPleaseClreanACfilter;
                            });
                        }
                    }
                }
@@ -308,6 +364,31 @@
        #endregion
        #region ■ 界面重新激活事件___________________
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override int FormActionAgainEvent()
        {
            if (this.actionDeviceKeys != null && dicControl.ContainsKey(this.actionDeviceKeys) == true)
            {
                //刷新设备信息
                var device = Common.LocalDevice.Current.GetDevice(this.actionDeviceKeys);
                if (device != null)
                {
                    var contr = dicControl[this.actionDeviceKeys];
                    contr.btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
                    contr.btnRoom.Text = HdlRoomLogic.Current.GetRoomNameByDevice(device);
                }
            }
            this.actionDeviceKeys = null;
            return 1;
        }
        #endregion
        #region ■ 结构体_____________________________
        /// <summary>
@@ -316,6 +397,14 @@
        private class RowControlInfo
        {
            /// <summary>
            /// 设备名字
            /// </summary>
            public NormalViewControl btnDeviceName = null;
            /// <summary>
            /// 设备房间
            /// </summary>
            public NormalViewControl btnRoom = null;
            /// <summary>
            /// 设备图标背景
            /// </summary>
            public FrameLayout btnIconBack = null;