From 9a4b76398009cf76c508d61f7e48fb6f5cb7ac2d Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期二, 21 七月 2020 09:46:53 +0800
Subject: [PATCH] 请合并最新多功能面板代码

---
 ZigbeeApp/Shared/Common/Device.cs |  257 +++++++++++++++++++++++++++++----------------------
 1 files changed, 145 insertions(+), 112 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
old mode 100644
new mode 100755
index b35be85..1435f45
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -115,7 +115,7 @@
             {
                 CommonDevice device = null;
                 //鍙嶅簭鍒楀寲涓烘寚瀹氱殑绫伙紝涓嶇劧鏁版嵁浼氫涪澶辫�屽鑷存棤娉曞己杞�
-                try
+                try 
                 {
                     device = CommonDevice.CommonDeviceByFilePath(file);
                 }
@@ -434,7 +434,7 @@
             if (Common.Config.Instance.Home.IsVirtually == true)
             {
                 //淇敼璁惧鍚嶅瓧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
-                Phone.UserView.UserPage.Instance.RefreshForm = true;
+                Phone.UserView.UserPage.Instance.RefreshAllForm = true;
                 return true;
             }
 
@@ -458,7 +458,7 @@
                 }
             }
             //淇敼璁惧鍚嶅瓧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
-            Phone.UserView.UserPage.Instance.RefreshForm = true;
+            Phone.UserView.UserPage.Instance.RefreshAllForm = true;
             return true;
         }
 
@@ -551,7 +551,7 @@
 
             //鑾峰彇缂栬緫璁惧Mac鍚嶅瓧鐨勫懡浠ゅ瓧绗�
             var sendData = this.GetReDeviceMacNameCommandText(device.DeviceAddr, device.DeviceEpoint, macName);
-            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "MacRename", sendData, "MacRename_Respon");
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "MacRename", sendData, "MacRename_Respon", 8);
             if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
             {
                 return null;
@@ -578,7 +578,7 @@
             }
             //鑾峰彇缂栬緫璁惧绔偣鍚嶅瓧鐨勫懡浠ゅ瓧绗�
             var sendData = this.GetReDeviceEpointNameCommandText(device.DeviceAddr, device.DeviceEpoint, deviceName);
-            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "DeviceRename", sendData, "DeviceRenameRespon");
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "DeviceRename", sendData, "DeviceRenameRespon", 8);
             if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
             {
                 return null;
@@ -709,8 +709,8 @@
                 this.SaveRealDeviceRoomId(null, null);
             }
             return true;
-        }
-
+        }
+
         /// <summary>
         /// 鍒犻櫎缂撳瓨鐨勪竴鑸澶�
         /// </summary>
@@ -719,7 +719,7 @@
         public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true)
         {
             //鍒犻櫎缂撳瓨璁惧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
-            Phone.UserView.UserPage.Instance.RefreshForm = true;
+            Phone.UserView.UserPage.Instance.RefreshAllForm = true;
 
             if (deleteRoom == true)
             {
@@ -792,21 +792,21 @@
                 }
                 this.dicOTADevice.Remove(otaKeys);
             }
-        }
-
+        }
+
         #endregion
-
+
         #region 鈻� 鍚屾璁惧___________________________
         /// <summary>
         ///  鍚屾璁惧骞朵笖鍒锋柊缂撳瓨(鍚屾澶辫触鏃讹紝浼氭樉绀轰俊鎭�)
         /// </summary>
         /// <param name="litdevice">璁惧瀵硅薄(MAC鍦板潃蹇呴』瑕佺浉鍚�)</param>
         public async Task<bool> SynchronizationDevice(List<CommonDevice> listdevice)
-        {
-            //铏氭嫙浣忓畢鐨勮瘽,涓嶉渶瑕佸垹闄ょ綉鍏崇殑璁惧
+        {
+            //铏氭嫙浣忓畢鐨勮瘽,涓嶉渶瑕佸垹闄ょ綉鍏崇殑璁惧
             if (Config.Instance.Home.IsVirtually == false)
-            {
-                //鍚屾
+            {
+                //鍚屾
                 var result = await listdevice[0].SyncMsgToBindSource(listdevice[0].DeviceAddr, listdevice[0].DeviceEpoint);
                 if (result == null || result.result != 0)
                 {
@@ -820,13 +820,13 @@
                 }
             }
             return true;
-        }
-        #endregion
-
-
-
+        }
+        #endregion
+
+
+
         #region 鈻� 娴嬭瘯璁惧___________________________
-
+
         /// <summary>
         /// 鍙戦�佸畾浣嶆寚浠ゅ埌璁惧
         /// </summary>
@@ -860,6 +860,11 @@
                     //浼犳劅鍣ㄩ櫎浜哖ir閮芥病鏈夊畾浣嶅姛鑳�
                     return true;
                 }
+                else if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_SphericalMotion)
+                {
+                    //鐞冨瀷绉诲姩浼犳劅鍣ㄨ櫧鐒舵槸鐢垫睜璁惧,浣嗘槸瀹冩湁瀹氫綅鍔熻兘
+                    return true;
+                }
                 return false;
             }
 
@@ -872,21 +877,21 @@
                 }
             }
             return false;
-        }
-
+        }
+
         /// <summary>
         /// 妫�娴嬭澶囨槸鍚︽嫢鏈変竴閿悓姝ュ姛鑳�
         /// </summary>
         /// <param name="device"></param>
         /// <returns></returns>
         public bool DeviceIsCanSynchronization(CommonDevice device)
-        {
-            //鑾峰彇璁惧绫诲瀷鐨�
+        {
+            //鑾峰彇璁惧绫诲瀷鐨�
             var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
-            if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
-            {
-                return true;
-            }
+            if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
+            {
+                return true;
+            }
             return false;
         }
 
@@ -1073,7 +1078,7 @@
         /// <param name="listDevice"></param>
         /// <returns></returns>
         public List<CommonDevice> GetPanelMatchEpointByMac(List<CommonDevice> listDevice, bool sort = true)
-        {
+        { 
             var list = new List<CommonDevice>();
             foreach (var dev in listDevice)
             {
@@ -1084,13 +1089,13 @@
                 else if (dev.Type == DeviceType.FreshAirHumiditySensor)
                 {
                     list.Add(dev);
-                }
+                }  
             }
             if (sort == false)
             {
                 return list;
-            }
-            list.Sort((obj1, obj2) =>
+            }
+            list.Sort((obj1, obj2) =>
             {
 
                 if (obj1.DeviceEpoint > obj2.DeviceEpoint)
@@ -1098,7 +1103,7 @@
                     return 1;
                 }
                 return -1;
-            });
+            }); 
             return list;
         }
 
@@ -1156,7 +1161,7 @@
         public List<string> GetAllDeviceFile()
         {
             List<string> listDeviceFile = new List<string>();
-            List<string> listAllFile = Global.FileListByHomeId();
+            List<string> listAllFile = HdlFileLogic.Current.GetRootPathListFile();
 
             foreach (string file in listAllFile)
             {
@@ -1311,7 +1316,7 @@
             }
 
             if (device.Type == DeviceType.OnOffOutput
-                || device.Type == DeviceType.DimmableLight
+                || device.Type == DeviceType.DimmableLight 
                 || device.Type == DeviceType.ColorDimmableLight
                 || device.Type == DeviceType.ColorTemperatureLight)
             {
@@ -1322,9 +1327,9 @@
             {
                 //绌鸿皟閮藉彨瀹ゅ唴鏈�
                 return Language.StringByID(R.MyInternationalizationString.uIndoorUnit) + epointNo;
-            }
-
-            //鑾峰彇璁惧绫诲瀷
+            }  
+
+            //鑾峰彇璁惧绫诲瀷
             var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
             if (device.Type == DeviceType.OnOffSwitch)
             {
@@ -2207,6 +2212,12 @@
                 info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow;
                 info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1301;
             }
+            else if (iasZone.IasDeviceType == 541)
+            {
+                //鐞冨瀷绉诲姩浼犳劅鍣�
+                info.ConcreteType = DeviceConcreteType.Sensor_SphericalMotion;
+                info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1205;
+            }
         }
 
         #endregion
@@ -2219,12 +2230,21 @@
         private void InitRealDeviceRoomId()
         {
             this.dicDeviceRoomId = new Dictionary<string, string>();
-            string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
-            var strData = UserCenterLogic.LoadFileContent(fullName);
+            string fullName = DirNameResourse.DeviceRoomIdFile;
+            var strData = HdlFileLogic.Current.ReadFileTextContent(fullName);
             if (strData != null)
             {
                 this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
             }
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍏ㄩ儴鐗╃悊璁惧鎵�灞炴埧闂寸殑璁板綍
+        /// </summary>
+        /// <returns></returns>
+        public Dictionary<string, string> GetAllRealDeviceRoomData()
+        {
+            return this.dicDeviceRoomId;
         }
 
         /// <summary>
@@ -2278,8 +2298,7 @@
             if (save == true)
             {
                 //淇濆瓨璁板綍
-                string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
-                UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
+                HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
 
                 //娣诲姞鑷姩澶囦唤
                 HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
@@ -2299,7 +2318,7 @@
                 return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
             }
             var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
-            return HdlRoomLogic.Current.GetFloorRoomName(room);
+            return HdlRoomLogic.Current.GetRoomName(room);
         }
 
         /// <summary>
@@ -2347,8 +2366,7 @@
                 return;
             }
             //淇濆瓨璁板綍
-            string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
-            UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
+            HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
 
             //娣诲姞鑷姩澶囦唤
             HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
@@ -2443,42 +2461,9 @@
             list.Add(DeviceBeloneType.A浼犳劅鍣�);
 
             //鍏朵粬鐨勭湅鐫�鍔炲憲,閮芥槸鎺掑湪鍚庨潰鐨�,閮藉綊涓鸿繖涓睘鎬�
-            list.Add(DeviceBeloneType.A鏈煡璁惧);
-
+            list.Add(DeviceBeloneType.A鏈煡璁惧);
+            
             return list;
-        }
-
-        #endregion
-
-        #region 鈻� 鑾峰彇璁惧鍦ㄧ嚎鐘舵�佸垪琛╛______________
-
-        /// <summary>
-        /// 鑾峰彇璁惧鍦ㄧ嚎鐘舵�佸垪琛�(娉ㄦ剰,涓�涓澶囧彧杩斿洖涓�涓洖璺�)
-        /// </summary>
-        /// <param name="gwId">缃戝叧id</param>
-        /// <returns></returns>
-        public List<CommonDevice> GetDeviceOnlineList(string gwId)
-        {
-            var zbway = HdlGatewayLogic.Current.GetLocalGateway(gwId);
-            int statu = 0;
-            var listDevice = this.GetDeviceListFromGateway(zbway, ref statu, false, ShowErrorMode.NO);
-            if (statu == -1)
-            {
-                //褰撳嚭鐜板紓甯告椂,浣跨敤鍚庡鎿嶄綔,鐩存帴鑾峰彇鏈湴鐨勮澶囧垪琛�
-                listDevice = this.GetDeviceByGatewayID(gwId);
-            }
-
-            var listCheck = new HashSet<string>();
-            var listReturn = new List<CommonDevice>();
-            foreach (var device in listDevice)
-            {
-                if (listCheck.Contains(device.DeviceAddr) == false)
-                {
-                    listCheck.Add(device.DeviceAddr);
-                    listReturn.Add(device);
-                }
-            }
-            return listReturn;
         }
 
         #endregion
@@ -2526,8 +2511,8 @@
                 {
                     return false;
                 }
-            }
-            //2020.03.30杩藉姞寮忔牱:濡傛灉鏄潰鏉跨殑娓╁害鎺㈠ご,涓嶆樉绀�
+            }
+            //2020.03.30杩藉姞寮忔牱:濡傛灉鏄潰鏉跨殑娓╁害鎺㈠ご,涓嶆樉绀�
             else if (i_device.Type == DeviceType.TemperatureSensor && ((TemperatureSensor)i_device).SensorDiv == 1)
             {
                 var myInfoType = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
@@ -2540,20 +2525,20 @@
             {
                 //鏂伴鐨勬箍搴︿紶鎰熷櫒涓嶆樉绀�
                 return false;
-            }
-
-            //濡傛灉鏄柊椋庨潰鏉挎垨鐜闈㈡澘,鍒欓兘涓嶆樉绀轰换浣曞洖璺�
-            var myInfoTypeTemp = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
-            if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir || myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment)
-            {
-                return false;
-            }
-            else if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
-            {
-                if (i_device.Type != DeviceType.OnOffOutput)
-                {
-                    return false;
-                }
+            }
+
+            //濡傛灉鏄柊椋庨潰鏉挎垨鐜闈㈡澘,鍒欓兘涓嶆樉绀轰换浣曞洖璺�
+            var myInfoTypeTemp = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
+            if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir || myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment)
+            {
+                return false;
+            }
+            else if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
+            {
+                if (i_device.Type != DeviceType.OnOffOutput)
+                {
+                    return false;
+                }
             }
             return true;
         }
@@ -2913,6 +2898,8 @@
             mainDevice.ModelIdentifier = device.DeviceInfo.ModelIdentifier;
             //搴忓垪鍙�
             mainDevice.SerialNumber = device.DeviceInfo.ProductCode;
+            //璁惧鍔熻兘绫诲瀷
+            mainDevice.DfunctionType = (DeviceFunctionType)device.DeviceInfo.FunctionType;
 
             mainDevice.InClusterList.Clear();
             mainDevice.InClusterList.AddRange(device.DeviceInfo.InClusterList);
@@ -2939,6 +2926,11 @@
             else if (mainDevice.Type == DeviceType.DimmableLight)
             {
                 mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
+                if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
+                {
+                    //璋冨厜鍣ㄥ浐瀹氱伅鍏�
+                    this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A鐏厜);
+                }
                 if (mainDevice.IsCustomizeImage == false)
                 {
                     mainDevice.IconPath = "Device/Light.png";
@@ -2948,6 +2940,11 @@
             else if (mainDevice.Type == DeviceType.ColorTemperatureLight)
             {
                 mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
+                if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
+                {
+                    //鑹叉俯鐏浐瀹氱伅鍏�
+                    this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A鐏厜);
+                }
                 if (mainDevice.IsCustomizeImage == false)
                 {
                     mainDevice.IconPath = "Device/ColorLightTemperature.png";
@@ -2957,18 +2954,17 @@
             else if (mainDevice.Type == DeviceType.OnOffOutput)
             {
                 //2020.05.13鍙樻洿:缁х數鍣ㄩ兘榛樿涓虹伅鍏�
-                //var myType = this.GetHdlMyDeviceEnumInfo(mainDevice);
-                //if (myType != null && myType.ConcreteType == DeviceConcreteType.Relay_ThreeLoad)
+                if (mainDevice.DfunctionType == DeviceFunctionType.A鏈畾涔�)
                 {
-                    if (mainDevice.DfunctionType == DeviceFunctionType.A鏈畾涔�)
+                    mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
+                    if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
                     {
-                        mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
-                    }
-                    if (mainDevice.IsCustomizeImage == false)
-                    {
-                        mainDevice.IconPath = "Device/Light.png";
+                        //缁х數鍣ㄩ粯璁や负鐏厜
+                        this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A鐏厜);
                     }
                 }
+                //鏍规嵁鍔熻兘绫诲瀷,閲嶆柊璁剧疆璁惧鍥炶矾鍥炬爣
+                this.ResetIconPathByDeviceFunctionType(mainDevice);
             }
             //濡傛灉鏄┖姘斿紑鍏崇殑璇�
             else if (mainDevice.Type == DeviceType.AirSwitch)
@@ -2977,20 +2973,52 @@
                 if (mainDevice.DfunctionType == DeviceFunctionType.A鏈畾涔�)
                 {
                     mainDevice.DfunctionType = DeviceFunctionType.A寮�鍏�;
+                    if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A寮�鍏�)
+                    {
+                        //绌烘皵寮�鍏抽粯璁や负寮�鍏�
+                        this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A寮�鍏�);
+                    }
                 }
-                if (mainDevice.IsCustomizeImage == false)
-                {
-                    mainDevice.IconPath = "Device/Switch.png";
-                }
+                //鏍规嵁鍔熻兘绫诲瀷,閲嶆柊璁剧疆璁惧鍥炶矾鍥炬爣
+                this.ResetIconPathByDeviceFunctionType(mainDevice);
             }
             //濡傛灉鏄僵鐏殑璇�
             else if (mainDevice.Type == DeviceType.ColorDimmableLight)
             {
                 mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
+                if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
+                {
+                    //褰╃伅榛樿涓哄紑鍏�
+                    this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A鐏厜);
+                }
                 if (mainDevice.IsCustomizeImage == false)
                 {
                     mainDevice.IconPath = "Device/ColorLight.png";
                 }
+            }
+        }
+
+        /// <summary>
+        /// 鏍规嵁鍔熻兘绫诲瀷,閲嶆柊璁剧疆璁惧鍥炶矾鍥炬爣
+        /// </summary>
+        /// <param name="device"></param>
+        private void ResetIconPathByDeviceFunctionType(CommonDevice device)
+        {
+            if (device.IsCustomizeImage == true)
+            {
+                return;
+            }
+            if (device.DfunctionType == DeviceFunctionType.A寮�鍏�)
+            {
+                device.IconPath = "Device/Switch.png";
+            }
+            else if (device.DfunctionType == DeviceFunctionType.A鎻掑骇)
+            {
+                device.IconPath = "Device/Socket1.png";
+            }
+            else
+            {
+                device.IconPath = "Device/Light.png";
             }
         }
 
@@ -3111,6 +3139,7 @@
 
             //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄=========
             this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200-60000";//pir浼犳劅鍣�220
+            this.dicDeviceModelIdEnum["MSPIRB-ZB.10"] = "1205-1200-60000";//鐞冨瀷绉诲姩浼犳劅鍣�
 
             //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄=========
             //杩欓噷鏄害涔愬厠鐨�
@@ -3300,6 +3329,10 @@
         /// pir浼犳劅鍣�220 闀滃儚id锛�1200
         /// </summary>
         Sensor_Pir = 1200,
+        /// <summary>
+        /// 鐞冨舰绉诲姩浼犳劅鍣� 闀滃儚id锛�1205
+        /// </summary>
+        Sensor_SphericalMotion = 1205,
 
         //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄=========
         /// <summary>
@@ -3368,9 +3401,9 @@
         /// <summary>
         /// 鏂规偊鏂伴灏忔ā鍧� 闀滃儚id锛�2310
         /// </summary>
-        Relay_FangyueFreshAirModul = 2310,
-
-        //=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄=========
+        Relay_FangyueFreshAirModul = 2310,
+		
+        //=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄=========
         /// <summary>
         /// 璋冨厜鍣�
         /// </summary>

--
Gitblit v1.8.0