From d8545fbd1b36a6766c57c987e5d89862b470fed9 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期四, 03 九月 2020 09:46:29 +0800
Subject: [PATCH] 2020-09-03 1.修改风扇默认为关状态。2.Alexa添加设备时,去掉空调和通用开关选择添加支持。 3.场景增加通用开关添加和发送控制支持,Alexa 的场景同样增加通用开关的支持。

---
 Crabtree/SmartHome/HDL/Operation/UserConfig.cs |  123 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 110 insertions(+), 13 deletions(-)

diff --git a/Crabtree/SmartHome/HDL/Operation/UserConfig.cs b/Crabtree/SmartHome/HDL/Operation/UserConfig.cs
index ac01c14..6074190 100644
--- a/Crabtree/SmartHome/HDL/Operation/UserConfig.cs
+++ b/Crabtree/SmartHome/HDL/Operation/UserConfig.cs
@@ -7,7 +7,7 @@
     [System.Serializable]
     public class UserConfig
     {
-        static string configFile = "UserConfig";
+        public static string configFile = "UserConfig";
 
         static UserConfig instance;
         public static UserConfig Instance {
@@ -28,7 +28,7 @@
                             instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Sensor);
                             instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Environmental);
                             instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.MusicModel);
-                            instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.UniversalDevice);
+                            //instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.UniversalDevice);
                         } else {
                             instance = temp;
                         }
@@ -154,9 +154,17 @@
             set {
                 currentRegion = value;
                 CheckIfNeedGetMasterAccountToken ();
+                //鍒囨崲浣忓畢 璁剧疆鏈湴鍔犲瘑Key
+                SetLocalEncryptKey ();
+
+
             }
             get {
+                if (currentRegion == null) {
+                    currentRegion = new RegionInfoRes ();
+                }
                 return currentRegion;
+
             }
 
         }
@@ -173,6 +181,15 @@
         public bool CheckHomeGatewaysNotEmpty ()
         {
             if (CheckHomeGateways () && !string.IsNullOrEmpty (currentRegion.HomeGateways [0].GatewayUniqueId)) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+
+        public bool CheckThisHomeGatewaysNotEmpty (RegionInfoRes mRegionInfoRes)
+        {
+            if (mRegionInfoRes != null && mRegionInfoRes.HomeGateways != null && mRegionInfoRes.HomeGateways.Count > 0 && !string.IsNullOrEmpty (mRegionInfoRes.HomeGateways [0].GatewayUniqueId)) {
                 return true;
             } else {
                 return false;
@@ -204,23 +221,100 @@
                 if (CheckHomeGateways ()) {
                     currentRegion.HomeGateways [0].GatewayUniqueId = value;
                 } else {
-                    if (currentRegion != null && currentRegion.HomeGateways == null) {
+                    //2020-01-11 
+                    if (currentRegion != null) {
                         var mHomeGateways = new HomeGateways () { GatewayUniqueId = value };
-                        List<HomeGateways> HomeGateways = new List<HomeGateways> ();
-                        HomeGateways.Add (mHomeGateways);
-                        currentRegion.HomeGateways = HomeGateways;
+                        var mList = new List<HomeGateways> ();
+                        mList.Add (mHomeGateways);
+                        currentRegion.HomeGateways = mList;
                     }
                 }
             }
 
         }
-        
+
+        /// <summary>
+        /// 鏇存柊璁剧疆褰撳墠浣忓畢缃戝叧
+        /// 2020-01-11 
+        /// </summary>
+        /// <param name="mGatewayDataList"></param>
+        public void SetNowHomeGateways (List<GatewayRes> mGatewayDataList) {
+            try {
+                if (currentRegion != null) {
+                    if (mGatewayDataList != null && mGatewayDataList.Count > 0) {
+                        var mMacList = new List<HomeGateways> ();
+                        foreach (var mGatewayRes in mGatewayDataList) {
+                            var mac = new HomeGateways ();
+                            mac.GatewayUniqueId = mGatewayRes.GatewayUniqueId;
+                            mMacList.Add (mac);
+                        }
+                        currentRegion.HomeGateways = mMacList;
+                    }
+                }
+            } catch {
+
+            }
+        }
+
+
 
         public List<string> RometoUserInfoKeys = new List<string> ();
 
+
+        /// <summary>
+        /// 鏈湴閫氫俊鍔犲瘑Key
+        /// </summary>
+        public string LocalEncryptKey = string.Empty;
+
+
+        /// <summary>
+        /// 鏄惁鍔犲瘑瀵嗙爜楠岃瘉閫氳繃
+        /// </summary>
+        public bool EncryptedPasswordCorrect = true;
+
+        /// <summary>
+        /// 鏄惁鍔犲瘑
+        /// </summary>
+        public bool IsLocalEncrypt = false;
+        /// <summary>
+        /// 璁剧疆涓洪粯璁ゅ姞瀵嗭紝骞惰绠楀姞瀵咾ey
+        /// </summary>
+        private void SetLocalEncryptKey ()
+        {
+            if (currentRegion != null) {
+                IsLocalEncrypt = true;
+                GenerateLocalEncryptionKey ();
+                //LocalEncryptKey = CommonPage.MyEncodingUTF8.GetString (GenerateLocalEncryptionKey ());
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇16浣嶇殑key byte []
+        /// </summary>
+        /// <returns></returns>
+        public byte [] GenerateLocalEncryptionKey ()
+        {
+            byte [] aseKey = new byte [16];
+            try {
+                //鐢熸垚鍔犲瘑Key
+                byte [] homeId =  System.Text.Encoding.ASCII.GetBytes (currentRegion.Id);
+                Array.Copy (homeId, 0, aseKey, 0, 16 < homeId.Length ? 16 : homeId.Length);
+                LocalEncryptKey = System.Text.Encoding.ASCII.GetString (aseKey);
+                return aseKey;
+
+            } catch {
+                return aseKey;
+            }
+
+        }
+
         public string MasterAccountToken = "";
         public string MasterAccountRequestBaseUrl = "";
-
+        /// <summary>
+        /// 鏄惁鑾峰彇涓�
+        /// 2020-01-11 
+        /// </summary>
+        bool bGetting = false;
         //public static List<string> LocalFiles = IO.FileUtils.ReadFiles ();
         /// <summary>
         /// 鑾峰彇鎺у埗鍒嗕韩椤圭洰(浣忓畢)璇锋眰淇℃伅
@@ -229,18 +323,19 @@
         /// <param name="mSharedHid"></param>
         public void CheckIfNeedGetMasterAccountToken ()
         {
+            if (bGetting) return;
+
             //2020-01-08 鍒ゆ柇鏄惁鍒嗕韩杩囨潵鐨勪綇瀹�
-            if (CurrentRegion != null && CurrentRegion.IsOthreShare) {
+            if (currentRegion != null && currentRegion.IsOthreShare) {
                 //MainPage.IsAdministrator = UserConfig.Instance.CurrentRegion.IsOthreShare;
                 //璇锋眰涓昏处鍙穞oken
                 System.Threading.Tasks.Task.Run (() => {
                     try {
-                        //var mMainAccountId = UserConfig.Instance.CurrentRegion.MainUserDistributedMark;
-                        //var mSharedHid = UserConfig.Instance.CurrentRegion.Id;
+                        bGetting = true;
                         var requestObj = new GetSharedHomeApiControlObj () {
                             LoginAccessToken = MainPage.LoginUser.LoginTokenString,
-                            MainAccountId = UserConfig.Instance.CurrentRegion.MainUserDistributedMark,
-                            SharedHid = UserConfig.Instance.CurrentRegion.Id,
+                            MainAccountId = currentRegion.MainUserDistributedMark,
+                            SharedHid = currentRegion.Id,
 
                         };
                         var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
@@ -254,6 +349,8 @@
                         }
                     } catch {
 
+                    } finally {
+                        bGetting = false;
                     }
                 });
             }

--
Gitblit v1.8.0