wei
2021-03-03 d4811b7d34b45ff6b21b97f11da128b5572ec526
HDL_ON/Entity/FunctionList.cs
old mode 100755 new mode 100644
@@ -75,12 +75,22 @@
                {
                    weepRobots = new List<WeepRobot>();
                }
                if(waterValveList == null)
                {
                    waterValveList = new List<Function>();
                }
                if(clothesHangerList == null)
                {
                    clothesHangerList = new List<Function>();
                }
                var list = new List<Function>();
                list.AddRange(fans);
                list.AddRange(switchSockets);
                list.AddRange(tVs);
                list.AddRange(airCleaners);
                list.AddRange(weepRobots);
                list.AddRange(waterValveList);
                list.AddRange(clothesHangerList);
                return list;
            }
        }
@@ -104,6 +114,14 @@
        /// 扫地机器人列表
        /// </summary>
        public List<WeepRobot> weepRobots = new List<WeepRobot>();
        /// <summary>
        /// 水阀列表
        /// </summary>
        public List<Function> waterValveList = new List<Function>();
        /// <summary>
        /// 凉霸列表
        /// </summary>
        public List<Function> clothesHangerList = new List<Function>();
        #endregion
        /// <summary>
@@ -140,6 +158,7 @@
        /// <param name="filePath"></param>
        public void IniFunctionList(string filePath)
        {
            // todo 增加设备,增加功能进功能列表
            if (filePath.StartsWith("FunctionData_"))
            {
                var functionDataBytes = Common.FileUtlis.Files.ReadFile(filePath);
@@ -147,14 +166,9 @@
                var tempFunction = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(functionDataString);
                if (tempFunction == null)
                {
                    Common.FileUtlis.Files.DeleteFile(filePath);
                    FileUtlis.Files.DeleteFile(filePath);
                    return;
                }
                if (tempFunction.DeleteSign)
                {
                    //todo 删除云端数据 20201203--App不能删除功能数据
                }
                else
                {
                    switch (tempFunction.spk)
                    {
@@ -224,12 +238,23 @@
                            List.weepRobots.Add(tuyaWeepRobot);
                            deviceFunctionList.Add(tuyaWeepRobot);
                            break;
                        case SPK.ElectricTuyaWaterValve:
                            var tuyaWaterValve = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(functionDataString);
                            List.waterValveList.Add(tuyaWaterValve);
                            deviceFunctionList.Add(tuyaWaterValve);
                            break;
                        case SPK.SensorSmoke:
                        case SPK.SensorWater:
                        case SPK.SensorGas:
                        case SPK.SensorDoorWindow:
                        case SPK.SensorPir:
                            var ser = Newtonsoft.Json.JsonConvert.DeserializeObject<Sensor>(functionDataString);
                            List.sensorsArm.Add(ser);
                            deviceFunctionList.Add(ser);
                            break;
                        case SPK.ClothesHanger:
                            var ch = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(functionDataString);
                            List.clothesHangerList.Add(ch);
                            deviceFunctionList.Add(ch);
                            break;
                    }
                }
@@ -246,7 +271,7 @@
        /// <summary>
        /// 获取设备功能列表
        /// </summary>
        public List<Function> GetDeviceFunctionList()
        public List<Function> GetDeviceFunctionList(SPK.BrandType brandType = SPK.BrandType.All)
        {
            if (deviceFunctionList == null || deviceFunctionList.Count == 0)
            {
@@ -259,17 +284,50 @@
                deviceFunctionList.AddRange(sensorsEnvironmentalScience);
                deviceFunctionList.AddRange(sensorsArm);
                deviceFunctionList.AddRange(UI.Music.A31MusicModel.A31MusicModelList);
                try
                {
                    deviceFunctionList = deviceFunctionList.OrderByDescending(o => o.controlCounter).ToList();
                }
                catch (Exception ex)
                {
                    MainPage.Log($"设备功能排序异常:{ex.Message}");
                }
            }
            try
            List<Function> resultFunctions = new List<Function>();
            if (brandType == SPK.BrandType.All)
            {
                deviceFunctionList = deviceFunctionList.OrderByDescending(o => o.controlCounter).ToList();
            }
            catch (Exception ex)
            {
                MainPage.Log($"设备功能排序异常:{ex.Message}");
            else
            {
                switch (brandType)
                {
                    case SPK.BrandType.Hdl:
                        foreach (var function in deviceFunctionList)
                        {
                            if (!SPK.Get3tySpk(SPK.BrandType.All3tyBrand).Contains(function.spk))
                            {
                                resultFunctions.Add(function);
                            }
                        }
                        break;
                    case SPK.BrandType.Tuya:
                        foreach (var function in deviceFunctionList)
                        {
                            if (SPK.Get3tySpk(SPK.BrandType.Tuya).Contains(function.spk))
                            {
                                resultFunctions.Add(function);
                            }
                        }
                        break;
                }
                return resultFunctions;
            }
            return deviceFunctionList;
        }
        /// <summary>
        /// 清空设备功能列表
        /// </summary>
@@ -279,12 +337,19 @@
            List.lights = new List<Light>();
            List.curtains = new List<Curtain>();
            List.floorHeatings = new List<FloorHeating>();
            List.tVs = new List<TV>();
            List.switchSockets = new List<SwitchSocket>();
            List.fans = new List<Fan>();
            List.sensorsEnvironmentalScience = new List<Sensor>();
            #region 家电
            List.fans = new List<Fan>();
            List.switchSockets = new List<SwitchSocket>();
            List.tVs = new List<TV>();
            List.airCleaners = new List<AirCleaner>();
            List.weepRobots = new List<WeepRobot>();
            List.waterValveList = new List<Function>();
            List.clothesHangerList = new List<Function>();
            #endregion
            List.scenes = new List<Scene>();
            List.deviceFunctionList = null;
            List.deviceFunctionList = new List<Function>();
            _FunctionList = null;
        }
@@ -505,7 +570,26 @@
                    List.tVs.Remove(List.tVs.Find((obj) => obj.deviceId == delTemp.deviceId));
                    break;
                case SPK.ElectricFan:
                case SPK.ElectricTuyaFan:
                    List.fans.Remove(List.fans.Find((obj) => obj.deviceId == delTemp.deviceId));
                    break;
                case SPK.ElectricTuyaAirCleaner:
                    List.airCleaners.Remove(List.airCleaners.Find((obj) => obj.deviceId == delTemp.deviceId));
                    break;
                case SPK.ElectricTuyaWaterValve:
                    List.waterValveList.Remove(List.waterValveList.Find((obj) => obj.deviceId == delTemp.deviceId));
                    break;
                case SPK.ElectricTuyaWeepRobot:
                    List.weepRobots.Remove(List.weepRobots.Find((obj) => obj.deviceId == delTemp.deviceId));
                    break;
                case SPK.ClothesHanger:
                    List.clothesHangerList.Remove(List.clothesHangerList.Find((obj) => obj.deviceId == delTemp.deviceId));
                    break;
                case SPK.SensorSmoke:
                case SPK.SensorWater:
                case SPK.SensorDoorWindow:
                case SPK.SensorPir:
                    List.sensorsArm.Remove(List.sensorsArm.Find((obj)=>obj.deviceId == delTemp.deviceId));
                    break;
            }
            var removeTemp = deviceFunctionList.Find((obj) => obj.deviceId == delTemp.deviceId);
@@ -517,6 +601,33 @@
        }
        bool lockReadFunctionStatus = false;
        /// <summary>
        /// 读取第三方设备状态
        /// </summary>
        public void Read3tyFunctionStatus()
        {
            //读取涂鸦设备状态
            if (GetDeviceFunctionList(SPK.BrandType.Tuya).Count > 0)
            {
                var page = new List<string>();
                int count = 0;
                foreach (var function in GetDeviceFunctionList(SPK.BrandType.Tuya))
                {
                    page.Add(function.deviceId);
                    count++;
                    if (count > 9)
                    {
                        DriverLayer.Control.Ins.ReadFunctionsInfo(page);
                        page.Clear();
                        count = 0;
                    }
                }
                DriverLayer.Control.Ins.ReadFunctionsInfo(page);
            }
        }
        /// <summary>
        /// 读取全部功能的状态
        /// </summary>
@@ -538,12 +649,38 @@
                lockReadFunctionStatus = true;
                try
                {
                    if (DriverLayer.Control.Ins.IsRemote)
                    Read3tyFunctionStatus();
                    if(DriverLayer.Control.Ins.GatewayOnline_Local)
                    {
                        foreach (var function in GetDeviceFunctionList(SPK.BrandType.Hdl))
                        {
                            switch (function.Spk_Prefix)
                            {
                                case FunctionCategory.Music:
                                case FunctionCategory.DryContact:
                                    continue;
                            }
                            DriverLayer.Control.Ins.SendReadCommand(function);
                            //switch (function.Spk_Prefix)
                            //{
                            //    case FunctionCategory.Light:
                            //    case FunctionCategory.Electric:
                            //    case FunctionCategory.Curtain:
                            //    case FunctionCategory.AC:
                            //    case FunctionCategory.FloorHeat:
                            //    case FunctionCategory.Sensor:
                            //        DriverLayer.Control.Ins.SendReadCommand(function);
                            //        break;
                            //}
                        }
                    }
                    else
                    {
                        var page = new List<string>();
                        int count = 0;
                        foreach (var function in GetDeviceFunctionList())
                        foreach (var function in GetDeviceFunctionList(SPK.BrandType.Hdl))
                        {
                            page.Add(function.deviceId);
                            count++;
@@ -556,22 +693,6 @@
                        }
                        DriverLayer.Control.Ins.SendApiReadCommand(page);
                    }
                    else
                    {
                        foreach (var function in GetDeviceFunctionList())
                        {
                            switch (function.Spk_Prefix)
                            {
                                case FunctionCategory.Light:
                                case FunctionCategory.Electric:
                                case FunctionCategory.Curtain:
                                case FunctionCategory.AC:
                                case FunctionCategory.FloorHeat:
                                    DriverLayer.Control.Ins.SendReadCommand(function);
                                    break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
@@ -582,6 +703,8 @@
                    lockReadFunctionStatus = false;
                    MainPage.Log($"结束--读取");
                }
            })
            { IsBackground = true }.Start();
        }