From 9ef48d7b2da7c408b53f73be0f6eef3cbac1c84a Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 19 十一月 2020 10:23:45 +0800
Subject: [PATCH] Evoyo.Home1.1.0120111601_Release

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs |  379 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 332 insertions(+), 47 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
index d9acfff..76c3d28 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
@@ -33,6 +33,14 @@
         }
 
         /// <summary>
+        /// 缃戝叧鎺ユ敹浜嬩欢(鍙傛暟1:涓婚 鍙傛暟2:鎺ㄩ�佹秷鎭�)
+        /// </summary>
+        private Action<string, string> GatewayReceiveEvent = null;
+        /// <summary>
+        /// 鎺ユ敹缃戝叧鐨刬d
+        /// </summary>
+        private string GatewayReceiveId = null;
+        /// <summary>
         /// 璁惧鎺ㄩ�佷簨浠堕泦鍚�
         /// </summary>
         private Dictionary<string, Action<CommonDevice>> dicDeviceEvent = new Dictionary<string, Action<CommonDevice>>();
@@ -54,6 +62,11 @@
         /// <param name="msgData">鎺ユ敹鐨勬暟鎹�</param>
         public void GatewayOverallMsgReceive(string gatewayId, string topic, string reportTopic, string msgData)
         {
+            //濡傛灉瀹冨湪鐧婚檰鐣岄潰,鍒欎笉鍋氫换浣曞鐞�
+            if (Common.Config.Instance.HomeId == string.Empty)
+            {
+                return;
+            }
             if (topic == "AppNoLogin")
             {
                 HdlThreadLogic.Current.RunMain(() =>
@@ -141,7 +154,11 @@
             {
                 if (HdlGatewayLogic.Current.IsGatewayExist(gatewayId) == false)
                 {
-                    //涓嶆槸鑷繁缁戝畾鐨勭綉鍏筹紝鍒欎笉澶勭悊
+                    //涓嶆槸鑷繁缁戝畾鐨勭綉鍏筹紝鍒欎笉澶勭悊,浣嗘槸涓嬮潰杩欎釜涓滆タ鏈夌偣鐗规畩
+                    if (gatewayId == this.GatewayReceiveId)
+                    {
+                        this.GatewayReceiveEvent?.Invoke(topic, msgData);
+                    }
                     return;
                 }
                 //璁惧灞炴�т笂鎶�
@@ -195,6 +212,11 @@
                 {
                     this.SceneExecPush(null);
                 }
+                //缃戝叧鎺ユ敹浜嬩欢
+                else if (gatewayId == this.GatewayReceiveId)
+                {
+                    this.GatewayReceiveEvent?.Invoke(topic, msgData);
+                }
             }
             catch (Exception ex)
             {
@@ -247,6 +269,51 @@
                         ((LightBase)locadevice).OnOffStatus = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                         //宸茬粡鎺ユ敹鍒扮姸鎬�
                         locadevice.HadReadDeviceStatu = true;
+                    }
+                }
+                #endregion
+
+                #region 鈻� 鐢甸噺鎺ㄩ��
+                //鐢甸噺鎺ㄩ��
+                if (report.DeviceStatusReport.CluterID == 1)
+                {
+                    foreach (var attData in report.DeviceStatusReport.AttriBute)
+                    {
+                        //鐢甸噺
+                        if (attData.AttributeId == 33)
+                        {
+                            string receiptData = string.Empty;
+                            //涓や釜涓や釜浣嶇疆鏇挎崲
+                            for (int i = attData.AttriButeDataHex.Length - 1; i >= 0; i = i - 2)
+                            {
+                                receiptData += attData.AttriButeDataHex[i - 1].ToString() + attData.AttriButeDataHex[i].ToString();
+                            }
+                            int batteryValue = Convert.ToInt32(receiptData, 16);
+                            //浣庝簬20%,鍒欎唬琛ㄧ數閲忎綆
+                            locadevice.IsBatteryDown = batteryValue < 20;
+                        }
+                        //宸茬粡鎺ユ敹鍒扮姸鎬�
+                        locadevice.HadReadDeviceStatu = true;
+                    }
+                }
+
+                #endregion
+
+                #region 鈻� 铚傞福鍣ㄦ帹閫�
+                //铚傞福鍣ㄦ暟鎹�
+                else if (report.DeviceStatusReport.CluterID == 1282)
+                {
+                    //mini澶滅伅
+                    if (Common.LocalDevice.Current.IsMiniLight(locadevice) == true)
+                    {
+                        foreach (var attData in report.DeviceStatusReport.AttriBute)
+                        {
+                            if (attData.AttributeId == 0)
+                            {
+                                //杩欎釜鏄姤璀︽寔缁椂闂�(澶т簬2绉掓椂,鏍囪涓鸿繕鍦ㄥ搷鐫�)
+                                ((ColorTemperatureLight)locadevice).IsBuzzerRing = attData.AttriButeData > 2 ? true : false;
+                            }
+                        }
                     }
                 }
                 #endregion
@@ -406,10 +473,43 @@
                 else if (report.DeviceStatusReport.CluterID == 8)
                 {
                     locadevice.DeviceStatusReport = report.DeviceStatusReport;
-                    if (locadevice.Type == DeviceType.DimmableLight && report.DeviceStatusReport.AttriBute[0].AttributeId == 0)
+                    if (report.DeviceStatusReport.AttriBute[0].AttributeId == 0)
                     {
-                        //姝ゅ睘鎬ц〃鏄庡綋鍓嶄寒搴︾▼搴�
-                        ((DimmableLight)locadevice).Level = report.DeviceStatusReport.AttriBute[0].AttriButeData;
+                        if (locadevice.Type == DeviceType.DimmableLight)
+                        {
+                            //姝ゅ睘鎬ц〃鏄庡綋鍓嶄寒搴︾▼搴�
+                            ((DimmableLight)locadevice).Level = report.DeviceStatusReport.AttriBute[0].AttriButeData;
+                        }
+                        else if (locadevice.Type == DeviceType.ColorTemperatureLight)
+                        {
+                            //姝ゅ睘鎬ц〃鏄庡綋鍓嶄寒搴︾▼搴�
+                            ((ColorTemperatureLight)locadevice).Level = report.DeviceStatusReport.AttriBute[0].AttriButeData;
+                        }
+                        //宸茬粡鎺ユ敹鍒扮姸鎬�
+                        locadevice.HadReadDeviceStatu = true;
+
+                        //if (locadevice is LightBase)
+                        //{
+                        //    //褰撴帴鏀跺埌浜害鍊兼椂,榛樿鎵撳紑
+                        //    ((LightBase)locadevice).OnOffStatus = 1;
+                        //}
+                    }
+                }
+                #endregion
+
+                #region 鈻� 鑹叉俯鏁版嵁
+                //鑹叉俯鏁版嵁
+                else if (report.DeviceStatusReport.CluterID == 768)
+                {
+                    locadevice.DeviceStatusReport = report.DeviceStatusReport;
+                    if (report.DeviceStatusReport.AttriBute[0].AttributeId == 0)
+                    {
+                        if (locadevice.Type == DeviceType.ColorTemperatureLight)
+                        {
+                            //姝ゅ睘鎬ц〃鏄庡綋鍓嶈壊娓�
+                            int value = report.DeviceStatusReport.AttriBute[0].AttriButeData != 0 ? 1000000 / report.DeviceStatusReport.AttriBute[0].AttriButeData : 0;
+                            ((ColorTemperatureLight)locadevice).ColorTemperature = value;
+                        }
                         //宸茬粡鎺ユ敹鍒扮姸鎬�
                         locadevice.HadReadDeviceStatu = true;
                     }
@@ -464,7 +564,7 @@
                             //娓╁害浼犳劅鍣�
                             if (locadevice is TemperatureSensor)
                             {
-                                ((TemperatureSensor)locadevice).Temperatrue = temperatrue;
+                                ((TemperatureSensor)locadevice).currentTemperature = temperatrue;
                             }
                             //PM2.5浼犳劅鍣�
                             else if (locadevice is PMSensor)
@@ -473,6 +573,8 @@
                             }
                             //宸茬粡鎺ユ敹鍒扮姸鎬�
                             locadevice.HadReadDeviceStatu = true;
+                            //娓╁害鍊奸渶瑕佷繚瀛�
+                            locadevice.ReSave();
                         }
                     }
                 }
@@ -510,24 +612,180 @@
                                 strValue = strValue.Substring(0, strValue.Length - 1);
                                 humidity = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, "."));
                             }
-                            //娓╁害浼犳劅鍣�
+                            //婀垮害浼犳劅鍣�
                             if (locadevice is TemperatureSensor)
                             {
-                                ((TemperatureSensor)locadevice).Humidity = humidity;
+                                ((TemperatureSensor)locadevice).currentHumidity = humidity;
+                            }
+                            //鏂伴鐨勬箍搴︿紶鎰熷櫒
+                            else if (locadevice is HumiditySensor)
+                            {
+                                ((HumiditySensor)locadevice).currentHumidity = humidity;
                             }
                             //PM2.5浼犳劅鍣�
                             else if (locadevice is PMSensor)
                             {
                                 ((PMSensor)locadevice).currentHumidity = (int)humidity;
                             }
+                            //宸茬粡鎺ユ敹鍒扮姸鎬�
+                            locadevice.HadReadDeviceStatu = true;
+                            //婀垮害鍊奸渶瑕佷繚瀛�
+                            locadevice.ReSave();
+                        }
+                    }
+                }
+                #endregion
+
+                #region 鈻� PM2.5鏁版嵁
+                //PM2.5鏁版嵁
+                else if (report.DeviceStatusReport.CluterID == 1066)
+                {
+                    foreach (var attData in report.DeviceStatusReport.AttriBute)
+                    {
+                        //PM2.5
+                        if (attData.AttributeId == (int)AttriButeId.MeasuredValue)
+                        {
+
+                            if (attData.AttriButeDataType == 57)
+                            {
+                                ((PMSensor)locadevice).currentPmData = attData.AttriButeData;
+                            }
                         }
                         //宸茬粡鎺ユ敹鍒扮姸鎬�
                         locadevice.HadReadDeviceStatu = true;
                     }
                 }
+
+                #endregion
+
+                #region 鈻� 璁惧鍩虹淇℃伅
+
+                else if (report.DeviceStatusReport.CluterID == 0)
+                {
+                    var listLocalDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceAddr, false);
+                    //灞炴�ч兘鏄竴鏍风殑
+                    foreach (var myDevice in listLocalDevice)
+                    {
+                        //灞炴�ф槸鍚︽敼鍙�
+                        bool attriButeChanged = false;
+                        foreach (var data in report.DeviceStatusReport.AttriBute)
+                        {
+                            //鐢熶骇鍟嗗悕瀛�
+                            if (data.AttributeId == 4 && data.AttriButeDataHex.Length > 2)
+                            {
+                                if (data.AttriButeDataHex.Length > 2)
+                                {
+                                    var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
+                                    if (myDevice.ManufacturerName != value)
+                                    {
+                                        //灞炴�у彉鏇翠簡
+                                        attriButeChanged = true;
+                                    }
+                                    myDevice.ManufacturerName = value;
+                                }
+                            }
+                            //鍨嬪彿鐮�(涔熷彨妯″潡ID)
+                            if (data.AttributeId == 5)
+                            {
+                                if (data.AttriButeDataHex.Length > 2)
+                                {
+                                    var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
+                                    if (myDevice.ModelIdentifier != value)
+                                    {
+                                        //灞炴�у彉鏇翠簡
+                                        attriButeChanged = true;
+                                    }
+                                    myDevice.ModelIdentifier = value;
+                                }
+                            }
+                            //鐢熶骇鏃ユ湡
+                            if (data.AttributeId == 6)
+                            {
+                                if (data.AttriButeDataHex.Length > 2)
+                                {
+                                    var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
+                                    if (myDevice.ProductionDate != value)
+                                    {
+                                        //灞炴�у彉鏇翠簡
+                                        attriButeChanged = true;
+                                    }
+                                    myDevice.ProductionDate = value;
+                                }
+                            }
+                            //鐢垫簮
+                            if (data.AttributeId == 7)
+                            {
+                                myDevice.PowerSource = data.AttriButeData;
+                            }
+                            //搴忓垪鍙�
+                            if (data.AttributeId == 13)
+                            {
+                                if (data.AttriButeDataHex.Length > 2)
+                                {
+                                    string value;
+                                    if (Common.LocalDevice.Current.IsHdlDevice(myDevice) == false)
+                                    {
+                                        //绗笁鏂硅澶�
+                                        value = data.AttriButeDataHex.Substring(2);
+                                    }
+                                    else
+                                    {
+                                        //娌充笢璁惧
+                                        value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
+                                    }
+                                    if (myDevice.SerialNumber != value)
+                                    {
+                                        //灞炴�у彉鏇翠簡
+                                        attriButeChanged = true;
+                                    }
+                                    myDevice.SerialNumber = value;
+                                }
+                            }
+                        }
+                        //濡傛灉灞炴�у彉鏇翠簡
+                        if (attriButeChanged == true && myDevice.IsCustomizeImage == false)
+                        {
+                            //UI閲嶆柊鐢熸垚
+                            myDevice.IconPath = string.Empty;
+                            myDevice.ReSave();
+                        }
+                    }
+                }
+
                 #endregion
             }
-
+            else if (deviceEpoint == 200)
+            {
+                var localOta = Common.LocalDevice.Current.GetOTADevice(deviceAddr);
+                if (localOta != null)
+                {
+                    #region 鈻� 鍥轰欢鐗堟湰
+                    //鍥轰欢鐗堟湰
+                    if (report.DeviceStatusReport.CluterID == (int)Cluster_ID.Ota)
+                    {
+                        foreach (var data in report.DeviceStatusReport.AttriBute)
+                        {
+                            //闀滃儚鐗堟湰
+                            if (data.AttributeId == (int)AttriButeId.ImgVersion)
+                            {
+                                localOta.ImgVersion = data.AttriButeData;
+                            }
+                            //纭欢鐗堟湰
+                            if (data.AttributeId == (int)AttriButeId.mgHWversion)
+                            {
+                                localOta.HwVersion = data.AttriButeData;
+                            }
+                            //闀滃儚ID
+                            if (data.AttributeId == (int)AttriButeId.ImgTypeId)
+                            {
+                                localOta.ImgTypeId = data.AttriButeData;
+                            }
+                        }
+                        localOta.ReSave();
+                    }
+                    #endregion
+                }
+            }
             this.DeviceReportPush(report, ReceiveComandDiv.A璁惧灞炴�т笂鎶�);
         }
 
@@ -578,8 +836,7 @@
         /// <param name="receiveData"></param>
         private void DoorLockDeviceReportPush(JObject receiveData)
         {
-            //鍙湁寰愭鐨勯棬閿佺晫闈㈡病鏈夋墦寮�鐨勬儏鍐典笅,鎵嶄細澶勭悊杩欎釜涓滆タ
-            if (ControlCommonResourse.IsDoorLockPageOpen == false && UserCenterResourse.UserInfo.AuthorityNo == 1)
+            if (UserCenterResourse.UserInfo.AuthorityNo == 1)
             {
                 var device = Common.LocalDevice.Current.GetDevice(receiveData.Value<string>("DeviceAddr"), receiveData.Value<int>("Epoint"));
                 if (device.Type != DeviceType.DoorLock)
@@ -587,31 +844,27 @@
                     //瀹冧笉鏄棬閿�
                     return;
                 }
+
                 var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLockAlarmsResult>(receiveData["Data"].ToString());
                 if (info.Clusterid == 257)
                 {
-                    //甯稿紑妯″紡鍏抽棴
-                    if (info.AlarmCode == 217 || info.AlarmCode == 219)
+                    //216锛氶攣涓婅缃殑甯稿紑
+                    if (info.AlarmCode == 216)
                     {
-                        HdlThreadLogic.Current.RunThread(async () =>
+                        HdlThreadLogic.Current.RunMain(() =>
                         {
-                            //娓╁眳鍩庣殑瑕佺綉鍏充腑鏄惁鏈夐�昏緫瀛樺湪 
-                            //鍙傛暟:2-甯稿紑鑷姩鍖�;3-澶辨晥鏃堕棿鑷姩鍖�
-                            var result = await Shared.Phone.Device.Logic.SkipView.Exist(3, (ZigBee.Device.DoorLock)device);
-                            HdlThreadLogic.Current.RunMain(() =>
+                            //鏇存柊闂ㄩ攣娑夊強鐨勫父寮�/甯稿叧鐨勭晫闈�
+                            if (UserCenter.DoorLock.DoorLockCommonInfo.UpdateCurrentDoorlockAction != null)
                             {
-                                //寮瑰嚭寰愭鐨勯偅涓獥鍙�
-                                DoorLock.DoorLockCommonInfo.NomallyOpenModeInvalidDialog((ZigBee.Device.DoorLock)device, DoorLock.DoorLockCommonInfo.DoorLockMessType.ServicePush,
-                                    result != 0 ? true : false, null);
-                            });
+                                UserCenter.DoorLock.DoorLockCommonInfo.UpdateCurrentDoorlockAction(device.DeviceAddr, true);
+                            }
                         });
                     }
                 }
+                //鏄剧ず鏈夋柊娑堟伅鐨勭壒鏁�
+                this.ShowHadNewMessageAppeal();
             }
-            //鏄剧ず鏈夋柊娑堟伅鐨勭壒鏁�
-            this.ShowHadNewMessageAppeal();
         }
-
         #endregion
 
         #region 鈻� 璁惧鍦ㄧ嚎鐘舵�佹洿鏂板弽棣坃______________
@@ -620,7 +873,7 @@
         /// 璁惧鍦ㄧ嚎鐘舵�佹洿鏂板弽棣�
         /// </summary>
         /// <param name="receiveData"></param>
-        private void DeviceOnlineChangePush (JObject receiveData)
+        private void DeviceOnlineChangePush(JObject receiveData)
         {
             if (this.dicDeviceEvent.Count == 0)
             {
@@ -805,29 +1058,40 @@
             //鏄剧ず鏈夋柊娑堟伅鐨勭壒鏁�
             this.ShowHadNewMessageAppeal();
 
-            //杩欎釜涓滆タ鏆傛椂涓嶅鐞�
-            ////鍙湁寰愭鐨勯棬閿佺晫闈㈡病鏈夋墦寮�鐨勬儏鍐典笅,鎵嶄細澶勭悊杩欎釜涓滆タ
-            //if (ControlCommonResourse.IsDoorLockPageOpen == false && UserCenterResourse.UserInfo.AuthorityNo == 1)
-            //{
-            //    var device = Common.LocalDevice.Current.GetDevice(receiveData.Value<string>("DeviceAddr"), receiveData.Value<int>("Epoint"));
-            //    if (device.Type != DeviceType.DoorLock)
-            //    {
-            //        return;
-            //    }
-            //    //鑷姩鍖栨墽琛� 甯稿紑鍏抽棴
-            //    var data = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicPushResult>(receiveData["Data"].ToString());
-            //    if (data.ActionData != null && data.ActionData.Actiontype == 8
-            //        && data.ActionData.PassDataString == "055704010113")
-            //    {
-            //        HdlThreadLogic.Current.RunMain(() =>
-            //        {
-            //            //寮瑰嚭寰愭鐨勯偅涓獥鍙�
-            //            DoorLock.DoorLockCommonInfo.NomallyOpenModeInvalidDialog((ZigBee.Device.DoorLock)device, DoorLock.DoorLockCommonInfo.DoorLockMessType.ServicePush, null);
-            //        });
-            //    }
-            //}
-        }
+            // 閫昏緫鎵ц甯稿紑妯″紡澶辨晥鐨勬儏鍐�
+            if (UserCenterResourse.UserInfo.AuthorityNo == 1)
+            {
+                //鑷姩鍖栨墽琛� 甯稿紑鍏抽棴
+                var data = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicPushResult>(receiveData["Data"].ToString());
+                if (data != null && data.ActionData != null)
+                {
+                    if (data.ActionData.Actiontype == 8 && data.ActionData.PassDataString == "055704010113")
+                    {
+                        var deviceAddr = data.ActionData.MacStr;
+                        var device = Common.LocalDevice.Current.GetDevicesByMac(deviceAddr, false);
+                        if (device.Count > 0 && device[0].Type != DeviceType.DoorLock)
+                        {
+                            return;
+                        }
 
+                        HdlThreadLogic.Current.RunThread(async () =>
+                        {
+                            HdlThreadLogic.Current.RunMain(() =>
+                            {
+                                //鎻愮ず闂ㄩ攣宸茬粡澶辨晥
+                                new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.NormallyClosed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+
+                                //鏇存柊闂ㄩ攣娑夊強鐨勫父寮�/甯稿叧鐨勭晫闈�
+                                if (UserCenter.DoorLock.DoorLockCommonInfo.UpdateCurrentDoorlockAction != null)
+                                {
+                                    UserCenter.DoorLock.DoorLockCommonInfo.UpdateCurrentDoorlockAction(deviceAddr, false);
+                                }
+                            });
+                        });
+                    }
+                }
+            }
+        }
         #endregion
 
         #region 鈻� 鍦烘櫙瑙﹀彂涓婃姤_______________________
@@ -873,6 +1137,18 @@
             }
         }
 
+        /// <summary>
+        /// 娣诲姞缃戝叧鎺ユ敹浜嬩欢(action鍙兘瀛樺湪涓�涓�,涓嶢ddAttributeEvent涓嶅叡瀛�,AddAttributeEvent浼樺厛)
+        /// </summary>
+        /// <param name="i_gatewayId">缃戝叧id</param>
+        /// <param name="action">鍙兘瀛樺湪涓�涓猘ction (鍙傛暟1:涓婚 鍙傛暟2:鎺ㄩ�佹秷鎭�)</param>
+        public void AddGatewayReceiveEvent(string i_gatewayId, Action<string, string> action)
+        {
+            //娣诲姞浜嬩欢
+            this.GatewayReceiveEvent = action;
+            this.GatewayReceiveId = i_gatewayId;
+        }
+
         #endregion
 
         #region 鈻� 绉婚櫎璁惧鐩戝惉_______________________
@@ -916,6 +1192,15 @@
             }
         }
 
+        /// <summary>
+        /// 绉婚櫎缃戝叧鎺ユ敹浜嬩欢(鍙兘瀛樺湪涓�涓簨浠�)
+        /// </summary>
+        public void RemoveGatewayReceiveEvent()
+        {
+            this.GatewayReceiveEvent = null;
+            this.GatewayReceiveId = null;
+        }
+
         #endregion
 
         #region 鈻� 涓�鑸柟娉昣__________________________

--
Gitblit v1.8.0