From b1ced15165c0c120483f821079fc23c63d455e8e Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 05 三月 2021 17:54:49 +0800
Subject: [PATCH] 2021-3-5-1

---
 HDL_ON/DAL/Server/NewAPI.cs                             |    6 
 HDL_ON/UI/UI2/4-PersonalCenter/PersonalCenterPageBLL.cs |   15 +
 HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirMain.cs     |  126 ++--------
 HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Pir.cs         |   40 +--
 .vs/HDL_APP_Project/xs/UserPrefs.xml                    |   41 ++-
 HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs     |   24 -
 HDL_ON/DAL/Mqtt/MqttClient.cs                           |    9 
 HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs   |  103 +++++++-
 HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs      |  258 ++++++++++++++++++++---
 9 files changed, 399 insertions(+), 223 deletions(-)

diff --git a/.vs/HDL_APP_Project/xs/UserPrefs.xml b/.vs/HDL_APP_Project/xs/UserPrefs.xml
index d825d53..8d9a23d 100644
--- a/.vs/HDL_APP_Project/xs/UserPrefs.xml
+++ b/.vs/HDL_APP_Project/xs/UserPrefs.xml
@@ -1,27 +1,42 @@
 锘�<Properties StartupConfiguration="{09712674-2A38-407B-B1E2-560B2C352F9A}|Default">
   <MonoDevelop.Ide.ItemProperties.HDL-ON__iOS automaticSigning="False" PreferredExecutionTarget="MonoDevelop.IPhone.IPhoneDeviceTarget.00008020-001674E61438002E" />
-  <MonoDevelop.Ide.Workbench ActiveDocument="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs">
+  <MonoDevelop.Ide.Workbench ActiveDocument="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs">
     <Files>
-      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs" Line="234" Column="18" />
-      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs" />
-      <File FileName="HDL-ON_Android/Assets/Language.ini" />
-      <File FileName="HDL_ON/Common/R.cs" />
-      <File FileName="HDL_ON/UI/UI2/3-Intelligence/Automation/LogicView/TipPopView.cs" />
-      <File FileName="HDL_ON/UI/UI2/3-Intelligence/Automation/AddLogic.cs" />
-      <File FileName="HDL_ON/UI/UI2/3-Intelligence/Automation/Set.cs" />
-      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Pir.cs" />
-      <File FileName="HDL_ON/UI/CSS/CSS.cs" />
+      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs" Line="276" Column="82" />
+      <File FileName="HDL_ON/DAL/Mqtt/MqttClient.cs" Line="294" Column="1" />
+      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs" Line="170" Column="1" />
+      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Pir.cs" Line="12" Column="33" />
+      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirMain.cs" Line="10" Column="23" />
+      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs" Line="50" Column="46" />
+      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/View/SaveView.cs" Line="11" Column="57" />
+      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PersonalCenterPageBLL.cs" Line="267" Column="70" />
+      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/BrandList.cs" Line="435" Column="63" />
+      <File FileName="HDL_ON/UI/UI2/3-Intelligence/Automation/AddLogic.cs" Line="147" Column="32" />
+      <File FileName="HDL_ON/UI/UI2/3-Intelligence/Automation/Set.cs" Line="8" Column="16" />
+      <File FileName="HDL_ON/UI/UI2/3-Intelligence/Automation/MainView.cs" Line="252" Column="18" />
     </Files>
     <Pads>
       <Pad Id="ProjectPad">
         <State name="__root__">
           <Node name="HDL_APP_Project" expanded="True">
             <Node name="HDL_ON" expanded="True">
+              <Node name="Common" expanded="True" />
+              <Node name="DAL" expanded="True">
+                <Node name="Mqtt" expanded="True" />
+                <Node name="Server" expanded="True" />
+              </Node>
+              <Node name="Entity" expanded="True">
+                <Node name="Function" expanded="True" />
+              </Node>
               <Node name="UI" expanded="True">
                 <Node name="UI2" expanded="True">
+                  <Node name="3-Intelligence" expanded="True">
+                    <Node name="Automation" expanded="True" />
+                  </Node>
                   <Node name="4-PersonalCenter" expanded="True">
                     <Node name="PirDevice" expanded="True">
-                      <Node name="PirSend.cs" selected="True" />
+                      <Node name="View" expanded="True" />
+                      <Node name="Method.cs" selected="True" />
                     </Node>
                   </Node>
                 </Node>
@@ -41,7 +56,9 @@
   <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
   <MonoDevelop.Ide.ItemProperties.HDL-ON__Android PreferredExecutionTarget="Android.4b65c4650918" />
   <MonoDevelop.Ide.DebuggingService.Breakpoints>
-    <BreakpointStore />
+    <BreakpointStore>
+      <Breakpoint file="/Users/hdl/Desktop/wjc/HDL_APP_Project/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs" relfile="HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs" line="274" column="1" />
+    </BreakpointStore>
   </MonoDevelop.Ide.DebuggingService.Breakpoints>
   <MultiItemStartupConfigurations />
 </Properties>
\ No newline at end of file
diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index a7dea34..d597565 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -194,7 +194,7 @@
                     //App璁㈤槄绾㈠瀹� / 缃戝叧閬ユ帶鍣ㄦ坊鍔犳垚鍔熼�氱煡
                     var pirStatus = new MqttTopicFilter()
                     {
-                        Topic = $"/user/${DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/topo/found",
+                        Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/topo/found",
                         QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
                     };
 
@@ -287,10 +287,11 @@
                                     ReceiveNotifySqueezeAsync(mMes);
                                 }
                                 //App璁㈤槄绾㈠瀹�/缃戝叧閬ユ帶鍣ㄦ坊鍔犳垚鍔熼�氱煡
-                                else if (topic == $"/user/${DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/topo/found")
+                                else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/topo/found")
                                 {
-                                    var ss = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
-                                    HDL_ON.UI.UI2.PersonalCenter.PirDevice.Method.addcontronsid = ss;
+                                    var bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, tuyaEncryptKey);
+                                    var revString = Encoding.UTF8.GetString(bytes);
+                                    HDL_ON.UI.UI2.PersonalCenter.PirDevice.Method.addcontronsid = revString;
                                     //ReceiveCheckGateway(ss);
                                     //return;
                                 }
diff --git a/HDL_ON/DAL/Server/NewAPI.cs b/HDL_ON/DAL/Server/NewAPI.cs
index c78788f..c1bdf1d 100644
--- a/HDL_ON/DAL/Server/NewAPI.cs
+++ b/HDL_ON/DAL/Server/NewAPI.cs
@@ -495,11 +495,7 @@
         /// </summary>
         public const string API_POST_Ir_CodeRemove = "/home-wisdom/app/device/ir/codeRemove";
         /// <summary>
-        /// 閬ユ帶鍣ㄥ垹闄�
-        /// </summary>
-        public const string API_POST_Ir_DeviceRemove = "/home-wisdom/program/device/delete";
-        /// <summary>
-        /// 绾㈠瀹濆垹闄�
+        /// 绾㈠瀹�/閬ユ帶鍣ㄥ垹闄�
         /// </summary>
         public const string API_POST_Ir_DeviceDel= "/home-wisdom/app/device/remove";
         /// <summary>
diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PersonalCenterPageBLL.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PersonalCenterPageBLL.cs
index 99458f3..17453a7 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PersonalCenterPageBLL.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PersonalCenterPageBLL.cs
@@ -263,10 +263,17 @@
                 // var page = new ThirdPartyBrandListPage();
                 // MainPage.BasePageView.AddChidren(page);
                 // page.LoadPage();
-                var page = new UI2.PersonalCenter.PirDevice.PirMain();
-                MainPage.BasePageView.AddChidren(page);
-                page.Show();
-                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+                //鑾峰彇鍒楄〃
+                HDL_ON.UI.UI2.PersonalCenter.PirDevice.Method.GetPirDeviceList(this, () =>
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        var page = new UI2.PersonalCenter.PirDevice.PirMain();
+                        MainPage.BasePageView.AddChidren(page);
+                        page.Show();
+                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+                    });
+                });
             };
             btnResidenceAddFunctionIcon.MouseUpEventHandler = eventHandler;
             btnResidenceAddFunctionText.MouseUpEventHandler = eventHandler;
diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs
index 7a72667..d7b7c56 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs
@@ -11,7 +11,8 @@
         {
             Tag = "PirView";
         }
-        public void Show() {
+        public void Show()
+        {
             #region 鐣岄潰甯冨眬
             this.BackgroundColor = CSS.CSS_Color.viewMiddle;
             PirDevice.View.TopView topView = new View.TopView();
@@ -19,10 +20,25 @@
             topView.topIconBtn.Visible = true;
             this.AddChidren(topView.FLayoutView());
             topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); };
-            VerticalScrolViewLayout vv = new VerticalScrolViewLayout();
+            VerticalRefreshLayout vv = new VerticalRefreshLayout();
             vv.Height = Application.GetRealHeight(667 - 64);
             vv.Y = Application.GetRealHeight(64);
             this.AddChidren(vv);
+            vv.BeginHeaderRefreshingAction += () =>
+            {
+                //鍏抽棴鍒锋柊View锛�
+                vv.EndHeaderRefreshing();
+                //鑾峰彇鍒楄〃
+                Method.GetPirDeviceList(this,() =>
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        //鍒锋柊鐣岄潰
+                        UIView(vv);
+                    });
+                });
+
+            };
             #endregion
             UIView(vv);
 
@@ -31,16 +47,17 @@
         /// 鍔犺浇UI鐣岄潰
         /// </summary>
         /// <param name="vv">涓婁笅婊戞帶浠�</param>
-        void UIView(VerticalScrolViewLayout vv) {
+        void UIView(VerticalRefreshLayout vv)
+        {
             vv.RemoveAll();
-            int a = 3;
             for (int i = 0; i < Pir.pirDeviceList.Count; i++)
             {
+                var pirDevice = Pir.pirDeviceList[i];
                 #region 绾㈠瀹濆浘鏍� 鐗堟湰鍙� 鍚嶇О 鐘舵��
                 FrameLayout fLayout = new FrameLayout
                 {
                     Width = Application.GetRealWidth(375),
-                    Height = Application.GetRealHeight(12 + 92 + (50 * a)),
+                    Height = Application.GetRealHeight(12 + 92 + (50 * pirDevice.FunctioList.Count)),
                 };
                 vv.AddChidren(fLayout);
 
@@ -50,7 +67,7 @@
                     Y = Application.GetRealHeight(12),
                     X = Application.GetRealWidth(16),
                     Width = Application.GetRealWidth(375 - 16 * 2),
-                    Height = Application.GetRealHeight(92 + (50 * a)),
+                    Height = Application.GetRealHeight(92 + (50 * pirDevice.FunctioList.Count)),
                     BackgroundColor = CSS.CSS_Color.view,
                     Radius = (uint)Application.GetRealHeight(12),
                 };
@@ -75,7 +92,7 @@
                     X = priequipmentBtn.Right + Application.GetRealWidth(7),
                     Width = Application.GetRealWidth(120),
                     Height = Application.GetRealHeight(20),
-                    Text = "绾㈠瀹滱" + i.ToString(),
+                    Text = pirDevice.name,
                     TextAlignment = TextAlignment.CenterLeft,
                     TextSize = TextSize.text14,
                     TextColor = CSS.CSS_Color.textColor,
@@ -102,7 +119,7 @@
                     X = priequipmentBtn.Right + Application.GetRealWidth(7),
                     Width = Application.GetRealWidth(120),
                     Height = Application.GetRealHeight(17),
-                    Text = "2",
+                    Text = pirDevice.FunctioList.Count.ToString(),
                     TextAlignment = TextAlignment.CenterLeft,
                     TextSize = TextSize.text12,
                     TextColor = CSS.CSS_Color.textConfirmColor,
@@ -163,15 +180,16 @@
                     X = Application.GetRealWidth(16),
                     Width = Application.GetRealWidth(375 - 16 * 2),
                     Height = Application.GetRealHeight(92),
-                    BackgroundColor = CSS.CSS_Color.view,
+                    BackgroundColor = 0x00000000, //CSS.CSS_Color.view,
                     Radius = (uint)Application.GetRealHeight(12),
                     Tag = Pir.pirDeviceList[i],
                 };
                 fLayout.AddChidren(clickFram);
 
-                clickFram.MouseUpEventHandler += (sender, e) => {
+                clickFram.MouseUpEventHandler += (sender, e) =>
+                {
                     var pirclick = (clickFram.Tag as Pir);
-                    NewSwitchView( pirclick,  vv);
+                    NewSwitchView(pirclick, vv);
                 };
 
                 if (Pir.pirDeviceList.Count - 1 == i)
@@ -181,8 +199,9 @@
                 }
                 #endregion
 
-                for (int j = 0; j < a; j++)
+                for (int j = 0; j < pirDevice.FunctioList.Count; j++)
                 {
+                    var control = pirDevice.FunctioList[i];
                     RowLayout funControlRow = new RowLayout
                     {
                         Y = Application.GetRealHeight(92 + (50 * j)),
@@ -198,7 +217,7 @@
                         X = Application.GetRealWidth(16),
                         Width = Application.GetRealWidth(150),
                         Height = Application.GetRealHeight(20),
-                        Text = j.ToString(),
+                        Text = control.name,
                         TextAlignment = TextAlignment.CenterLeft,
                         TextSize = TextSize.text14,
                         TextColor = CSS.CSS_Color.textColor,
@@ -239,6 +258,7 @@
                         TextColor = CSS.CSS_Color.textWhiteColor,
                         IsBold = true,
                         BackgroundColor = CSS.CSS_Color.textRedColor,
+                        Tag = control,
                     };
                     funControlRow.AddRightView(delBtn);
                     //绾�
@@ -251,15 +271,54 @@
                         BackgroundColor = CSS.CSS_Color.viewLine,
                     };
                     funControlRow.AddChidren(line1Btn);
-                    if (j == a - 1)
+                    if (j == pirDevice.FunctioList.Count - 1)
                     {
                         //鏈�鍚庢敼鍙樹竴涓嚎鐨勯鑹�
                         line1Btn.BackgroundColor = CSS.CSS_Color.viewTranslucence;
                         funControlRow.LineColor = CSS.CSS_Color.viewTranslucence;
                     }
-                    delBtn.MouseUpEventHandler += (sender, e) => {
+                    delBtn.MouseUpEventHandler += (sender, e) =>
+                    {
 
+                        var Function = delBtn.Tag as Entity.Function;
+                        //鍔犺浇log
+                        Loading loading = new Loading();
+                        this.AddChidren(loading);
+                        HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
+                        loading.Start();
+                        new System.Threading.Thread(() =>
+                        {
+                            try
+                            {
+                                responsePackNew = PirSend.DeleteDevice(Function.deviceId);
+                            }
+                            catch { }
+                            finally
+                            {
+                                Application.RunOnMainThread(() =>
+                                {
+                                    loading.Hide();
+                                    try
+                                    {
+                                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                                        {
+                                            pirDevice.FunctioList.Remove(Function);
+                                            UIView(vv);
+                                        }
 
+                                        else
+                                        {
+                                            Method method = new Method();
+                                            method.ErrorShow(responsePackNew);
+                                        }
+                                    }
+                                    catch { }
+
+                                });
+                            }
+
+                        })
+                        { IsBackground = true }.Start();
                     };
                 }
 
@@ -272,7 +331,8 @@
         /// </summary>
         /// <param name="pirclick"></param>
         /// <param name="vv"></param>
-        void NewSwitchView(Pir pirclick,VerticalScrolViewLayout vv) {
+        void NewSwitchView(Pir pirclick, VerticalRefreshLayout vv)
+        {
             FrameLayout frame = new FrameLayout { BackgroundColor = CSS.CSS_Color.viewTrans60lucence };
             this.AddChidren(frame);
             SwitchView switchView = new SwitchView();
@@ -324,7 +384,8 @@
                         })
                         { IsBackground = true }.Start();
 
-                    }, () => {
+                    }, () =>
+                    {
                         NewSwitchView(pirclick, vv);
                     }, false);
 
@@ -333,7 +394,8 @@
                 {
                     string text = Language.StringByID(StringId.shanchushebei) + pirclick.name + "?";
                     TipPopView tipPopView = new TipPopView();
-                    tipPopView.TipBox(StringId.tip, text, (dialog) => {
+                    tipPopView.TipBox(StringId.tip, text, (dialog) =>
+                    {
                         //鍔犺浇log
                         Loading loading = new Loading();
                         dialog.AddChidren(loading);
@@ -368,12 +430,15 @@
 
                         })
                         { IsBackground = true }.Start();
-                    }, () => {
+                    }, () =>
+                    {
                         NewSwitchView(pirclick, vv);
                     }, false);
 
                 }
             });
         }
+
+      
     }
 }
diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
index 4825826..0bc89c6 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -11,26 +11,26 @@
         /// <summary>
         /// 娣诲姞閬ユ帶鍣ㄧ殑鏂规硶
         /// </summary>
-        public void AddControl(FrameLayout frameLayout,Action<Control> action)
+        public void AddControl(FrameLayout frameLayout, Action<Control> action)
         {
             View.TipView tipView = new View.TipView();
-            tipView.InputBox(frameLayout,"", (name, frame) => 
-            {
-                ///娓呴櫎涔嬪墠鍒楄〃鏁版嵁
-                Pir.BuottonList.Clear();
-                if (!string.IsNullOrEmpty(name))
-                {
-                    Control control = new Control();
-                    control.name = name;
-                    control.type = "learn";
-                    control.spk = "ir.learn";
-
-                    ThreadAddControl(control, frame, action);
+            tipView.InputBox(frameLayout, "", (name, frame) =>
+             {
+                 ///娓呴櫎涔嬪墠鍒楄〃鏁版嵁
+                 Pir.BuottonList.Clear();
+                 if (!string.IsNullOrEmpty(name))
+                 {
+                     Control control = new Control();
+                     control.name = name;
+                     control.type = "learn";
+                     control.spk = "ir.learn";
+                     control.deviceId = Pir.currPir.deviceId;
+                     ThreadAddControl(control, frame, action);
 
 
 
-                }
-            }, false);
+                 }
+             }, false);
 
         }
         /// <summary>
@@ -38,7 +38,8 @@
         /// </summary>
         /// <param name="control"></param>
         /// <param name="frame"></param>
-        public void ThreadAddControl(Control control, FrameLayout frame,Action<Control> action) {  
+        public void ThreadAddControl(Control control, FrameLayout frame, Action<Control> action)
+        {
 
             DAL.Server.ResponsePackNew responsePackNew = null;
             Loading loading = new Loading();
@@ -56,10 +57,26 @@
                     Application.RunOnMainThread(() =>
                     {
                         loading.Hide();
-                    if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
-                    {
+                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                        {
+                            bool bool_if = false;
                             string sid = responsePackNew.Data.ToString();
-                            if (string.IsNullOrEmpty(Sid(sid)))
+                            var mqttdate = MqttDate();
+                            for (int i = 0; i < mqttdate.objects.Count; i++) {
+                                var objects = mqttdate.objects[i];
+                                if (sid == objects.sid) {
+                                    bool_if = true;
+                                    break;
+                                }
+                            }
+                            if (bool_if)
+                            {
+                                control.deviceId = mqttdate.id;
+                                ///杩欓噷锛氱洃鍚琈TTP鎺ㄩ�佷笅鏉ヤ富棰橈紝鎵嶇煡閬撴槸鍚︽坊鍔犳垚鍔�
+                                frame.RemoveFromParent();//娣诲姞鎴愬姛鍏抽棴寮圭獥
+                                action(control);
+                            }
+                            else
                             {
                                 //鐩戝惉Mqtt鎺ㄩ�佷笅鏉ョ姸鎬佺爜鍋氭彁绀�
                                 View.FailView failView = new View.FailView();
@@ -69,14 +86,8 @@
                                     ThreadAddControl(control, frame, action);
                                 });
                             }
-                            else
-                            {
-                                ///杩欓噷锛氱洃鍚琈TTP鎺ㄩ�佷笅鏉ヤ富棰橈紝鎵嶇煡閬撴槸鍚︽坊鍔犳垚鍔�
-                                frame.RemoveFromParent();//娣诲姞鎴愬姛鍏抽棴寮圭獥
-                                action(control);
-                            }
 
-                            
+
                         }
                         else
                         {
@@ -88,7 +99,152 @@
             { IsBackground = true }.Start();
 
         }
-      
+
+        /// <summary>
+        /// 鑾峰彇绾㈠璁惧鍒楄〃
+        /// </summary>
+        public static void GetPirDeviceList(FrameLayout frame, Action action)
+        {
+            //娓呴櫎涔嬪墠鍒楄〃;
+            Pir.pirDeviceList.Clear();
+            //鍔犺浇log
+            Loading loading = new Loading();
+            frame.AddChidren(loading);
+            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
+            loading.Start();
+            new System.Threading.Thread(() =>
+            {
+                try
+                {
+                    responsePackNew = PirSend.GetDeviceList("ir.module");
+                }
+                catch { }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        loading.Hide();
+                        try
+                        {
+                            if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                            {
+                                var jobject = Newtonsoft.Json.Linq.JObject.Parse(responsePackNew.Data.ToString());
+                                string list = jobject["list"].ToString();
+
+                                var jArray = Newtonsoft.Json.Linq.JArray.Parse(list);
+                                for (int a = 0; a < jArray.Count; a++)
+                                {
+                                    var jay = jArray[a];
+                                    string spk = jay["spk"].ToString();
+                                    if (spk == "ir.module")
+                                    {
+                                        //鏁版嵁杩斿簭鍒楀寲涓篖ogic瀵硅薄
+                                        var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
+                                        var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Pir>(str);
+                                        if (pirJosn != null)
+                                        {
+                                            if (null == Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
+                                            {
+
+                                                Pir.pirDeviceList.Add(pirJosn);
+
+                                            }
+                                        }
+                                    }
+
+                                }
+                                GetControlList(frame, action);
+
+                            }
+                            else
+                            {
+                                Method method = new Method();
+                                method.ErrorShow(responsePackNew);
+                            }
+                        }
+                        catch { }
+
+                    });
+                }
+
+            })
+            { IsBackground = true }.Start();
+
+        }
+        /// <summary>
+        /// 鑾峰彇閬ユ帶鍣ㄥ垪琛�
+        /// </summary>
+        public static void GetControlList(FrameLayout frame, Action action)
+        {
+            //鍔犺浇log
+            Loading loading = new Loading();
+            frame.AddChidren(loading);
+            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
+            loading.Start();
+            new System.Threading.Thread(() =>
+            {
+                try
+                {
+                    for (int i = 0; i < Pir.pirDeviceList.Count; i++)
+                    {
+                        var pirDevice = Pir.pirDeviceList[i];
+                        try
+                        {
+                            responsePackNew = PirSend.ControlList(pirDevice);
+
+                        }
+                        catch { }
+                        finally
+                        {
+                            Application.RunOnMainThread(() =>
+                            {
+                                try
+                                {
+                                    if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                                    {
+                                        var jArray = Newtonsoft.Json.Linq.JArray.Parse(responsePackNew.Data.ToString());
+                                        for (int a = 0; a < jArray.Count; a++)
+                                        {
+                                            var jay = jArray[a];
+                                            //鏁版嵁杩斿簭鍒楀寲涓篖ogic瀵硅薄
+                                            var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
+                                            var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(str);
+                                            if (pirJosn != null)
+                                            {
+                                                if (null == pirDevice.FunctioList.Find((c) => c.sid == pirJosn.sid))
+                                                {
+                                                    pirDevice.FunctioList.Add(pirJosn);
+                                                }
+                                            }
+
+                                        }
+                                    }
+                                    else
+                                    {
+                                        //Method method = new Method();
+                                        //method.ErrorShow(responsePackNew);
+                                    }
+                                }
+                                catch { }
+
+                            });
+                        }
+                    }
+                }
+                catch { }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        loading.Hide();
+                        action();
+                    });
+                }
+            })
+            { IsBackground = true }.Start();
+
+        }
+
         /// <summary>
         /// MQTT涓婚鎺ㄩ�佷笅鏉ョ殑鏁版嵁(閬ユ帶鍣ㄦ坊鍔�)
         /// </summary>
@@ -96,26 +252,40 @@
         /// <summary>
         /// 
         /// </summary>
-        /// <param name="sid"></param>
         /// <returns></returns>
-        public string Sid(string sid)
+        public Cloud MqttDate()
         {
             var dateTime = DateTime.Now;
-            while ((DateTime.Now - dateTime).TotalMilliseconds < 5* 1000)
+            while ((DateTime.Now - dateTime).TotalMilliseconds < 5 * 1000)
             {
-                if (!string.IsNullOrEmpty(addcontronsid) && addcontronsid == sid)
+                if (!string.IsNullOrEmpty(addcontronsid))
                 {
                     break;
                 }
 
             }
-            return addcontronsid;
+            return PushData();
         }
+
+        public Cloud PushData()
+        {
+            Cloud cloud = new Cloud();
+            if (addcontronsid != "")
+            {
+                //var date = Newtonsoft.Json.JsonConvert.SerializeObject(addcontronsid);
+                cloud = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(addcontronsid);
+
+            }
+            return cloud;
+        }
+
+
+
         /// <summary>
         /// 閿欒鐮佹彁绀�
         /// </summary>
         /// <param name="responsePackNew"></param>
-        public  void ErrorShow(ResponsePackNew responsePackNew)
+        public void ErrorShow(ResponsePackNew responsePackNew)
         {
 
             if (responsePackNew != null && responsePackNew.Code == "14005")
@@ -129,7 +299,25 @@
 
             }
         }
-       
+
     }
-  
+    [Serializable]
+    public class Cloud
+    {
+        /// <summary>
+        /// 璁惧id
+        /// </summary>
+        public string id = string.Empty;
+        public List<Objects> objects = new List<Objects>();
+        public string time_stamp = string.Empty;
+
+
+    }
+    [Serializable]
+    public class Objects
+    {
+        public string sid = string.Empty;
+        public string spk = string.Empty;
+    }
+
 }
diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Pir.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Pir.cs
index cc45c1f..e985b71 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Pir.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Pir.cs
@@ -3,7 +3,7 @@
 namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
 {
     [System.Serializable]
-    public class Pir
+    public class Pir: Entity.Function
     {
         /// <summary>
         /// 娣诲姞鎸夐敭鍒楄〃
@@ -15,36 +15,15 @@
         /// </summary>
         public static Pir currPir;
         /// <summary>
-        /// 璁惧ID
+        /// 閬ユ帶鍣ㄥ垪琛�
         /// </summary>
-        public string deviceId = string.Empty;
-        public string homeId = string.Empty;
-        public string gatewayId = string.Empty;
-        public string name = string.Empty;
-        public string sid = string.Empty;
-        public string spk = string.Empty;
-        public string oid = string.Empty;
-        public string omodel = string.Empty;
-        public bool collect =false;
-        public bool online = false;
-        public string controlCounter = string.Empty;
+        public List<Entity.Function> FunctioList = new List<Entity.Function>();
 
-        public  List<Attributes> attributes = new List<Attributes>();
+    }
+   
 
-}
-[Serializable]
-public class Attributes
-{
-    public string key = string.Empty;
-    public string data_type = string.Empty;
-    public int max = 0;
-    public int min = 0;
-    public int sort = 0;
-    public List<string> value = new List<string>();
-}
-
-
-public class Control
+    [System.Serializable]
+    public class Control
     {
         /// <summary>
         /// 绾㈠瀹濊澶嘔d
@@ -75,6 +54,7 @@
         /// </summary>
         public List<ButtonObj> status = new List<ButtonObj>();
     }
+    [System.Serializable]
     public class ButtonObj
     {
         public string Key = string.Empty;
@@ -83,6 +63,7 @@
         /// </summary>
         public string value = string.Empty;
     }
+    [System.Serializable]
     public class DeviceType
     {
         /// <summary>
@@ -94,6 +75,7 @@
         /// </summary>
         public string deviceType = string.Empty;
     }
+    [System.Serializable]
     public class Brand
     {
         /// <summary>
@@ -127,5 +109,5 @@
         public string irIndex = string.Empty;
 
     }
-   
+
 }
diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirMain.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirMain.cs
index 1aebd1f..902b7ee 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirMain.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirMain.cs
@@ -10,7 +10,7 @@
         public PirMain()
         {
             Tag = "PirMain";
-            GetPirDeviceList();
+        
         }
         /// <summary>
         /// 涓存椂鍌ㄥ瓨璁惧绫诲瀷鍒楄〃
@@ -179,7 +179,8 @@
                 Text = "mini鏅鸿兘閬ユ帶鍣�",
             };
             deviceListFLayout.AddChidren(deviceNameBtn);
-            if (Pir.pirDeviceList.Count!=0) {
+            if (Pir.pirDeviceList.Count != 0)
+            {
                 deviceNameBtn.Text = Pir.pirDeviceList[0].name;
                 Pir.currPir = Pir.pirDeviceList[0];
             }
@@ -209,7 +210,7 @@
                     fLayout.RemoveFromParent();
                 };
 
-                FrameLayout iconFLyout = new FrameLayout 
+                FrameLayout iconFLyout = new FrameLayout
                 {
                     X = Application.GetRealWidth(205),
                     Y = Application.GetRealHeight(314),
@@ -219,14 +220,14 @@
                 };
                 fLayout.AddChidren(iconFLyout);
 
-                FrameLayout textFLyout = new FrameLayout 
+                FrameLayout textFLyout = new FrameLayout
                 {
                     X = Application.GetRealWidth(8),
                     Y = Application.GetRealHeight(14),
                     Width = Application.GetRealWidth(144),
                     Height = Application.GetRealHeight(44),
                 };
-                VerticalScrolViewLayout vv = new VerticalScrolViewLayout 
+                VerticalScrolViewLayout vv = new VerticalScrolViewLayout
                 {
                     X = Application.GetRealWidth(8),
                     Y = Application.GetRealHeight(14),
@@ -234,7 +235,7 @@
                     Height = Application.GetRealHeight(44 * 4),
                 };
 
-                if (Pir.pirDeviceList.Count >4)
+                if (Pir.pirDeviceList.Count > 4)
                 {
                     iconFLyout.Height = Application.GetRealHeight(21 + 44 * 4);
                     iconFLyout.AddChidren(vv);
@@ -252,8 +253,8 @@
 
                 for (int i = 0; i < Pir.pirDeviceList.Count; i++)
                 {
-                    var pirJson = Pir.pirDeviceList[i]; 
-                    View.PirNameView pirNameView = new View.PirNameView(); 
+                    var pirJson = Pir.pirDeviceList[i];
+                    View.PirNameView pirNameView = new View.PirNameView();
                     if (Pir.pirDeviceList.Count > 4)
                     {
                         vv.AddChidren(pirNameView.FLayoutView());
@@ -330,7 +331,8 @@
                     if (if_value == 7)
                     {
                         Method method = new Method();
-                        method.AddControl(this,(control) => {
+                        method.AddControl(this, (control) =>
+                        {
                             AddButton addButton = new AddButton();
                             MainPage.BasePageView.AddChidren(addButton);
                             addButton.Show(control);
@@ -347,35 +349,36 @@
                         }
                         GetBrandList(jobDeviceType.id, (brandList) =>
                         {
-                          var brandSupportStrList= GetBrandSupport(if_value);
+                            var brandSupportStrList = GetBrandSupport(if_value);
                             var strList = new List<string>();
                             for (int str = 0; str < brandList.Count; str++)
                             {
                                 string s = brandList[str].brandName;
-                                var bool_if = brandSupportStrList.Find((c)=>s.Contains(c));
-                                if (bool_if!=null)
+                                var bool_if = brandSupportStrList.Find((c) => s.Contains(c));
+                                if (bool_if != null)
                                 {
                                     strList.Add(s);
                                 }
 
                             }
-                            Application.RunOnMainThread(()=> {
+                            Application.RunOnMainThread(() =>
+                            {
                                 BrandList brandObj = new BrandList();
                                 MainPage.BasePageView.AddChidren(brandObj);
                                 brandObj.Show(brandList, strList, strings[1]);
                                 MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                             });
-                         
+
                         });
-                        
+
                     }
 
-                   
+
                 };
 
             }
             GetDeviceTypeList();
-          
+
         }
         /// <summary>
         /// 鑾峰彇鍝佺墝鏀寔
@@ -425,7 +428,7 @@
                     {
                     }
                     break;
-              
+
 
             }
             return strList;
@@ -442,13 +445,13 @@
                 case 1:
                     {
                         //绌鸿皟
-                        type = "ac-"+SPK.AcIr;
+                        type = "ac-" + SPK.AcIr;
                     }
                     break;
                 case 2:
                     {
                         //鐢佃
-                        type = "tv-"+SPK.ElectricTV;
+                        type = "tv-" + SPK.ElectricTV;
                     }
                     break;
                 case 3:
@@ -460,22 +463,22 @@
                 case 4:
                     {
                         //鏈洪《鐩�
-                      //  type = "set_top_box-" + SPK.ElectricTV;
+                        //  type = "set_top_box-" + SPK.ElectricTV;
                     }
                     break;
                 case 5:
                     {
-                      //褰辩鏈�
-                      // type = "dvd-" + SPK.ElectricTV;
+                        //褰辩鏈�
+                        // type = "dvd-" + SPK.ElectricTV;
                     }
                     break;
                 case 6:
                     {
                         //鎶曞奖浠�
-                      //  type = "projector-" + SPK.ElectricTV;
+                        //  type = "projector-" + SPK.ElectricTV;
                     }
                     break;
-            
+
 
             }
             return type;
@@ -573,11 +576,10 @@
                 }
             }, "", "璁惧绫诲瀷鍒楄〃");
         }
-
         /// <summary>
         /// 璇诲彇绾㈠璁惧绫诲瀷鐨勫搧鐗屽垪琛�
         /// </summary>
-        private void GetBrandList(string id,Action<List<Brand>> actionBrand)
+        private void GetBrandList(string id, Action<List<Brand>> actionBrand)
         {
             List<Brand> brandList = new List<Brand>();
             PirSend.GetDeviceTypesList(this, (responsePackNew) =>
@@ -610,74 +612,6 @@
                 }
             }, id, "鍝佺墝鍒楄〃");
         }
-
-       
-        /// <summary>
-        /// 鑾峰彇绾㈠璁惧鍒楄〃
-        /// </summary>
-        private void GetPirDeviceList( )
-        {
-
-            //鍔犺浇log
-            Loading loading = new Loading();
-            this.AddChidren(loading);
-            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
-            loading.Start();
-            new System.Threading.Thread(() =>
-            {
-                try
-                {
-                    responsePackNew = PirSend.GetDeviceList("ir.module");
-                }
-                catch { }
-                finally
-                {
-                    Application.RunOnMainThread(() =>
-                    {
-                        loading.Hide();
-                        try { 
-                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
-                        {
-                            var jobject = Newtonsoft.Json.Linq.JObject.Parse(responsePackNew.Data.ToString());
-                            string list = jobject["list"].ToString();
-
-                            var jArray = Newtonsoft.Json.Linq.JArray.Parse(list);
-                            for (int a = 0; a < jArray.Count; a++)
-                            {
-                                var jay = jArray[a];
-                                string spk = jay["spk"].ToString();
-                                if (spk == "ir.module")
-                                {
-                                    //鏁版嵁杩斿簭鍒楀寲涓篖ogic瀵硅薄
-                                    var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
-                                    var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Pir>(str);
-                                    if (pirJosn != null)
-                                    {
-                                        if (null == Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
-                                        {
-
-                                            Pir.pirDeviceList.Add(pirJosn);
-                                        }
-                                    }
-                                }
-
-                            }
-                        }
-                        else
-                        {
-                            Method method = new Method();
-                            method.ErrorShow(responsePackNew);
-                        }
-                        }
-                        catch { }
-
-                    });
-                }
-
-            })
-            { IsBackground = true }.Start();
-        }
-
     }
-  
+
 }
diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs
index 537f1a0..6c253dc 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/PirSend.cs
@@ -53,9 +53,9 @@
         /// <summary>
         /// 鑾峰彇閬ユ帶鍣ㄥ垪琛�
         /// </summary>
-        public static ResponsePackNew GetList()
+        public static ResponsePackNew ControlList(Pir pir)
         {
-            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", pirId } };
+            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", pir.deviceId } };
             var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_List);
             return responsePackNew;
         }
@@ -69,7 +69,7 @@
         {
             var jObject = new JObject { }; 
             jObject.Add("homeId", HomeId);
-            jObject.Add("deviceId", pirId);
+            jObject.Add("deviceId", control.deviceId);
             jObject.Add("name", control.name);
             jObject.Add("spk", control.spk);
             jObject.Add("type", control.type);
@@ -95,7 +95,7 @@
         {
             var jObject = new JObject { }; 
             jObject.Add("homeId", HomeId);
-            jObject.Add("deviceId", pirId);
+            jObject.Add("deviceId", control.deviceId);
             jObject.Add("spk", control.spk);
             if (control.spk== Entity.SPK.AcStandard) {
                 jObject.Add("group_id", control.group_id);
@@ -181,23 +181,9 @@
             var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_CodeRemove);
             return responsePackNew;
         }
-        /// <summary>
-        /// 閬ユ帶鍣ㄥ垹闄�
-        /// </summary>
-        /// <returns></returns>
-        public static ResponsePackNew DeleteControl(string deviceId)
-        {
-            var job = new JObject { };
-            job.Add("deviceId", deviceId);
-            var jArray = new JArray { };
-            jArray.Add(job);
-            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", pirId }, { "devices", jArray } };
-            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_DeviceRemove);
-            return responsePackNew;
-        }
 
         /// <summary>
-        /// 绾㈠瀹濊澶囧垹闄�
+        /// 绾㈠瀹�/閬ユ帶鍣ㄥ垹闄�
         /// </summary>
         /// <returns></returns>
         public static ResponsePackNew DeleteDevice(string deviceId)

--
Gitblit v1.8.0