黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
ZigbeeApp/Shared/Phone/Device/Logic/Method.cs
@@ -21,7 +21,7 @@
        /// <param name="device">Device.</param>
        public static void RoomNmae(Button button, CommonDevice device)
        {
            button.Text = UserCenter.HdlRoomLogic.Current.GetRoomNameByDevice(device);
            button.Text = HdlRoomLogic.Current.GetRoomNameByDevice(device);
        }
        /// <summary>
        /// 返回楼层所有的房间的列表
@@ -32,7 +32,7 @@
        public static List<Common.Room> GetRoomList(string type, string floorId = null)
        {
            var list = new List<Common.Room>();
            var listAllRoom = UserCenter.HdlRoomLogic.Current.GetAllListRooms();
            var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
            for (int i = 0; i < listAllRoom.Count; i++)
            {
                if (type == "action_logicscene" || type == "action_lockscene")
@@ -46,7 +46,7 @@
                {
                    ///区分出输入条件和输出目标设备
                    var listdevicetype = GetDevice(type);
                    var listdevice = GetDeviceUIList(listAllRoom[i], listdevicetype);
                    var listdevice = GetDeviceUIList(listAllRoom[i], listdevicetype, type);
                    if (listdevice.Count == 0)
                    {
                        ///过滤掉没有设备的房间
@@ -68,13 +68,14 @@
        /// </summary>
        /// <param name="room">当前房间</param>
        /// <param name="deviceTypelist">设备类型</param>
        ///  /// <param name="type">逻辑类型</param>
        /// <returns></returns>
        public static List<CommonDevice> GetDeviceUIList(Common.Room room, List<DeviceType> deviceTypelist)
        public static List<CommonDevice> GetDeviceUIList(Common.Room room, List<DeviceType> deviceTypelist,string type)
        {
            var deviceUIlist = new List<CommonDevice>();
            foreach (var deviceKey in room.ListDevice)
            {
                var device = LocalDevice.Current.GetDevice(deviceKey);
                var device = HdlDeviceCommonLogic.Current.GetDevice(deviceKey);
                if (device == null)
                {
                    continue;
@@ -84,6 +85,32 @@
                    //过滤掉不支持的设备
                    continue;
                }
                if (device.Type == DeviceType.DoorLock)
                {
                    var myInfo = HdlDeviceCommonLogic.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
                    if (myInfo.ConcreteType == DeviceConcreteType.IntelligentLocks_Sone)
                    {
                        //暂时不支持S-one门锁;
                        //过滤掉不支持S-one门锁设备;
                        continue;
                    }
                }
                if (type == "condition_mould")
                {
                    if (device.Type == DeviceType.IASZone)
                    {
                        if (device.IasDeviceType != 13)
                        {//自动化模板只支持红外传感器
                            continue;
                        }
                        if (device.ModelIdentifier == "MSPIRB-ZB.10")
                        {
                            //自动化模板不支持光照度
                            continue;
                        }
                    }
                }
                deviceUIlist.Add(device);
            }
            return deviceUIlist;
@@ -91,47 +118,53 @@
        /// <summary>
        /// 排列所有设备类型的列表
        /// </summary>
        /// <param name="type">判断字符串</param>
        /// <param name="devicelist">设备列表</param>
        /// <returns></returns>
        public static List<string> GetDeviceTypeList(string type, List<CommonDevice> devicelist)
        public static List<string> GetDeviceTypeList(List<CommonDevice> devicelist)
        {
            List<string> devicetypelist = new List<string>();
            devicetypelist.Clear();
            var lightjosn = devicelist.Find((device) => device.Type == DeviceType.ColorDimmableLight || device.Type == DeviceType.OnOffOutput);
            var lightjosn = devicelist.Find((device) => device.Type == DeviceType.DimmableLight || device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.ColorTemperatureLight);
            if (lightjosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Lights));
            }
            var iASZonejosn = devicelist.Find((device) => device.Type == DeviceType.IASZone || device.Type == DeviceType.TemperatureSensor);
            if (iASZonejosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.sensor));
            }
            var onOffSwitchjson = devicelist.Find((device) => device.Type == DeviceType.OnOffSwitch);
            if (onOffSwitchjson != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.OnOffSwitch));
            }
            var doorLock = devicelist.Find((device) => device.Type == DeviceType.DoorLock);
            if (doorLock != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.doorLock));
            }
            var curtainjosn = devicelist.Find((device) => device.Type == DeviceType.WindowCoveringDevice);
            if (curtainjosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Curtains));
            }
            var ac = devicelist.Find((device) => device.Type == DeviceType.Thermostat);
            if (ac != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.AC));
            }
            var onOffSwitchjson = devicelist.Find((device) => device.Type == DeviceType.OnOffSwitch);
            if (onOffSwitchjson != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.OnOffSwitch));
            }
            var doorLock = devicelist.Find((device) => device.Type == DeviceType.DoorLock);
            if (doorLock != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.doorLock));
            }
            var airSwitch = devicelist.Find((device) => device.Type == DeviceType.AirSwitch);
            if (airSwitch != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Airswitch));
            }
            var iASZonejosn = devicelist.Find((device) => device.Type == DeviceType.IASZone || device.Type == DeviceType.TemperatureSensor);
            if (iASZonejosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.sensor));
            }
            return devicetypelist;
@@ -150,6 +183,7 @@
            {
                DeviceTypeList.Add(DeviceType.OnOffOutput);//0x0101十进制257
                DeviceTypeList.Add(DeviceType.DimmableLight);
                DeviceTypeList.Add(DeviceType.ColorTemperatureLight);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Curtains))
            {
@@ -244,8 +278,17 @@
                        {
                            break;
                        }
                        patm = $"ZigeeLogic/sensor{iASZonedevice.IasDeviceType}.png";
                        selectedpatm = $"ZigeeLogic/selectedsensor{iASZonedevice.IasDeviceType}.png";
                        if (device.ModelIdentifier == "MSPIRB-ZB.10")
                        {
                            patm = $"ZigeeLogic/sensor541.png";
                            selectedpatm = $"ZigeeLogic/selectedsensor541.png";
                        }
                        else
                        {
                            patm = $"ZigeeLogic/sensor{iASZonedevice.IasDeviceType}.png";
                            selectedpatm = $"ZigeeLogic/selectedsensor{iASZonedevice.IasDeviceType}.png";
                        }
                    }
                    break;
                case DeviceType.TemperatureSensor:
@@ -300,6 +343,12 @@
                        selectedpatm = "ZigeeLogic/selectedairswitch.png";
                    }
                    break;
                case DeviceType.ColorTemperatureLight:
                    {
                        patm = "ZigeeLogic/nightLight.png";
                        selectedpatm = "ZigeeLogic/nightLightSelected.png";
                    }
                    break;
            }
            button.UnSelectedImagePath = patm;
            button.SelectedImagePath = selectedpatm;
@@ -326,12 +375,17 @@
                    }
                    break;
                case "action_logic":
                    { //自动化支持的目标设备
                    {
                        //自动化支持的目标设备
                        deviceTypeList.Add(DeviceType.OnOffOutput);
                        deviceTypeList.Add(DeviceType.DimmableLight);
                        deviceTypeList.Add(DeviceType.WindowCoveringDevice);
                        deviceTypeList.Add(DeviceType.Thermostat);
                        deviceTypeList.Add(DeviceType.AirSwitch);
                        deviceTypeList.Add(DeviceType.ColorTemperatureLight);
                        ///门锁特殊
                       // deviceTypeList.Add(DeviceType.DoorLock);
                    }
                    break;
                case "condition_mould":
@@ -352,6 +406,9 @@
                        deviceTypeList.Add(DeviceType.WindowCoveringDevice);
                        deviceTypeList.Add(DeviceType.Thermostat);
                        deviceTypeList.Add(DeviceType.AirSwitch);
                        deviceTypeList.Add(DeviceType.ColorTemperatureLight);
                        ///门锁特殊
                      // deviceTypeList.Add(DeviceType.DoorLock);
                    }
                    break;
@@ -537,7 +594,9 @@
                    }; break;
                case 5:
                    {
                        string len = "", text = "";
                        string len = "";
                         string   text = "";
                        string weekStr = Language.StringByID(MyInternationalizationString.week1);
                        List<int> listvalueInt = new List<int>();
                        listvalueInt.Clear();
                        var maxvalue = Convert.ToString(currentLogic.TimeAttribute.WeekDay, 2);
@@ -553,44 +612,36 @@
                            if (strvalue == "1")
                            {
                                listvalueInt.Add(j + 1);
                                if ((j + 1) == 1)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.mon1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.mon) + ",";
                                switch ((j + 1)) {
                                    case 1: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.mon1) + ",";
                                        }
                                        break;
                                    case 2: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.tue1) + ",";
                                        }
                                        break;
                                    case 3: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.wed1) + ",";
                                        }
                                        break;
                                    case 4: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.thu1) + ",";
                                        }
                                        break;
                                    case 5: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.frl1) + ",";
                                        }
                                        break;
                                    case 6: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.sat1) + ",";
                                        }
                                        break;
                                    case 7: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.sun1) + ",";
                                        }
                                        break;
                                }
                                else if ((j + 1) == 2)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.tue1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.tue) + ",";
                                }
                                else if ((j + 1) == 3)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.wed1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.wed) + ",";
                                }
                                else if ((j + 1) == 4)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.thu1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.thu) + ",";
                                }
                                else if ((j + 1) == 5)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.frl1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.frl) + ",";
                                }
                                else if ((j + 1) == 6)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.sat1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.sat) + ",";
                                }
                                else if ((j + 1) == 7)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.sun1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.sun) + ",";
                                }
                            }
                        }
@@ -611,8 +662,7 @@
                        //{
                        //    btndisplaycycle.Text = Language.StringByID(MyInternationalizationString.week1) + text.Replace(Language.StringByID(MyInternationalizationString.week1), "").TrimEnd(',');
                        //}
                        button.Text = Language.StringByID(MyInternationalizationString.week1) + text.Replace(Language.StringByID(MyInternationalizationString.week1), "").TrimEnd(',');
                        //btndisplaycycle.Text = text.TrimEnd(',');
                        button.Text = weekStr + text.Replace(weekStr, "").TrimEnd(',');
                    }; break;
            }
@@ -649,6 +699,7 @@
            custompushview.iconBtn.Visible = true;
            custompushview.iconBtn.UnSelectedImagePath = "ZigeeLogic/next.png";
            custompushview.titleBtn.TextID = MyInternationalizationString.custompush;
            custompushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
            middle.AddChidren(custompushview.AddDeviceView());
            EventHandler<MouseEventArgs> customclick = (sender, e) =>
@@ -669,6 +720,7 @@
                    LogicView.IfString.Tag = true;
                    custompushview.frameLayout.Height = Application.GetRealHeight(160);
                    Common.Logic.CurrentLogic.LogicIsCustomPushText = 1;
                    pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor;
                }
                else
@@ -676,8 +728,13 @@
                    LogicView.IfString.Tag = false;
                    custompushview.frameLayout.Height = Application.GetRealHeight(0);
                    Common.Logic.CurrentLogic.LogicIsCustomPushText = 0;
                    pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
                }
                Send.Zj(LogicView.IfString.Tag, Common.Logic.CurrentLogic);
                if (!Config.Instance.Home.IsVirtually)
                {
                    Send.Zj(LogicView.IfString.Tag, Common.Logic.CurrentLogic);
                }
            };
            if (Common.Logic.CurrentLogic.LogicIsCustomPushText == 0)
@@ -685,12 +742,14 @@
                LogicView.IfString.Tag = false;
                pushview.switchBtn.IsSelected = false;
                custompushview.frameLayout.Height = Application.GetRealHeight(0);
                pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
            }
            else
            {
                LogicView.IfString.Tag = true;
                pushview.switchBtn.IsSelected = true;
                custompushview.frameLayout.Height = Application.GetRealHeight(160);
                pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor;
            }
        }
        /// <summary>
@@ -702,9 +761,19 @@
        /// <param name="CurrentLogic">当前逻辑</param>
        public async static void SaveLogic(string if_logic, string name, bool tag, Common.Logic CurrentLogic)
        {
            if (CurrentLogic.Conditions.Count == 0 || CurrentLogic.Actions.Count == 0)
            {
                var alert = new ShowMsgControl(ShowMsgType.Normal,
                  Language.StringByID(MyInternationalizationString.addnull),
                  Language.StringByID(MyInternationalizationString.confrim));
                alert.Show();
                return;
            }
            if (string.IsNullOrEmpty(name))
            {
                var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Normal,
                var alert = new ShowMsgControl(ShowMsgType.Normal,
                  Language.StringByID(MyInternationalizationString.PleaseEnterLogicName),
                  Language.StringByID(MyInternationalizationString.confrim));
                alert.Show();
@@ -722,28 +791,94 @@
            bool succeed = false;
            //判断是新添加逻辑(默认0)还是修改逻辑
            CommonPage.Loading.Start();
            if (CurrentLogic.LogicId == 0)
            if (Config.Instance.Home.IsVirtually)
            {
                //发送添加逻辑命令
                var logicifon = await Send.AddModifyLogic(CurrentLogic);
                if (logicifon != null && logicifon.LogicId != 0)
                if (Common.Logic.LogicList.Count == 0)
                {
                    succeed = true;
                    CurrentLogic.LogicId = logicifon.LogicId;
                    CurrentLogic.LogicId = 1;
                    Common.Logic.LogicList.Add(CurrentLogic);
                    if (tag)
                    {
                        Send.Zj(tag, CurrentLogic);
                    }
                }
                if (CurrentLogic.LogicId == 0)
                {
                    bool d = false;
                    for (int i = 1; i < 50; i++)
                    {
                        for (int j = 0; j < Common.Logic.LogicList.Count; j++)
                        {
                            if (i != Common.Logic.LogicList[j].LogicId)
                            {
                                CurrentLogic.LogicId = i;
                                Common.Logic.LogicList.Add(CurrentLogic);
                                d = true;
                                break;
                            }
                        }
                        if (d)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < Common.Logic.LogicList.Count; j++)
                    {
                        if (CurrentLogic.LogicId == Common.Logic.LogicList[j].LogicId)
                        {
                            Common.Logic.LogicList.RemoveAt(j);
                            Common.Logic.LogicList.Insert(j,CurrentLogic);
                            break;
                        }
                    }
                }
                //自动化逻辑列表
            }
            else
            {
                //发送修改逻辑命令;
                //修改命令不需要等待回复;
                Send.AddModifyLogic(CurrentLogic);
                //编辑默认成功(不考虑网络情况);
                succeed = true;
                if (CurrentLogic.LogicId == 0)
                {
                    //发送添加逻辑命令
                    var logicifon = await Send.AddModifyLogic(CurrentLogic);
                    if (logicifon != null && logicifon.LogicId != 0)
                    {
                        succeed = true;
                        CurrentLogic.LogicId = logicifon.LogicId;
                        if (LogicView.IfString._Logic == if_logic || LogicView.IfString._SoneLogic == if_logic)
                        {
                            //自动化逻辑列表
                            Common.Logic.LogicList.Add(CurrentLogic);
                        }
                        if (LogicView.IfString._LockLogic == if_logic)
                        {
                            //门锁联动事件逻辑列表
                            Common.Logic.LockLogicList.Add(CurrentLogic);
                        }
                        if (LogicView.IfString._SoneLogic == if_logic)
                        {
                            //Sone门锁常开模式逻辑列表
                            Common.Logic.SoneLogicList.Add(CurrentLogic);
                        }
                        if (tag)
                        {
                            Send.Zj(tag, CurrentLogic);
                        }
                    }
                }
                else
                {
                    //发送修改逻辑命令;
                    //修改命令不需要等待回复;
                    Send.AddModifyLogic(CurrentLogic);
                    //编辑默认成功(不考虑网络情况);
                    succeed = true;
                }
            }
            CommonPage.Loading.Hide();
@@ -755,20 +890,109 @@
                //TipView("添加自动化失败");
                //return;
            }
            UserView.HomePage.Instance.RemoveViewByTag("Logic");
            UserView.HomePage.Instance.RemoveViewByTag("Logic");//移除所有标记Logic界面
            if (LogicView.IfString._Logic == if_logic)
            {
                Category.Category.instance?.RefreshBodyView();
                //查询-当前逻辑-是否添加地理位置作为条件
                var exist = Common.Logic.CurrentLogic.Conditions.Find((obj) => obj["Type"] == "7");
                if (exist==null)
                {
                    bool if_type = false;
                    //查询-逻辑列表-是否添加过地理位置作为条件
                    for (int a = 0; a < Common.Logic.LogicList.Count; a++)
                    {
                        var logic = Common.Logic.LogicList[a];
                        var exist_logic = logic.Conditions.Find((obj) => obj["Type"] == "7");
                        if (exist_logic != null)
                        {
                            //是否存在地理位置条件
                            if_type = true;
                            //退出for循环
                            break;
                        }
                    }
                    if (if_type)
                    {
                        //查询之前状态是否已经开启GPS服务(以本地存储状态为主 0:没开启; 1:开启)
                        if (Send.If_Exist == "0")
                        {
                            //开启GPS服务
                            Application.StartGPSLocationService();
                            //保存GPS服务开启状态
                            Send.SaveLocalFile(Config.Instance.HomeId + "_GPS_File", "1");
                        }
                    }
                    else
                    {
                        //如果找不到地理位置作为条件的话,关闭GPS服务(减少耗电)
                        if (Send.If_Exist == "1")
                        {
                            //关闭GPS服务
                            Application.StopGPSLocationService();
                            //保存GPS服务关闭状态
                            Send.SaveLocalFile(Config.Instance.HomeId + "_GPS_File", "0");
                        }
                    }
                }
                else
                {
                    //查询之前状态是否已经开启GPS服务(以本地存储状态为主 0:没开启; 1:开启)
                    if (Send.If_Exist == "0")
                    {
                        //开启GPS服务
                        Application.StartGPSLocationService();
                        //保存GPS服务开启状态
                        Send.SaveLocalFile(Config.Instance.HomeId + "_GPS_File", "1");
                    }
                }
                //只刷新分类-自动化上下滑动view;
                Phone.Category.CategoryMainForm.instance?.RefreshBodyView();
                // Category.Category.instance?.RefreshBodyView();
            }
            else if (LogicView.IfString._LockLogic == if_logic)
            {
                //跳到门锁联动事件列表界面
                UserView.HomePage.Instance.RemoveViewByTag("LockListView");//移除所有标记LockListView界面
                var doorLockLogicList = new DoorLockLogic.LockLogicList();
                UserView.HomePage.Instance.AddChidren(doorLockLogicList);
                UserView.HomePage.Instance.PageIndex += 1;
                doorLockLogicList.Show();
            }
            else if (LogicView.IfString._SoneLogic == if_logic)
            {
                //跳到Sone门锁联动事件列表界面
                //UserView.HomePage.Instance.RemoveViewByTag("SoneLogic");//移除所有标记LockListView界面
                //var soneLogicList = new SoneLogicList();
                //UserView.HomePage.Instance.AddChidren(soneLogicList);
                //UserView.HomePage.Instance.PageIndex += 1;
                //soneLogicList.Show();
                SoneLogicList.soneLogicList?.RefreshView();
            }
        }
        /// <summary>
        /// 跳入输出目标功能界面的方法
        /// </summary>
        /// <param name="str1">设备界面识别字符串</param>
        /// <param name="str2">场景界面识别字符串</param>
        public static void View(string str1, string str2)
        {
            var deviceTarget = new DeviceTarget();
            UserView.HomePage.Instance.AddChidren(deviceTarget);
            UserView.HomePage.Instance.PageIndex += 1;
            deviceTarget.Show(str1, str2);
        }
        /// <summary>
        /// 界面高度
        /// </summary>
        public static int H = 1922;
    }
}