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 |  553 +++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 417 insertions(+), 136 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 6431441..1435f45 100755
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -123,12 +123,6 @@
 
                 if (device == null || device.CurrentGateWayId == null)
                 {
-#if DEBUG
-                    //璋冩煡,涓轰粈涔堝畠浼氭妸鍏ㄩ儴璁惧鍒犳帀锛�
-                    string file1 = UserCenterLogic.CombinePath(file);
-                    string file2 = UserCenterLogic.CombinePath("Back_" + file);
-                    System.IO.File.Copy(file1, file2, true);
-#endif
                     //澶辨晥鐨勬枃浠讹紝娌℃湁缃戝叧id鐨勯兘鍒犻櫎鎺�
                     Global.DeleteFilebyHomeId(file);
                     continue;
@@ -143,12 +137,6 @@
                     }
                     else
                     {
-#if DEBUG
-                        //璋冩煡,涓轰粈涔堝畠浼氭妸鍏ㄩ儴璁惧鍒犳帀锛�
-                        string file1 = UserCenterLogic.CombinePath(file);
-                        string file2 = UserCenterLogic.CombinePath("Back_" + file);
-                        System.IO.File.Copy(file1, file2, true);
-#endif
                         //濡傛灉鏄富浜�,鎴栬�呯鐞嗗憳,閭d箞杩欎釜鏂囦欢鏄潪娉曠殑,鐩存帴鍒犻櫎
                         Global.DeleteFilebyHomeId(file);
                         continue;
@@ -211,7 +199,7 @@
             var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
             foreach (var gateway in listGateway)
             {
-                string gwId = HdlGatewayLogic.Current.GetGatewayId(gateway);
+                string gwId = gateway.GwId;
                 if (listId.Contains(gwId) == false)
                 {
                     //杩欎釜缃戝叧瀵逛簬褰撳墠杩欎釜鎴愬憳鏉ヨ鏄潪娉曠殑
@@ -242,7 +230,7 @@
             listDevice.AddRange(list);
 
             //鑾峰彇杩欎釜缃戝叧鐨勬湰鍦版墍鏈夎澶�
-            string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
+            string gwID = zbGateway.GwId;
             List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID);
             //鑾峰彇ota璁惧
             foreach (var ota in this.dicOTADevice.Values)
@@ -261,6 +249,7 @@
             }
 
             //娣诲姞璁惧鐨勭紦瀛�
+            var listDriveDevice = new List<CommonDevice>();
             for (int i = 0; i < listDevice.Count; i++)
             {
                 var device = listDevice[i];
@@ -279,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);
+                    }
+                });
             }
 
             //鍙湁瀹屽叏鑾峰彇鐨勬椂鍊�,鎵嶄細鍘诲鐞嗗垹闄ょ殑闂
@@ -442,7 +434,7 @@
             if (Common.Config.Instance.Home.IsVirtually == true)
             {
                 //淇敼璁惧鍚嶅瓧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
-                Phone.UserView.UserPage.Instance.RefreshForm = true;
+                Phone.UserView.UserPage.Instance.RefreshAllForm = true;
                 return true;
             }
 
@@ -466,7 +458,7 @@
                 }
             }
             //淇敼璁惧鍚嶅瓧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
-            Phone.UserView.UserPage.Instance.RefreshForm = true;
+            Phone.UserView.UserPage.Instance.RefreshAllForm = true;
             return true;
         }
 
@@ -559,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;
@@ -586,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;
@@ -680,22 +672,26 @@
         /// <param name="listdevice">璁惧瀵硅薄(MAC鍦板潃蹇呴』瑕佺浉鍚�)</param>
         public async Task<bool> DeleteDevice(List<CommonDevice> listdevice)
         {
-            var data = new CommonDevice.RemoveDeviceData();
-            var info = new CommonDevice.RemoveDeviceListInfo();
-            info.DeviceAddr = listdevice[0].DeviceAddr;
-            data.DeviceAddrList.Add(info);
-
-            //鍒犱竴娆$殑鏃跺�欙紝瀹冧細鎶奙AC鍦板潃涓嬮潰鍏ㄩ儴鐨勮澶囬兘鍒犻櫎
-            var result = await listdevice[0].DeleteDeviceAsync(data);
-            if (result == null || result.removeDeviceResponseData == null || result.removeDeviceResponseData.Result != 0)
+            //铏氭嫙浣忓畢鐨勮瘽,涓嶉渶瑕佸垹闄ょ綉鍏崇殑璁惧
+            if (Config.Instance.Home.IsVirtually == false)
             {
-                //璁惧鍒犻櫎澶辫触
-                string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail);
-                //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
-                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+                var data = new CommonDevice.RemoveDeviceData();
+                var info = new CommonDevice.RemoveDeviceListInfo();
+                info.DeviceAddr = listdevice[0].DeviceAddr;
+                data.DeviceAddrList.Add(info);
 
-                this.ShowErrorMsg(msg);
-                return false;
+                //鍒犱竴娆$殑鏃跺�欙紝瀹冧細鎶奙AC鍦板潃涓嬮潰鍏ㄩ儴鐨勮澶囬兘鍒犻櫎
+                var result = await listdevice[0].DeleteDeviceAsync(data);
+                if (result == null || result.removeDeviceResponseData == null || result.removeDeviceResponseData.Result != 0)
+                {
+                    //璁惧鍒犻櫎澶辫触
+                    string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail);
+                    //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+                    msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+
+                    this.ShowErrorMsg(msg);
+                    return false;
+                }
             }
 
             //鍒犻櫎缂撳瓨鐨凮ta璁惧
@@ -723,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)
             {
@@ -800,6 +796,35 @@
 
         #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>
@@ -835,6 +860,11 @@
                     //浼犳劅鍣ㄩ櫎浜哖ir閮芥病鏈夊畾浣嶅姛鑳�
                     return true;
                 }
+                else if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_SphericalMotion)
+                {
+                    //鐞冨瀷绉诲姩浼犳劅鍣ㄨ櫧鐒舵槸鐢垫睜璁惧,浣嗘槸瀹冩湁瀹氫綅鍔熻兘
+                    return true;
+                }
                 return false;
             }
 
@@ -845,6 +875,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;
         }
@@ -979,6 +1025,89 @@
         }
 
         /// <summary>
+        /// 鏍规嵁MAC鍦板潃,鑾峰彇绠�绾﹂潰鏉垮叏閮ㄥ洖璺殑璁惧瀵硅薄
+        /// </summary>
+        /// <param name="listDevice"></param>
+        /// <returns></returns>
+        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)
+        { 
+            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;
+                }
+                return -1;
+            }); 
+            return list;
+        }
+
+        /// <summary>
         /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勮澶囧璞�(寮哄埗鎺掑簭)
         /// </summary>
         /// <param name="DeviceAddr">Mac鍦板潃</param>
@@ -1032,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)
             {
@@ -1093,6 +1222,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>
@@ -1107,6 +1286,12 @@
             {
                 return dName;
             }
+            if (this.IsMiniLight(device) == true)
+            {
+                //Mini澶滅伅
+                return Language.StringByID(R.MyInternationalizationString.uMiniNightLight);
+            }
+
             //濡傛灉杩欎釜璁惧鍙湁涓�涓洖璺殑璇�,杩斿洖Mac鍚嶅瓧缁欏畠
             if (this.GetDevicesCountByMac(device.DeviceAddr) <= 1)
             {
@@ -1131,7 +1316,9 @@
             }
 
             if (device.Type == DeviceType.OnOffOutput
-                || device.Type == DeviceType.DimmableLight || device.Type == DeviceType.ColorDimmableLight)
+                || device.Type == DeviceType.DimmableLight 
+                || device.Type == DeviceType.ColorDimmableLight
+                || device.Type == DeviceType.ColorTemperatureLight)
             {
                 //缁х數鍣�,鎺夊厜鍣ㄩ兘鍙洖璺�
                 return Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + epointNo;
@@ -1140,17 +1327,7 @@
             {
                 //绌鸿皟閮藉彨瀹ゅ唴鏈�
                 return Language.StringByID(R.MyInternationalizationString.uIndoorUnit) + epointNo;
-            }
-            else if (device.Type == DeviceType.FreshAir)
-            {
-                //鏂伴闈㈡澘涓殑鎸夐敭鍙柊椋�
-                return Language.StringByID(R.MyInternationalizationString.FreshAir);
-            }
-            else if (device.Type == DeviceType.FreshAirHumiditySensor)
-            {
-                //鏂伴闈㈡澘婀垮害浼犳劅鍣�
-                return Language.StringByID(R.MyInternationalizationString.HumiditySensor);
-            }
+            }  
 
             //鑾峰彇璁惧绫诲瀷
             var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
@@ -1167,12 +1344,19 @@
                     return Language.StringByID(R.MyInternationalizationString.uDeviceBelongId16) + epointNo;
                 }
             }
+            else if (device.Type == DeviceType.FreshAirHumiditySensor)
+            {
+                //鏂伴闈㈡澘/绠�绾﹀鍔熻兘/绠�绾︾幆澧冮潰鏉挎箍搴︿紶鎰熷櫒
+                return Language.StringByID(deviceInfoType.DefultNameId) + Language.StringByID(R.MyInternationalizationString.HumiditySensor);
+            }
             else if (device.Type == DeviceType.TemperatureSensor)
             {
-                if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir)
+                if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir
+                    || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment
+                    || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
                 {
-                    //鏂伴闈㈡澘涓殑Thermostat涓烘俯搴︿紶鎰熷櫒
-                    return Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
+                    //鏂伴闈㈡澘/绠�绾﹀鍔熻兘/绠�绾︾幆澧冮潰鏉� 娓╁害浼犳劅鍣�
+                    return Language.StringByID(deviceInfoType.DefultNameId) + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
                 }
                 else if (deviceInfoType.BeloneType == DeviceBeloneType.A鎸夐敭闈㈡澘)
                 {
@@ -1195,6 +1379,11 @@
             if (string.IsNullOrEmpty(dName) == false)
             {
                 return dName;
+            }
+            if (this.IsMiniLight(device) == true)
+            {
+                //Mini澶滅伅
+                return Language.StringByID(R.MyInternationalizationString.uMiniNightLight);
             }
 
             //鑾峰彇璁惧绫诲瀷
@@ -1945,6 +2134,14 @@
                 info.ConcreteType = DeviceConcreteType.Sensor_PMTwoPointFive;
                 info.ObjectTypeNameId = 60000;//浼犳劅鍣�
             }
+            //16鑹叉俯鐏�
+            else if (dicType.ContainsKey(DeviceType.ColorTemperatureLight) == true)
+            {
+                info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId20000;
+                info.BeloneType = DeviceBeloneType.A褰╃伅;
+                info.ConcreteType = DeviceConcreteType.ColorLight_Temperature;
+                info.ObjectTypeNameId = 60007;//璋冨厜妯″潡
+            }
 
             int value = (int)info.BeloneType;
             if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + value) == true)
@@ -2015,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
@@ -2027,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>
@@ -2075,7 +2287,7 @@
                 {
                     //2020.05.18杩藉姞:濡傛灉璁板綍鐨勬埧闂碔D鏄笉瀛樺湪鐨勮瘽,鍒欓噸鏂拌鐩�
                     var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[listDevice[0].DeviceAddr]);
-                    if (room == null)
+                    if (room == null || this.dicDeviceRoomId[listDevice[0].DeviceAddr] != roomId)
                     {
                         this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
                         save = true;
@@ -2086,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);
@@ -2107,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>
@@ -2155,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);
@@ -2258,39 +2468,6 @@
 
         #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
-
         #region 鈻� 涓�鑸柟娉昣__________________________
 
         /// <summary>
@@ -2329,16 +2506,8 @@
             if (i_device.Type == DeviceType.OnOffOutput || i_device.Type == DeviceType.AirSwitch)
             {
                 //2020.03.23杩藉姞寮忔牱:鏈寚瀹氱被鍨嬬殑缁х數鍣�,涓嶆樉绀�
-                if (i_device.DfunctionType == DeviceFunctionType.A鏈畾涔�)
-                {
-                    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)
+                if (i_device.DfunctionType == DeviceFunctionType.A鏈畾涔�
+                    || i_device.DfunctionType == DeviceFunctionType.A涓嶆寚瀹�)
                 {
                     return false;
                 }
@@ -2348,6 +2517,25 @@
             {
                 var myInfoType = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
                 if (myInfoType.BeloneType == DeviceBeloneType.A鎸夐敭闈㈡澘)
+                {
+                    return false;
+                }
+            }
+            else if (i_device.Type == DeviceType.FreshAirHumiditySensor)
+            {
+                //鏂伴鐨勬箍搴︿紶鎰熷櫒涓嶆樉绀�
+                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;
                 }
@@ -2363,6 +2551,16 @@
         public bool IsHdlDevice(CommonDevice device)
         {
             return device.ManufacturerName == "HDL";
+        }
+
+        /// <summary>
+        /// 鏄惁鏄疢ini澶滅伅
+        /// </summary>
+        /// <param name="device"></param>
+        /// <returns></returns>
+        public bool IsMiniLight(CommonDevice device)
+        {
+            return device.DriveCode != 0 && device.Type == DeviceType.ColorTemperatureLight;
         }
 
         /// <summary>
@@ -2409,16 +2607,22 @@
         /// <returns></returns>
         public string AppendVersion(int versionValue)
         {
+            //10101 3涓猙yte  鏄剧ず涓猴細ver.1.01.01
+            //涓棿閭d釜byte涓哄鏁版椂锛屼唬琛ㄦ槸娴嬭瘯鐗堟湰,鍦ㄦ樉绀烘渶鏂扮増鏈椂,涓嶉渶瑕佹樉绀猴紝浣嗘槸鍦ㄥ巻鍙茬増鏈偅閲屽彲浠ユ樉绀�
+            //涓棿閭d釜byte涓哄伓鏁版椂, 浠h〃鏄寮忕増鏈�
+
             //鐩存帴鏄�10杩涘埗
-            string txt10 = Convert.ToString(versionValue).PadLeft(4, '0');
-            //杩欎釜鏄皬鏁扮偣鍓嶉潰鐨勫��
-            int value1 = Convert.ToInt32(txt10.Substring(0, txt10.Length - 2));
-            //杩欎釜鏄皬鏁扮偣鍚庨潰鐨勫��
-            int value2 = Convert.ToInt32(txt10.Substring(txt10.Length - 2, 2));
+            string txt10 = Convert.ToString(versionValue).PadLeft(6, '0');
+            //杩欎釜鏄涓�浣�
+            int value1 = Convert.ToInt32(txt10.Substring(0, 2));
+            //杩欎釜鏄浜屼綅
+            string value2 = txt10.Substring(2, 2);
+            //杩欎釜鏄涓変綅
+            string value3 = txt10.Substring(4, 2);
 
             //Ver.
             string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation);
-            return ver + value1 + "." + value2.ToString().PadLeft(2, '0');
+            return ver + value1 + "." + value2 + "." + value3;
         }
 
         /// <summary>
@@ -2470,7 +2674,7 @@
                 {
                     //涓嶆棤瑙嗘椂闂�,杩斿洖鏈湴璁惧鍒楄〃
                     statu = 1;
-                    return this.GetDeviceByGatewayID(HdlGatewayLogic.Current.GetGatewayId(zbGateway));
+                    return this.GetDeviceByGatewayID(zbGateway.GwId);
                 }
             }
             zbGateway.LastDateTime = DateTime.Now;
@@ -2494,7 +2698,7 @@
             //鏄惁杈炬垚涓柇鐨勬椂鏈�
             bool canBreak = false;
             //缃戝叧ID
-            string gatewayID = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
+            string gatewayID = zbGateway.GwId;
             //瓒呮椂鏃堕棿
             int TimeOut = 0;
             //璁惧鎬绘暟
@@ -2631,7 +2835,7 @@
         /// <returns></returns>
         private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, ZbGateway zbGateway)
         {
-            string gwId = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
+            string gwId = zbGateway.GwId;
 
             //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
             CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType);
@@ -2694,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);
@@ -2720,27 +2926,45 @@
             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";
+                }
+            }
+            //濡傛灉鏄壊娓╃伅
+            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";
                 }
             }
             //濡傛灉鏄笁璺户鐢靛櫒鐨勫洖璺殑璇�,榛樿涓虹伅鍏�
             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)
@@ -2749,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";
             }
         }
 
@@ -2778,10 +3034,13 @@
             //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
             if (deviceType == DeviceType.ColorDimmableLight) { device = new ColorDimmableLight(); }
             else if (deviceType == DeviceType.DimmableLight) { device = new DimmableLight(); }
+            else if (deviceType == DeviceType.ColorDimmerSwitch) { device = new ColorDimmerSwitch(); }
+            else if (deviceType == DeviceType.LevelControlSwitch) { device = new LevelControlSwitch(); }
             else if (deviceType == DeviceType.OnOffSwitch) { device = new Panel(); }
             else if (deviceType == DeviceType.OnOffOutput) { device = new ToggleLight(); }
             else if (deviceType == DeviceType.AirSwitch) { device = new AirSwitch(); }
             else if (deviceType == DeviceType.WindowCoveringDevice) { device = new Rollershade(); }
+            else if (deviceType == DeviceType.WindowCoveringController) { device = new WindowCoveringController(); }
             else if (deviceType == DeviceType.IASZone) { device = new IASZone(); }
             else if (deviceType == DeviceType.Repeater) { device = new Repeater(); }
             else if (deviceType == DeviceType.Thermostat) { device = new AC(); }
@@ -2790,6 +3049,8 @@
             else if (deviceType == DeviceType.TemperatureSensor) { device = new TemperatureSensor(); }
             else if (deviceType == DeviceType.PMSensor) { device = new PMSensor(); }
             else if (deviceType == DeviceType.FreshAirHumiditySensor) { device = new HumiditySensor(); }
+            else if (deviceType == DeviceType.ColorTemperatureLight) { device = new ColorTemperatureLight(); }
+            else if (deviceType == DeviceType.Buzzer) { device = new Buzzer(); }
             else if (deviceType == DeviceType.OtaDevice || deviceType == DeviceType.OtaPanelDevice) { device = new OTADevice(); }
             else { return null; }
 
@@ -2872,9 +3133,13 @@
             this.dicDeviceModelIdEnum["MPFA/TILE-ZB.18"] = "250-200-60003";//鏂规偊鏂伴闈㈡澘
             this.dicDeviceModelIdEnum["MPTE3/TILE-ZB.18"] = "253-200-60003";//鏂规偊鐜闈㈡澘
             this.dicDeviceModelIdEnum["MP2W/TILE-ZB.18"] = "256-200-60003";//绐楀笜闈㈡澘
+            this.dicDeviceModelIdEnum["MPTL4C/S-ZB.18"] = "212-200-60003";//绠�绾﹀鍔熻兘闈㈡澘
+            this.dicDeviceModelIdEnum["MPTE3/S-ZB.18"] = "230-200-60003";//绠�绾︾幆澧冮潰鏉�
+
 
             //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄=========
             this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200-60000";//pir浼犳劅鍣�220
+            this.dicDeviceModelIdEnum["MSPIRB-ZB.10"] = "1205-1200-60000";//鐞冨瀷绉诲姩浼犳劅鍣�
 
             //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄=========
             //杩欓噷鏄害涔愬厠鐨�
@@ -2891,7 +3156,7 @@
             this.dicDeviceModelIdEnum["MSPIR01/M-ZB.10"] = "1303-1200-60000";//绾㈠浼犳劅鍣�
             this.dicDeviceModelIdEnum["MSW01/M-ZB.10"] = "1304-1200-60000";//姘存蹈浼犳劅鍣�
             this.dicDeviceModelIdEnum["MBU01/M-ZB.10"] = "1305-1200-60000";//绱ф�ユ寜閿�
-            this.dicDeviceModelIdEnum["MGCD01/ZB.10"] = "1306-1200-60000";//鍚搁《鐕冩皵浼犳劅鍣�
+            this.dicDeviceModelIdEnum["MGCD01/M-ZB.10"] = "1306-1200-60000";//鍚搁《鐕冩皵浼犳劅鍣�
 
             //PM2.5绌烘皵璐ㄩ噺浼犳劅鍣� 銆愯璁惧灞炰簬绗笁鏂硅澶囷紝娌℃湁闀滃儚ID銆�
             this.dicDeviceModelIdEnum["MSPM25/M-ZB.10"] = "1307-1200-60000";//PM2.5绌烘皵璐ㄩ噺浼犳劅鍣� 
@@ -3046,6 +3311,14 @@
         /// 绐楀笜闈㈡澘 闀滃儚id锛�256
         /// </summary>
         ButtonPanel_Curtain = 256,
+        /// <summary>
+        /// 绠�绾﹀鍔熻兘闈㈡澘 闀滃儚ID锛�212
+        /// </summary>
+        ButtonPanel_SimpleMultifunction = 212,
+        /// <summary>
+        /// 绠�绾︾幆澧冮潰鏉�
+        /// </summary>
+        ButtonPanel_SimpleEnvironment = 230,
 
         //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄=========
         /// <summary>
@@ -3056,6 +3329,10 @@
         /// pir浼犳劅鍣�220 闀滃儚id锛�1200
         /// </summary>
         Sensor_Pir = 1200,
+        /// <summary>
+        /// 鐞冨舰绉诲姩浼犳劅鍣� 闀滃儚id锛�1205
+        /// </summary>
+        Sensor_SphericalMotion = 1205,
 
         //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄=========
         /// <summary>
@@ -3155,6 +3432,10 @@
         /// 褰╃伅
         /// </summary>
         ColorLight = -10,
+        /// <summary>
+        /// 鑹叉俯鐏�(瀹冪殑闀滃儚ID鏈畾,鏆傚畾20000)
+        /// </summary>
+        ColorLight_Temperature = 20000,
 
         //=========鈽呪槄绌鸿皟(3600-3899)鈽呪槄=========
         /// <summary>

--
Gitblit v1.8.0