From 0bf9e65bc3ba98391e7835c922b15baab3c77876 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 01 六月 2020 14:59:39 +0800
Subject: [PATCH] 上传一个合并的版本

---
 ZigbeeApp/Shared/Common/Device.cs |  254 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 224 insertions(+), 30 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 75fe150..3bc9e9e 100755
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -292,9 +292,9 @@
                     //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍�
                     dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
 
-                    HdlThreadLogic.Current.RunThread(async () =>
+                    HdlThreadLogic.Current.RunThread(() =>
                     {
-                        await this.ReName(device, dName, ShowErrorMode.NO);
+                        this.ReName(device, dName, ShowErrorMode.NO);
                     });
                 }
             }
@@ -431,7 +431,7 @@
         /// <param name="device">璁惧瀵硅薄</param>
         /// <param name="newName">鏂板悕瀛�</param>
         /// <param name="mode">鏄惁鏄剧ず閿欒</param>
-        public async Task<bool> ReName(CommonDevice device, string newName, ShowErrorMode mode = ShowErrorMode.YES)
+        public bool ReName(CommonDevice device, string newName, ShowErrorMode mode = ShowErrorMode.YES)
         {
             //鍏堝埆绠¢偅涔堝锛屾洿鏀瑰悕瀛楀悗锛屽埛鏂拌澶囩紦瀛�
             this.SetEpointName(device, newName);
@@ -450,7 +450,7 @@
             //鎴愬憳鍙兘淇敼鑷繁鏈湴鐨勫悕瀛�
             if (UserCenterResourse.UserInfo.AuthorityNo != 3)
             {
-                var result = await device.RenameDeviceNameAsync(device.DeviceAddr, device.DeviceEpoint, newName);
+                var result = this.RenameDeviceNameAsync(device, newName);
                 if (result == null || result.deviceRenameData == null || result.deviceRenameData.Result == 1)
                 {
                     //璁惧鍚嶇О淇敼澶辫触
@@ -464,8 +464,6 @@
                     }
                     return false;
                 }
-                //澶囦唤鏁版嵁
-                await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A绔偣鍚嶇О, newName);
             }
             //淇敼璁惧鍚嶅瓧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
             Phone.UserView.UserPage.Instance.RefreshForm = true;
@@ -478,7 +476,7 @@
         /// <param name="listDevice">璁惧瀵硅薄</param>
         /// <param name="newMacName">鏂板悕瀛�</param>
         /// <param name="mode">鏄惁鏄剧ず閿欒</param>
-        public async Task<bool> ReMacName(List<CommonDevice> listDevice, string newMacName, ShowErrorMode mode = ShowErrorMode.YES)
+        public bool ReMacName(List<CommonDevice> listDevice, string newMacName, ShowErrorMode mode = ShowErrorMode.YES)
         {
             if (listDevice.Count == 0)
             {
@@ -506,7 +504,7 @@
             if (UserCenterResourse.UserInfo.AuthorityNo != 3)
             {
                 //淇敼鐗╃悊鍚嶅瓧
-                var result = await device.RenameDeviceMacNameAsync(device.DeviceAddr, device.DeviceEpoint, newMacName);
+                var result = this.RenameDeviceMacNameAsync(device, newMacName);
                 if (result == null || result.renameDeviceMacNameData == null || result.renameDeviceMacNameData.Result != 0)
                 {
                     //璁惧鍚嶇О淇敼澶辫触
@@ -519,15 +517,13 @@
                     }
                     return false;
                 }
-                //澶囦唤鏁版嵁
-                await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.AMac鍚嶇О, newMacName);
                 //濡傛灉瀹冨彧鏈変竴涓洖璺�,鍒欐洿鏀圭鐐瑰悕瀛�
                 if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true)
                 {
                     //鍙湁涓�涓鐐�
                     if (this.dicDeviceEpoint[device.DeviceAddr].Count == 1)
                     {
-                        return await this.ReName(device, newMacName);
+                        return this.ReName(device, newMacName);
                     }
                     //濡傛灉瀹冩湁涓や釜绔偣鏃�,pir浼犳劅鍣ㄧ壒娈婂鐞�
                     else if (this.dicDeviceEpoint[device.DeviceAddr].Count == 2)
@@ -539,7 +535,7 @@
                             {
                                 if (myDevice.Type == DeviceType.IASZone)
                                 {
-                                    return await this.ReName(myDevice, newMacName);
+                                    return this.ReName(myDevice, newMacName);
                                 }
                             }
                         }
@@ -547,6 +543,100 @@
                 }
             }
             return true;
+        }
+
+        ///<summary >
+        /// 淇敼璁惧mac鍚嶇О
+        /// <para>macName:璁惧鍚嶇О</para>
+        /// </summary>
+        private CommonDevice.RenameDeviceMacNameAllData RenameDeviceMacNameAsync(CommonDevice device, string macName)
+        {
+            //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                return Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceMacName(device, macName, "MacRename");
+            }
+
+            //鑾峰彇缂栬緫璁惧Mac鍚嶅瓧鐨勫懡浠ゅ瓧绗�
+            var sendData = this.GetReDeviceMacNameCommandText(device.DeviceAddr, device.DeviceEpoint, macName);
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "MacRename", sendData, "MacRename_Respon");
+            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+            {
+                return null;
+            }
+            //鍔犵紦瀛�
+            Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceMacName(device, macName, "MacRename");
+
+            var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RenameDeviceMacNameData>(result.ReceiptData);
+            return new CommonDevice.RenameDeviceMacNameAllData { renameDeviceMacNameData = tempData };
+        }
+
+        /// <summary>
+        /// 淇敼璁惧绔彛锛堟寜閿級鍚嶇О
+        /// </summary>
+        /// <param name="device">璁惧瀵硅薄</param>
+        /// <param name="deviceName">璁惧绔偣鍚嶅瓧</param>
+        /// <returns></returns>
+        private CommonDevice.DeviceRenameAllData RenameDeviceNameAsync(CommonDevice device, string deviceName)
+        {
+            //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                return Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceEpointName(device, deviceName, "DeviceRename");
+            }
+            //鑾峰彇缂栬緫璁惧绔偣鍚嶅瓧鐨勫懡浠ゅ瓧绗�
+            var sendData = this.GetReDeviceEpointNameCommandText(device.DeviceAddr, device.DeviceEpoint, deviceName);
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "DeviceRename", sendData, "DeviceRenameRespon");
+            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+            {
+                return null;
+            }
+            //鍔犵紦瀛�
+            Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceEpointName(device, deviceName, "DeviceRename");
+
+            var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceRenameResponseData>(result.ReceiptData);
+            return new CommonDevice.DeviceRenameAllData { deviceRenameData = tempData };
+        }
+
+        /// <summary>
+        /// 鑾峰彇缂栬緫璁惧Mac鍚嶅瓧鐨勫懡浠ゅ瓧绗�
+        /// </summary>
+        /// <param name="deviceAddr"></param>
+        /// <param name="deviceEpoint"></param>
+        /// <param name="deviceName"></param>
+        /// <returns></returns>
+        public string GetReDeviceMacNameCommandText(string deviceAddr, int deviceEpoint, string deviceName)
+        {
+            var bytes = new byte[64];
+            var reamarkGwBytes = Encoding.UTF8.GetBytes(deviceName);
+            System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 64 < reamarkGwBytes.Length ? 64 : reamarkGwBytes.Length);
+            deviceName = Encoding.UTF8.GetString(bytes);
+
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 100 } };
+            var data = new Newtonsoft.Json.Linq.JObject { { "MacName", deviceName } };
+            jObject.Add("Data", data);
+            return jObject.ToString();
+        }
+
+        /// <summary>
+        /// 鑾峰彇缂栬緫璁惧绔偣鍚嶅瓧鐨勫懡浠ゅ瓧绗�
+        /// </summary>
+        /// <param name="deviceAddr"></param>
+        /// <param name="deviceEpoint"></param>
+        /// <param name="deviceName"></param>
+        /// <returns></returns>
+        public string GetReDeviceEpointNameCommandText(string deviceAddr, int deviceEpoint, string deviceName)
+        {
+            var bytes = new byte[64];
+            var reamarkGwBytes = Encoding.UTF8.GetBytes(deviceName);
+            System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 64 < reamarkGwBytes.Length ? 64 : reamarkGwBytes.Length);
+            deviceName = Encoding.UTF8.GetString(bytes);
+
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 96 } };
+            var data = new Newtonsoft.Json.Linq.JObject { { "DeviceName", deviceName } };
+            jObject.Add("Data", data);
+
+            return jObject.ToString();
         }
 
         /// <summary>
@@ -590,22 +680,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璁惧
@@ -732,7 +826,7 @@
         /// <returns></returns>
         public bool DeviceIsCanFixedPosition(CommonDevice device)
         {
-            if (device.Type == DeviceType.DoorLock)
+            if (device.Type == DeviceType.DoorLock || device.Type == DeviceType.PMSensor)
             {
                 //闂ㄩ攣娌℃湁瀹氫綅鍔熻兘
                 return false;
@@ -889,6 +983,47 @@
         }
 
         /// <summary>
+        /// 鏍规嵁MAC鍦板潃,鑾峰彇绠�绾﹂潰鏉垮叏閮ㄥ洖璺殑璁惧瀵硅薄
+        /// </summary>
+        /// <param name="listDevice"></param>
+        /// <returns></returns>
+        public List<CommonDevice> GetMutilfunctionPanelByMac(List<CommonDevice> listDevice, bool sort = true)
+        {
+            //鍜屽姜鍝ャ�佽澶囧拰浜у搧閮ㄥ悓浜嬬‘璁わ細
+            //绠�绾﹀鍔熻兘闈㈡澘[涓嶆樉绀哄浣欑殑鍥炶矾锛屽彧鏄剧ず鎼哄甫鐨�2涓户鐢靛櫒鍜�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.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="DeviceAddr">Mac鍦板潃</param>
@@ -1017,6 +1152,12 @@
             {
                 return dName;
             }
+            if (this.IsMiniLight(device) == true)
+            {
+                //Mini澶滅伅
+                return Language.StringByID(R.MyInternationalizationString.uMiniNightLight);
+            }
+
             //濡傛灉杩欎釜璁惧鍙湁涓�涓洖璺殑璇�,杩斿洖Mac鍚嶅瓧缁欏畠
             if (this.GetDevicesCountByMac(device.DeviceAddr) <= 1)
             {
@@ -1441,7 +1582,6 @@
             unSelectPath = imageFilePath;
             selectPath = imageSelectFilePath;
         }
-
 
         #endregion
 
@@ -1982,6 +2122,16 @@
                     this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
                     save = true;
                 }
+                else
+                {
+                    //2020.05.18杩藉姞:濡傛灉璁板綍鐨勬埧闂碔D鏄笉瀛樺湪鐨勮瘽,鍒欓噸鏂拌鐩�
+                    var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[listDevice[0].DeviceAddr]);
+                    if (room == null || this.dicDeviceRoomId[listDevice[0].DeviceAddr] != roomId)
+                    {
+                        this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
+                        save = true;
+                    }
+                }
             }
 
             if (save == true)
@@ -2061,6 +2211,25 @@
 
             //娣诲姞鑷姩澶囦唤
             HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
+        }
+
+        /// <summary>
+        /// 鏍规嵁鎴块棿ID,绉婚櫎鎸囧畾鐨勭湡瀹炵墿鐞嗚澶囩殑鎵�灞炴埧闂磋褰�
+        /// </summary>
+        /// <param name="i_RoomId"></param>
+        public void DeleteRealDeviceByRoomId(string i_RoomId)
+        {
+            var listDeleteKey = new List<string>();
+            foreach (var deviceAddr in this.dicDeviceRoomId.Keys)
+            {
+                if (this.dicDeviceRoomId[deviceAddr] == i_RoomId
+                    && listDeleteKey.Contains(deviceAddr) == false)
+                {
+                    listDeleteKey.Add(deviceAddr);
+                }
+            }
+            //灏嗙湡瀹炵墿鐞嗚澶囦粠鎴块棿涓Щ闄�
+            this.DeleteRealDeviceFromRoom(listDeleteKey);
         }
 
         #endregion
@@ -2245,6 +2414,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.DeviceAddr == "3737363534333231";
         }
 
         /// <summary>
@@ -2605,6 +2784,11 @@
                 if (mainDevice.IsCustomizeImage == false)
                 {
                     mainDevice.IconPath = "Device/Light.png";
+                    if (this.IsMiniLight(mainDevice) == true)
+                    {
+                        //mini澶滅伅
+                        mainDevice.IconPath = "Device/MiniNightLight.png";
+                    }
                 }
             }
             //濡傛灉鏄笁璺户鐢靛櫒鐨勫洖璺殑璇�,榛樿涓虹伅鍏�
@@ -2754,6 +2938,9 @@
             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
@@ -2776,7 +2963,7 @@
             this.dicDeviceModelIdEnum["MGCD01/ZB.10"] = "1306-1200-60000";//鍚搁《鐕冩皵浼犳劅鍣�
 
             //PM2.5绌烘皵璐ㄩ噺浼犳劅鍣� 銆愯璁惧灞炰簬绗笁鏂硅澶囷紝娌℃湁闀滃儚ID銆�
-            this.dicDeviceModelIdEnum["SZ_PM100"] = "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璺户鐢靛櫒灏忔ā鍧�
@@ -2928,7 +3115,14 @@
         /// 绐楀笜闈㈡澘 闀滃儚id锛�256
         /// </summary>
         ButtonPanel_Curtain = 256,
-
+        /// <summary>
+        /// 绠�绾﹀鍔熻兘闈㈡澘 闀滃儚ID锛�212
+        /// </summary>
+        ButtonPanel_SimpleMultifunction = 212,
+        /// <summary>
+        /// 绠�绾︾幆澧冮潰鏉�
+        /// </summary>
+        ButtonPanel_SimpleEnvironment = 230,
         //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄=========
         /// <summary>
         /// 浼犳劅鍣�

--
Gitblit v1.8.0