wxr
2023-08-23 96e9ff2e5a54f54cdbb6b8b2f049fdf6a837de3c
OnPro/HDL_ON/UI/UI2/1-HomePage/HomePageBLL.cs
@@ -81,152 +81,6 @@
        }
        /// <summary>
        /// 更新安防状态
        /// </summary>
        public static void LoadEvent_RefreshSecurityStatus()
        {
            try
            {
                Application.RunOnMainThread(() =>
                {
                    if (bodyView != null)
                    {
                        lock (FunctionList.List.securities)
                        {
                            bodyView.btnSecurityStatus.IsSelected = false;
                            foreach (var temp in FunctionList.List.securities)
                            {
                                if (temp.status == "enable")
                                {
                                    if (temp.alarm)
                                    {
                                        bodyView.btnSecurityStatus.SelectedImagePath = "Collection/DefenseAlarmIcon.png";
                                    }
                                    else
                                    {
                                        bodyView.btnSecurityStatus.SelectedImagePath = "Collection/DefenseStatusIcon.png";
                                    }
                                    bodyView.btnSecurityStatus.IsSelected = true;
                                    return;
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                MainPage.Log($"安防主页更新异常:{ex.Message}");
            }
        }
        /// <summary>
        /// 更新室内传感器数据-湿度
        /// </summary>
        public static void LoadEvent_RefreshEnvirIndoorHumi()
        {
            Application.RunOnMainThread(() =>
            {
                if (bodyView != null)
                {
                    var humiSensorList = FunctionList.List.GetEnvirSensorsList().FindAll((obj) => obj.spk == SPK.SensorHumidity);
                    var enviSensorList = FunctionList.List.GetEnvirSensorsList().FindAll((obj) => SPK.EvironmentSensorList().Contains(obj.spk ));
                    foreach (var enviTemp in enviSensorList)
                    {
                        var tempAttr = enviTemp.attributes.Find((obj) => obj.key == "humidity");
                        if (tempAttr != null)
                        {
                            var newTemp = new Function()
                            {
                                name = enviTemp.name,
                                sid = enviTemp.sid,
                                deviceId = enviTemp.deviceId,
                                attributes = new List<FunctionAttributes> { new FunctionAttributes { key = "humidity", state = tempAttr.state, curValue = tempAttr.curValue } },
                            };
                            humiSensorList.Add(newTemp);
                        }
                    }
                    double humiTotalValues = 0;
                    int humiTotalCount = 0;
                    foreach (var temp in humiSensorList)
                    {
                        double humiValue = 0;
                        double.TryParse(temp.GetAttrState("humidity"), out humiValue);
                        if(humiValue > 0)
                        {
                            humiTotalValues += humiValue;
                            humiTotalCount++;
                        }
                    }
                    if (humiTotalValues > 0)
                    {
                        bodyView.btnIndoorHumiValues.Text = "/" + (humiTotalValues /humiTotalCount).ToString("0")+ "%";
                    }
                    bodyView.btnIndoorHumiValues.Width = bodyView.btnIndoorHumiValues.GetTextWidth();
                    bodyView.btnHumidityIcon.X = bodyView.btnIndoorTempValues.Right + Application.GetRealWidth(8);
                    bodyView.btnHumidityValues.X = bodyView.btnHumidityIcon.Right + Application.GetRealWidth(4);
                    bodyView.btnIndoorHumiValues.X = bodyView.btnHumidityValues.Right;
                    bodyView.btnPm25Icon.X = bodyView.btnIndoorHumiValues.Right + Application.GetRealWidth(4);
                    bodyView.btnPm25Values.X = bodyView.btnPm25Icon.Right + Application.GetRealWidth(4);
                }
            });
        }
        /// <summary>
        /// 更新室内传感器数据
        /// </summary>
        public static void LoadEvent_RefreshEnvirIndoorTemp()
        {
            Application.RunOnMainThread(() =>
            {
                if (bodyView != null)
                {
                    var tempSensorList = FunctionList.List.GetEnvirSensorsList().FindAll((obj) => obj.spk == SPK.SensorTemperature);
                    var enviSensorList = FunctionList.List.GetEnvirSensorsList().FindAll((obj) => SPK.EvironmentSensorList().Contains(obj.spk));
                    foreach (var enviTemp in enviSensorList)
                    {
                        var tempAttr = enviTemp.attributes.Find((obj) => obj.key == "temperature");
                        if (tempAttr != null)
                        {
                            var newTemp = new Function()
                            {
                                name = enviTemp.name,
                                sid = enviTemp.sid,
                                deviceId = enviTemp.deviceId,
                                attributes = new List<FunctionAttributes> { new FunctionAttributes { key = "temperature", state = tempAttr.state, curValue = tempAttr.curValue } },
                            };
                            tempSensorList.Add(newTemp);
                        }
                    }
                    double tempTotalValues = 0;
                    int tempTotalCount = 0;
                    foreach (var temp in tempSensorList)
                    {
                        double tempValue = 0;
                        double.TryParse(temp.GetAttrState("temperature"), out tempValue);
                        if (tempValue > 0)
                        {
                            tempTotalValues += tempValue;
                            tempTotalCount++;
                        }
                    }
                    if (tempTotalValues > 0)
                    {
                        bodyView.btnIndoorTempValues.Text = "/" + (tempTotalValues /tempTotalCount).ToString("0.0")+ "°";
                    }
                    bodyView.btnIndoorTempValues.Width = bodyView.btnIndoorTempValues.GetTextWidth();
                    bodyView.btnHumidityIcon.X = bodyView.btnIndoorTempValues.Right + Application.GetRealWidth(8);
                    bodyView.btnHumidityValues.X = bodyView.btnHumidityIcon.Right + Application.GetRealWidth(4);
                    bodyView.btnIndoorHumiValues.X = bodyView.btnHumidityValues.Right;
                    bodyView.btnPm25Icon.X = bodyView.btnIndoorHumiValues.Right + Application.GetRealWidth(4);
                    bodyView.btnPm25Values.X = bodyView.btnPm25Icon.Right + Application.GetRealWidth(4);
                }
            });
        }
        /// <summary>
        /// 更新功能列表主页
        /// </summary>
        public static void RefreshFunctionView()
@@ -236,25 +90,6 @@
                bodyView.LoadDeviceFunctionControlZone();
            }
        }
        /// <summary>
        /// 更新功能组控主页
        /// </summary>
        public static void RefreshGroupControlView()
        {
            if (bodyView != null)
            {
                if (FunctionList.List.groupControls.Count == 0)
                {
                    bodyView.loadNavView();
                    bodyView.contentView.PageIndex = 0;
                }
                bodyView.LoadGroupControlFunctionControlZone();
            }
        }
        /// <summary>
        /// 更新连接状态图标
@@ -309,14 +144,6 @@
            btn.MouseUpEventHandler += (sender, e) =>
            {
                function.collect = false;
                if (SPK.MusicSpkList().Contains(function.spk))//处理音乐主从关系
                {
                    //if ((function as Music.A31MusicModel).ServerClientType == 1)
                    //{
                    //    (function as Music.A31MusicModel).MainPlayCollection = false;
                    //    Music.A31MusicModel.Save();
                    //}
                }
                string msg = function.name + Language.StringByID(StringId.CollectionCancelled);
                LoadDeviceFunctionControlZone();
                function.CollectFunction();
@@ -336,19 +163,6 @@
                scene.CollectScene();
                new PublicAssmebly().TipMsgAutoClose(msg, true);
            };
        }
        /// <summary>
        /// 修改显示的功能类型
        /// 设备功能/场景功能
        /// </summary>
        void LoadEvent_ChangeShowedFunctionType()
        {
            if (DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl && FunctionList.List.groupControls.Count>0)
            {
            }
        }
        /// <summary>
@@ -386,52 +200,6 @@
                                        state = function.trait_on_off.curValue.ToString() == "on";
                                    }
                                }
                                else if (function.spk == SPK.SenesorMegahealth || function.spk == SPK.SensorMmvPose)
                                {
                                    var tempStatus = function.attributes.Find((sta) => sta.key == FunctionAttributeKey.TargetStatus);
                                    if (tempStatus != null)
                                    {
                                        switch (tempStatus.state)
                                        {//0空,1走,2跑,3坐,4跌倒,5站
                                            case "0":
                                                state = false;
                                                break;
                                            case "1":
                                                state = true;
                                                break;
                                            case "2":
                                                if (function.extSet.labModel)
                                                {
                                                    state = true;
                                                }
                                                break;
                                            case "3":
                                                if (function.extSet.labModel)
                                                {
                                                    state = true;
                                                }
                                                break;
                                            case "4":
                                                state = true;
                                                break;
                                            case "5":
                                                if (function.extSet.labModel)
                                                {
                                                    state = true;
                                                }
                                                break;
                                        }
                                    }
                                }
                                else if(function.spk == SPK.SensorHelp)
                                {
                                    var tempStatus = function.attributes.Find((sta) => sta.key == FunctionAttributeKey.AlarmStatus);
                                    if(tempStatus != null)
                                    {
                                        state = tempStatus.curValue.ToString() == "alarm";
                                    }
                                }
                                else
                                {
                                    state = function.trait_on_off.curValue.ToString() == "on";
@@ -444,23 +212,9 @@
                                        btn.IsSelected = state;
                                        if (btn.Tag != null && btn.Tag.ToString() == "state")
                                        {
                                            if (SPK.MusicSpkList().Contains(function.spk))
                                            if (function.spk != SPK.LightSwitch)
                                            {
                                                btn.Text =function.GetAttrState("song_name");
                                            }
                                            else
                                            {
                                                if (function.spk != SPK.LightSwitch)
                                                {
                                                    if (function.spk == SPK.SensorHelp)
                                                    {
                                                        btn.TextID = StringId.InAlarming;
                                                    }
                                                    else
                                                    {
                                                        btn.Text = function.lastState;
                                                    }
                                                }
                                                btn.Text = function.lastState;
                                            }
                                        }
                                    }
@@ -497,40 +251,6 @@
                new PublicAssmebly().TipMsgAutoClose(msg, true);
                Control.Ins.ControlScene(scene);
                scene.SceneCountDown(btnShowDelay);
                //new System.Threading.Thread(() => {
                //    int time = Convert.ToInt32(scene.delay);
                //    if (time > 0)
                //    {
                //        while (time > 0)
                //        {
                //            Application.RunOnMainThread(() =>
                //            {
                //                if (time / 60 > 1)
                //                {
                //                    btnShowDelay.Text = (time / 60).ToString() + "min";
                //                }
                //                else
                //                {
                //                    btnShowDelay.Text = (time--).ToString() + "s";
                //                }
                //            });
                //            if (time / 60 > 1)
                //            {
                //                System.Threading.Thread.Sleep(time / 60 * 60000);
                //            }
                //            else
                //            {
                //                System.Threading.Thread.Sleep(1000);
                //            }
                //        }
                //        Application.RunOnMainThread(() =>
                //        {
                //            btnShowDelay.Text = "";
                //        });
                //    }
                //})
                //{ IsBackground = true, Priority = System.Threading.ThreadPriority.BelowNormal }.Start();
            };
            btnCoverd.MouseUpEventHandler = eventHandler;
            btnName.MouseUpEventHandler = eventHandler;
@@ -559,13 +279,6 @@
                btnSwitch.IsSelected = !btnSwitch.IsSelected;
                new System.Threading.Thread(() =>
                {
                    if(SPK.NotStatusSpkList.Contains(function.spk))
                    {
                        System.Threading.Thread.Sleep(1000);
                        Application.RunOnMainThread(() => {
                            btnSwitch.IsSelected = !btnSwitch.IsSelected;
                        });
                    }
                    function.trait_on_off.curValue = btnSwitch.IsSelected ? "on" : "off";
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    if (function.spk == SPK.LightDimming || function.spk == SPK.LightRGB)
@@ -582,19 +295,6 @@
                        d.Add(FunctionAttributeKey.FadeTime, function.GetAttrState(FunctionAttributeKey.FadeTime));
                        Control.Ins.SendWriteCommand(function, d);
                    }
                    //else if (function.spk == SPK.PanelSocket)//去掉,统一处理总控
                    //{
                    //    if (function.attributes.Find((obj) => obj.key == "on_off_usb") != null)
                    //    {
                    //        d.Add("on_off_usb", function.trait_on_off.curValue.ToString());
                    //    }
                    //    Control.Ins.SendWriteCommand(function, d);
                    //}
                    else if (function.spk == SPK.GroupControl)
                    {
                        d.Add("on_off", function.trait_on_off.curValue.ToString());
                        (function as GroupControl).Control(d);
                    }
                    else
                    {
                        d.Add("on_off", function.trait_on_off.curValue.ToString());
@@ -606,68 +306,12 @@
        }
        /// <summary>
        /// 加载电视控制事件
        /// </summary>
        /// <param name="function"></param>
        /// <param name="btnSwitch"></param>
        void LoadEvent_ControlTV(Function function, Button btnSwitch)
        {
            btnSwitch.MouseUpEventHandler = (sender, e) =>
            {
                if (!function.isOnline())//离线不允许操作
                {
                    new Tip()
                    {
                        CloseTime = 1,
                        Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
                        Direction = AMPopTipDirection.None,
                    }.Show(MainPage.BaseView);
                    return;
                }
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    btnSwitch.IsSelected = !btnSwitch.IsSelected;
                    new System.Threading.Thread(() =>
                    {
                        if (SPK.NotStatusSpkList.Contains(function.spk))
                        {
                            System.Threading.Thread.Sleep(2000);
                            Application.RunOnMainThread(() =>
                            {
                                btnSwitch.IsSelected = !btnSwitch.IsSelected;
                            });
                        }
                        Dictionary<string, string> d = new Dictionary<string, string>();
                        d.Add("on_off", "");
                        Control.Ins.SendWriteCommand(function, d);
                    })
                    { IsBackground = true }.Start();
                }
                else
                {
                    new TV().ControlTV(InfraredCode_TV.Power, function);
                }
            };
        }
        /// <summary>
        /// 加载窗帘控制事件
        /// </summary>
        void LoadEvent_ControlCurtain(Function curtain, Button btnClose, Button btnOpen)
        {
            btnClose.MouseUpEventHandler = (sender, e) =>
            {
                //if (!curtain.isOnline())//离线不允许操作
                //{
                //    new Tip()
                //    {
                //        CloseTime = 1,
                //        Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
                //        Direction = AMPopTipDirection.None,
                //    }.Show(MainPage.BaseView);
                //    return;
                //}
                btnClose.IsSelected = true;
                curtain.trait_on_off.curValue = "off";
                curtain.SetAttrState(FunctionAttributeKey.Percent, 0);
@@ -678,16 +322,6 @@
            btnOpen.MouseUpEventHandler = (sender, e) =>
            {
                //if (!curtain.isOnline())//离线不允许操作
                //{
                //    new Tip()
                //    {
                //        CloseTime = 1,
                //        Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
                //        Direction = AMPopTipDirection.None,
                //    }.Show(MainPage.BaseView);
                //    return;
                //}
                btnOpen.IsSelected = true;
                curtain.trait_on_off.curValue = "on";
                curtain.SetAttrState(FunctionAttributeKey.Percent, 100);