From acb2b278663952ce555b06a2e821f359225f15e0 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期五, 10 七月 2020 09:41:15 +0800
Subject: [PATCH] 备份

---
 ZigbeeApp/Shared/Common/Device.cs |  335 ++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 220 insertions(+), 115 deletions(-)

diff --git a/Home0630/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
similarity index 95%
rename from Home0630/Shared/Common/Device.cs
rename to ZigbeeApp/Shared/Common/Device.cs
index fdeebb2..b35be85 100644
--- a/Home0630/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -249,6 +249,7 @@
             }
 
             //娣诲姞璁惧鐨勭紦瀛�
+            var listDriveDevice = new List<CommonDevice>();
             for (int i = 0; i < listDevice.Count; i++)
             {
                 var device = listDevice[i];
@@ -259,7 +260,7 @@
                 //娣诲姞缂撳瓨
                 this.AddDeviceToMemory(ref device);
 
-                //绉婚櫎瀛樺湪鐨勮澶囧唴瀛�
+                //绉婚櫎瀛樺湪鐨勮澶囧唴瀛� 
                 string maikey = this.GetDeviceMainKeys(device);
                 if (dicExist.ContainsKey(maikey) == true)
                 {
@@ -267,24 +268,27 @@
                 }
                 //鑾峰彇璁惧鐨勫浐瀹氬睘鎬�
                 HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device);
-            }
-
-            for (int i = 0; i < listDevice.Count; i++)
-            {
-                var device = listDevice[i];
                 //瀵规湭鍛藉悕鐨勮櫄鎷熻澶囬噸鏂板懡鍚�
                 if (device.DriveCode > 0 && this.GetSimpleEpointName(device) == string.Empty)
                 {
-                    //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О
-                    var dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false);
-                    //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍�
-                    dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
-
-                    HdlThreadLogic.Current.RunThread(() =>
-                    {
-                        this.ReName(device, dName, ShowErrorMode.NO);
-                    });
+                    listDriveDevice.Add(device);
                 }
+            }
+            if (listDriveDevice.Count > 0)
+            {
+                //濡傛灉铏氭嫙璁惧杩樻病鏈夊悕瀛楃殑璇�
+                HdlThreadLogic.Current.RunThread(() =>
+                {
+                    //濡傛灉涓嶈繖鏍锋斁鍦ㄤ竴涓嚎绋嬮噷,鏈夊彲鑳藉Dictionary浜х敓褰卞搷
+                    foreach (var myDevice in listDriveDevice)
+                    {
+                        //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О
+                        var dName = this.GetDeviceObjectText(new List<CommonDevice>() { myDevice }, false);
+                        //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍�
+                        dName += "(" + myDevice.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
+                        this.ReName(myDevice, dName, ShowErrorMode.NO);
+                    }
+                });
             }
 
             //鍙湁瀹屽叏鑾峰彇鐨勬椂鍊�,鎵嶄細鍘诲鐞嗗垹闄ょ殑闂
@@ -705,8 +709,8 @@
                 this.SaveRealDeviceRoomId(null, null);
             }
             return true;
-        }
-
+        }
+
         /// <summary>
         /// 鍒犻櫎缂撳瓨鐨勪竴鑸澶�
         /// </summary>
@@ -788,12 +792,41 @@
                 }
                 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)
+                {
+                    //鍚屾鍒犻櫎澶辫触
+                    string msg = Language.StringByID(R.MyInternationalizationString.SynchronizationFailed);
+                    //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                    msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
 
+                    this.ShowErrorMsg(msg);
+                    return false;
+                }
+            }
+            return true;
+        }
+        #endregion
+
+
+
         #region 鈻� 娴嬭瘯璁惧___________________________
-
+
         /// <summary>
         /// 鍙戦�佸畾浣嶆寚浠ゅ埌璁惧
         /// </summary>
@@ -838,6 +871,22 @@
                     return true;
                 }
             }
+            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;
+            }
             return false;
         }
 
@@ -970,94 +1019,95 @@
             return list;
         }
 
-        /// <summary>
-        /// 鏍规嵁MAC鍦板潃,鑾峰彇绠�绾﹂潰鏉垮叏閮ㄥ洖璺殑璁惧瀵硅薄
-        /// </summary>
-        /// <param name="listDevice"></param>
+        /// <summary>
+        /// 鏍规嵁MAC鍦板潃,鑾峰彇绠�绾﹂潰鏉垮叏閮ㄥ洖璺殑璁惧瀵硅薄
+        /// </summary>
+        /// <param name="listDevice"></param>
         /// <returns></returns>
-        public List<CommonDevice> GetMutilfunctionPanelByMac(List<CommonDevice> listDevice, bool sort = true)
+        public List<CommonDevice> GetMutilfunctionPanelByMac(List<CommonDevice> listDevice, bool sort = true)
+        {
+            //鍜屽姜鍝ャ�佽澶囧拰浜у搧閮ㄥ悓浜嬬‘璁わ細
+            //绠�绾﹀鍔熻兘闈㈡澘[涓嶆樉绀哄浣欑殑鍥炶矾锛屽彧鏄剧ず鎼哄甫鐨�2涓户鐢靛櫒锛�1涓俯搴︿紶鎰熷櫒锛�1涓箍搴︿紶鎰熷櫒
+            var list = new List<CommonDevice>();
+            foreach (var dev in listDevice)
+            {
+                if (dev.Type == DeviceType.TemperatureSensor)
+                {
+                    if (dev.DeviceEpoint == 64)
+                    {
+                        list.Add(dev);
+                    }
+                }
+                else if (dev.Type == DeviceType.FreshAirHumiditySensor)
+                {
+                    if (dev.DeviceEpoint == 65)
+                    {
+                        list.Add(dev);
+                    }
+                }
+                else if (dev.Type == DeviceType.OnOffOutput)
+                {
+                    list.Add(dev);
+                }
+            }
+
+            if (sort == false)
+            {
+                return list;
+            }
+            list.Sort((obj1, obj2) =>
+            {
+                if (obj1.DeviceEpoint > obj2.DeviceEpoint)
+                {
+                    return 1;
+                }
+                return -1;
+            });
+
+            return list;
+        }
+
+        /// <summary>
+        /// 鏍规嵁MAC鍦板潃,鑾峰彇鏂伴銆佺畝绾︾幆澧冮潰鏉垮叏閮ㄥ洖璺殑璁惧瀵硅薄
+        /// </summary>
+        /// <param name="listDevice"></param>
+        /// <returns></returns>
+        public List<CommonDevice> GetPanelMatchEpointByMac(List<CommonDevice> listDevice, bool sort = true)
         {
-            //鍜屽姜鍝ャ�佽澶囧拰浜у搧閮ㄥ悓浜嬬‘璁わ細
-            //绠�绾﹀鍔熻兘闈㈡澘[涓嶆樉绀哄浣欑殑鍥炶矾锛屽彧鏄剧ず鎼哄甫鐨�2涓户鐢靛櫒锛�1涓俯搴︿紶鎰熷櫒锛�1涓箍搴︿紶鎰熷櫒
-            var list = new List<CommonDevice>();
-            foreach (var dev in listDevice)
-            {
-                if (dev.Type == DeviceType.TemperatureSensor)
-                {
-                    if (dev.DeviceEpoint == 64)
-                    {
-                        list.Add(dev);
-                    }
+            var list = new List<CommonDevice>();
+            foreach (var dev in listDevice)
+            {
+                if (dev.Type == DeviceType.TemperatureSensor)
+                {
+                    list.Add(dev);
+                }
+                else if (dev.Type == DeviceType.FreshAirHumiditySensor)
+                {
+                    list.Add(dev);
                 }
-                else if (dev.Type == DeviceType.FreshAirHumiditySensor)
-                {
-                    if (dev.DeviceEpoint == 65)
-                    {
-                        list.Add(dev);
-                    }
-                }
-                else if (dev.Type == DeviceType.OnOffOutput)
-                {
-                    list.Add(dev);
-                }
-            }
-
+            }
             if (sort == false)
             {
                 return list;
             }
             list.Sort((obj1, obj2) =>
-            {
-                if (obj1.DeviceEpoint > obj2.DeviceEpoint)
-                {
-                    return 1;
-                }
-                return -1;
-            });
-
-            return list;
-        }
-
-        /// <summary>
-        /// 鏍规嵁MAC鍦板潃,鑾峰彇鏂伴銆佺畝绾︾幆澧冮潰鏉垮叏閮ㄥ洖璺殑璁惧瀵硅薄
-        /// </summary>
-        /// <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)
-            {
-                if (dev.Type == DeviceType.TemperatureSensor)
-                {
-                    list.Add(dev);
-                }
-                else if (dev.Type == DeviceType.FreshAirHumiditySensor)
-                {
-                    list.Add(dev);
-                }  
-            }
-            if (sort == false)
             {
-                return list;
-            } 
-            list.Sort((obj1, obj2) => {
 
-                if (obj1.DeviceEpoint > obj2.DeviceEpoint)
-                {
-                    return 1;
+                if (obj1.DeviceEpoint > obj2.DeviceEpoint)
+                {
+                    return 1;
                 }
                 return -1;
-            }); 
+            });
             return list;
         }
 
-            /// <summary>
-            /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勮澶囧璞�(寮哄埗鎺掑簭)
-            /// </summary>
-            /// <param name="DeviceAddr">Mac鍦板潃</param>
-            /// <returns></returns>
-            public List<CommonDevice> GetDevicesByMac(List<string> listMacAddr)
+        /// <summary>
+        /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勮澶囧璞�(寮哄埗鎺掑簭)
+        /// </summary>
+        /// <param name="DeviceAddr">Mac鍦板潃</param>
+        /// <returns></returns>
+        public List<CommonDevice> GetDevicesByMac(List<string> listMacAddr)
         {
             //鍏堟帓搴�
             listMacAddr.Sort();
@@ -1167,6 +1217,56 @@
 
         #endregion
 
+        #region 鈻� 鑾峰彇璁惧淇℃伅_______________________
+
+        /// <summary>
+        /// 璇诲彇鍗曚釜绔偣鍥炶矾璁惧淇℃伅
+        /// </summary>
+        /// <param name="device">璁惧瀵硅薄</param>
+        /// <returns></returns>
+        public CommonDevice.DeviceInfoData ReadDeviceEpointDeviceInfo(CommonDevice device)
+        {
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 80 } };
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "GetStatusRecord", jObject.ToString(), "GetStatusRecord_Respon");
+            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+            {
+                return null;
+            }
+            var info = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(result.ReceiptData);
+            return info;
+        }
+
+        #endregion
+
+        #region 鈻� 璁剧疆璁惧鍔熻兘绫诲瀷___________________
+
+        /// <summary>
+        /// 璁剧疆璁惧鍔熻兘绫诲瀷鍒扮綉鍏�
+        /// </summary>
+        /// <param name="device">璁惧鍥炶矾</param>
+        /// <param name="functionType">鍔熻兘绫诲瀷</param>
+        /// <returns></returns>
+        public bool SendDeviceFunctionTypeToGateway(CommonDevice device, DeviceFunctionType functionType)
+        {
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 110 } };
+            var data = new Newtonsoft.Json.Linq.JObject { { "FunctionType", (int)functionType } };
+            jObject.Add("Data", data);
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Device/SetEPDeviceFunctionType", jObject.ToString(), "Device/SetEPDeviceFunctionTypeRespon");
+            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+            {
+                return false;
+            }
+            var resultData = Newtonsoft.Json.Linq.JObject.Parse(result.ReceiptData);
+            if (resultData.Property("Result") != null)
+            {
+                //0:淇敼鎴愬姛 1:淇敼澶辫触
+                return resultData["Result"].ToString() == "0";
+            }
+            return false;
+        }
+
+        #endregion
+
         #region 鈻� 鑾峰彇璁惧鍚嶇О_______________________
 
         /// <summary>
@@ -1211,21 +1311,20 @@
             }
 
             if (device.Type == DeviceType.OnOffOutput
-                || device.Type == DeviceType.DimmableLight
+                || device.Type == DeviceType.DimmableLight
                 || device.Type == DeviceType.ColorDimmableLight
                 || device.Type == DeviceType.ColorTemperatureLight)
             {
                 //缁х數鍣�,鎺夊厜鍣ㄩ兘鍙洖璺�
                 return Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + epointNo;
             }
-            //寰愭浜�20200630璋冩暣杩欓噷浠g爜锛岃鍚堝苟
             if (device.Type == DeviceType.Thermostat)
             {
                 //绌鸿皟閮藉彨瀹ゅ唴鏈�
                 return Language.StringByID(R.MyInternationalizationString.uIndoorUnit) + epointNo;
-            }  
-
-            //鑾峰彇璁惧绫诲瀷
+            }
+
+            //鑾峰彇璁惧绫诲瀷
             var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
             if (device.Type == DeviceType.OnOffSwitch)
             {
@@ -2396,7 +2495,7 @@
             var listDevice = this.GetDevicesByMac(i_device.DeviceAddr, false);
             foreach (var device in listDevice)
             {
-                //0:绂荤嚎 1:鍦ㄧ嚎 2:姝e湪鍒锋柊鐘舵��
+                //0:绂荤嚎 1:鍦ㄧ嚎 2:姝e湪鍒锋柊鐘舵�� 
                 bool statu = i_device.IsOnline == 1 || i_device.IsOnline == 2;
                 if (statu == true)
                 {
@@ -2427,17 +2526,8 @@
                 {
                     return false;
                 }
-            }
-            //濡傛灉鏄柊椋庨潰鏉跨殑鏂伴璁惧,鍒欎笉鏄剧ず
-            else if (i_device.Type == DeviceType.FreshAir)
-            {
-                var myInfoType = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
-                if (myInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir)
-                {
-                    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 });
@@ -2450,6 +2540,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;
+                }
             }
             return true;
         }
@@ -3026,7 +3130,7 @@
             this.dicDeviceModelIdEnum["MGCD01/M-ZB.10"] = "1306-1200-60000";//鍚搁《鐕冩皵浼犳劅鍣�
 
             //PM2.5绌烘皵璐ㄩ噺浼犳劅鍣� 銆愯璁惧灞炰簬绗笁鏂硅澶囷紝娌℃湁闀滃儚ID銆�
-            this.dicDeviceModelIdEnum["MSPM25/M-ZB.10"] = "1307-1200-60000";//PM2.5绌烘皵璐ㄩ噺浼犳劅鍣�
+            this.dicDeviceModelIdEnum["MSPM25/M-ZB.10"] = "1307-1200-60000";//PM2.5绌烘皵璐ㄩ噺浼犳劅鍣� 
 
             //=========鈽呪槄缁х數鍣ㄧ被(2300-2499)鈽呪槄=========
             this.dicDeviceModelIdEnum["MPR0310-ZB.10"] = "2300-2300-60001";//3璺户鐢靛櫒灏忔ā鍧�
@@ -3178,14 +3282,15 @@
         /// 绐楀笜闈㈡澘 闀滃儚id锛�256
         /// </summary>
         ButtonPanel_Curtain = 256,
-        /// <summary>
-        /// 绠�绾﹀鍔熻兘闈㈡澘 闀滃儚ID锛�212
+        /// <summary>
+        /// 绠�绾﹀鍔熻兘闈㈡澘 闀滃儚ID锛�212
         /// </summary>
         ButtonPanel_SimpleMultifunction = 212,
-        /// <summary>
-        /// 绠�绾︾幆澧冮潰鏉�
+        /// <summary>
+        /// 绠�绾︾幆澧冮潰鏉�
         /// </summary>
         ButtonPanel_SimpleEnvironment = 230,
+
         //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄=========
         /// <summary>
         /// 浼犳劅鍣�

--
Gitblit v1.8.0