From ba275a7b58e56c61820ffccc86571447b2997e52 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期四, 05 八月 2021 16:18:00 +0800
Subject: [PATCH] 2021-08-05 1.更新

---
 HDL_ON/DAL/DriverLayer/Control.cs |  250 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 185 insertions(+), 65 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index 7127058..7cbe4d6 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -283,6 +283,30 @@
         /// </summary>
         public void ControlScene(Scene scene)
         {
+            //浣撻獙妯″紡
+            if(MainPage.NoLoginMode)
+            {
+                foreach(var sceneFunction in scene.functions)
+                {
+                    var revString = "";
+                    var upDataObj = new AlinkFunctionStatusObj();
+                    upDataObj.id = "999";
+                    upDataObj.objects = new List<AlinkStatusData>();
+                    var asd = new AlinkStatusData() { deviceId = sceneFunction.localFunction.deviceId, sid = sceneFunction.sid };
+                    var status1 = new List<AttributesStatus>();
+                    foreach (var dic in sceneFunction.status)
+                    {
+                        status1.Add(new AttributesStatus() { key = dic.key, value = dic.value });
+                    }
+                    asd.status = status1;
+                    upDataObj.objects.Add(asd);
+                    revString = Newtonsoft.Json.JsonConvert.SerializeObject(upDataObj);
+                    UpdataFunctionStatus(revString, null, true);
+                }
+                return;
+            }
+
+            //杩滅▼鎴栬�呮帶鍒秎ink缃戝叧鍦烘櫙
             if (!Ins.GatewayOnline_Local || DB_ResidenceData.Instance.GatewayType == 1)
             {
                 new System.Threading.Thread(() =>
@@ -336,10 +360,31 @@
                 }
             }
 
+            ///dome鎺у埗
+            if (MainPage.NoLoginMode)
+            {
+                var revString = "";
+                var upDataObj = new AlinkFunctionStatusObj();
+                upDataObj.id = "999";
+                upDataObj.objects = new List<AlinkStatusData>();
+                var asd = new AlinkStatusData() { deviceId = function.deviceId, sid = function.sid };
+                var status1 = new List<AttributesStatus>();
+                foreach (var dic in commandDictionary)
+                {
+                    status1.Add(new AttributesStatus() { key = dic.Key, value = dic.Value });
+                }
+                asd.status = status1;
+                upDataObj.objects.Add(asd);
+                revString = Newtonsoft.Json.JsonConvert.SerializeObject(upDataObj);
+                UpdataFunctionStatus(revString, null, true);
+                return;
+            }
+
+
             //MainPage.Log($"鍙戦�佹暟鎹�:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}");
 
             ///绗笁鏂规秱楦﹁澶囩粺涓�浣跨敤杩滅▼鎺у埗
-            switch(function.spk)
+            switch (function.spk)
             {
                 case SPK.ElectricTuyaAirCleaner:
                 case SPK.ElectricTuyaFan:
@@ -361,16 +406,6 @@
             }
             else
             {
-                ////杩滅▼閫氳
-                //if (Ins.GatewayOnline_Local == false && Ins.GatewayOnline_Cloud == true)
-                //{
-                //    DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest();
-                //    //ALink鎺у埗銆丅us鎺у埗浣跨敤鍚屼竴涓帴鍙f帶鍒讹紝鐢变簯绔礋璐hВ鏋�
-                //    var apiControlData = function.GetApiControlData(commandDictionary);
-                //    var actionObjs = new List<ApiAlinkControlActionObj>();
-                //    actionObjs.Add(apiControlData);
-                //    var pack = httpServer.ControlDevice(actionObjs);
-                //}
                 //鏈湴閫氳
                 if (Ins.GatewayOnline_Local)
                 {
@@ -399,6 +434,25 @@
                 //杩滅▼閫氳
                 else
                 {
+                    //Bug淇锛氫竴绔彛杩滅▼鎺у埗璋冨厜璁惧鐨勮皟鍏夊睘鎬ф椂锛屾棤娉曟帶鍒跺埌0锛屽弽澶嶆í璺炽��
+                    //鍥犱负On + 杩滅▼鎺у埗鍙戦�佺粰浜戠浣跨敤鐨勬槸link鍗忚鏁版嵁锛屾潹娑涗腑杞粰楂樿儨澶勭悊鏃跺�欓�昏緫涓婃湁鍐茬獊锛屽鑷存棤娉曞崟鐙帶鍒朵寒搴﹀�硷紝闇�瑕佸悓鏃跺彂閫佸紑鍏冲�间笌浜害鍊笺��
+                    if (DB_ResidenceData.Instance.GatewayType == 0)
+                    {
+                        if (commandDictionary.Count == 1)
+                        {
+                            if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
+                            {
+                                commandDictionary.Add(FunctionAttributeKey.OnOff, commandDictionary[FunctionAttributeKey.Brightness] == "0" ? "off" : "on");
+                            }
+                        }
+                        if(function.spk == SPK.LightCCT)
+                        {
+                            if (!commandDictionary.ContainsKey(FunctionAttributeKey.CCT))
+                            {
+                                commandDictionary.Add(FunctionAttributeKey.CCT, function.GetAttrState(FunctionAttributeKey.CCT));
+                            }
+                        }
+                    }
                     DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest();
                     //ALink鎺у埗銆丅us鎺у埗浣跨敤鍚屼竴涓帴鍙f帶鍒讹紝鐢变簯绔礋璐hВ鏋�
                     var apiControlData = function.GetApiControlData(commandDictionary);
@@ -414,29 +468,59 @@
         /// </summary>
         public void SwtichFunctions(bool open,List<Function> functions)
         {
+            //dome妯″紡鎺у埗
+            if(MainPage.NoLoginMode)
+            {
+                new System.Threading.Thread(() =>
+                {
+                    foreach (var temp in functions)
+                    {
+                        Dictionary<string, string> d1 = new Dictionary<string, string>();
+                        d1.Add(FunctionAttributeKey.OnOff, open ? "on" : "off");
+                        SendWriteCommand(temp, d1);
+                        System.Threading.Thread.Sleep(100);
+                    }
+                })
+                { IsBackground = true }.Start();
+                return;
+            }
+
             var count = 0;
-            var logString = open ? "鎵撳紑\r\n" : "鍏抽棴\r\n";
             List<ApiAlinkControlActionObj> actionObjs = new List<ApiAlinkControlActionObj>();
             Dictionary<string, string> d = new Dictionary<string, string>();
             d.Add(FunctionAttributeKey.OnOff, open ? "on" : "off");
             var pm = new DAL.Server.HttpServerRequest();
-            foreach (var temp in functions)
+            //涓�绔彛鍏ㄥ紑鍏ㄥ叧闇�瑕佸欢鏃跺彂閫�
+            if (DB_ResidenceData.Instance.GatewayType == 0)
             {
-                logString += temp.spk + ":" + temp.sid + "\r\n";
-                var apiControlData = temp.GetApiControlData(d);
-                actionObjs.Add(apiControlData);
-                count++;
-                if (count > 9)
+                new System.Threading.Thread(() =>
                 {
-                    var result = pm.ControlDevice(actionObjs);
-                    actionObjs = new List<ApiAlinkControlActionObj>();
-                    count = 0;
-                    MainPage.Log(logString);
-                    logString = "";
-                }
+                    foreach (var temp in functions)
+                    {
+                        var apiControlData = temp.GetApiControlData(d);
+                        var result = pm.ControlDevice(new List<ApiAlinkControlActionObj>() { apiControlData });
+                        System.Threading.Thread.Sleep(100);
+                    }
+                })
+                { IsBackground = true }.Start();
             }
-            var pack = pm.ControlDevice(actionObjs);
-            MainPage.Log(logString);
+            else
+            {
+                foreach (var temp in functions)
+                {
+                    var apiControlData = temp.GetApiControlData(d);
+                    actionObjs.Add(apiControlData);
+                    count++;
+                    if (count > 9)
+                    {
+                        var result = pm.ControlDevice(actionObjs);
+                        actionObjs = new List<ApiAlinkControlActionObj>();
+                        count = 0;
+                        System.Threading.Thread.Sleep(100);
+                    }
+                }
+                var pack = pm.ControlDevice(actionObjs);
+            }
         }
 
         public void SendApiReadCommand(List<string> functionIds)
@@ -477,47 +561,55 @@
         /// 鍙戦�佽鍙栧懡浠�
         /// 鑷姩鍒ゆ柇鏄惁涓篈鍗忚璁惧
         /// </summary>
-        public void SendReadCommand(Function function)
+        public void SendReadCommand(Function function ,bool forceRemote = false)
         {
             function.refreshTime = DateTime.Now;
-            if (Ins.GatewayOnline_Local)
+            if (forceRemote)
             {
-
-                if (DB_ResidenceData.Instance.GatewayType == 0)
+                var pm = new DAL.Server.HttpServerRequest();
+                var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId });
+            }
+            else
+            {
+                if (Ins.GatewayOnline_Local)
                 {
-                    try
+
+                    if (DB_ResidenceData.Instance.GatewayType == 0)
                     {
-                        new Control_Udp().ReadBusData(function);
+                        try
+                        {
+                            new Control_Udp().ReadBusData(function);
+                        }
+                        catch (Exception ex)
+                        {
+                            MainPage.Log($"鍙戦�佹暟鎹紓甯�: {ex.Message}");
+                        }
                     }
-                    catch (Exception ex)
+                    else
                     {
-                        MainPage.Log($"鍙戦�佹暟鎹紓甯�: {ex.Message}");
+                        var readKey = new Dictionary<string, string>();
+                        readKey.Add("sid", function.sid);
+
+                        var readDataObj = new AlinkReadFunctionStatusObj()
+                        {
+                            id = Ins.msg_id.ToString(),
+                            objects = new List<Dictionary<string, string>>()
+                        {
+                            readKey
+                        },
+                            time_stamp = Utlis.GetTimestamp()
+                        };
+                        var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj);
+                        var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson);
+                        MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
+                        new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id);
                     }
                 }
                 else
                 {
-                    var readKey = new Dictionary<string, string>();
-                    readKey.Add("sid", function.sid);
-
-                    var readDataObj = new AlinkReadFunctionStatusObj()
-                    {
-                        id = Ins.msg_id.ToString(),
-                        objects = new List<Dictionary<string, string>>()
-                        {
-                            readKey
-                        },
-                        time_stamp = Utlis.GetTimestamp()
-                    };
-                    var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj);
-                    var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson);
-                    MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
-                    new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id);
+                    var pm = new DAL.Server.HttpServerRequest();
+                    var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId });
                 }
-            }
-            else
-            {
-                var pm = new DAL.Server.HttpServerRequest();
-                var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId });
             }
         }
 
@@ -551,7 +643,7 @@
             }
         }
         /// <summary>
-        /// 杞崲閫氳鏁版嵁
+        /// 杞崲鍙戦�佹暟鎹�
         /// </summary>
         public byte[] ConvertSendBodyData(string topic, string bodyDataString)
         {
@@ -661,15 +753,6 @@
         /// <param name="updateBytes"></param>
         public void UpdataFunctionStatus(string revString, byte[] usefulBytes,bool isCloudData = false)
         {
-
-            if (Ins.GatewayOnline_Local && isCloudData)//鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�
-            {
-                if (FunctionList.List.GetDeviceFunctionList(SPK.BrandType.Tuya).Count == 0)
-                {
-                    //MainPage.Log($"A鍗忚鏇存柊鐘舵��:鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�...");
-                    return;
-                }
-            }
             var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString);
             if (temp != null)
             {
@@ -679,6 +762,22 @@
                 {
                     try
                     {
+
+                        if (Ins.GatewayOnline_Local && isCloudData)//鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�
+                        {
+                            if (FunctionList.List.OtherBrandFunction.Count != 0)
+                            {
+                                if (FunctionList.List.OtherBrandFunction.Find((obj) => obj.sid == updateTemp.sid) == null)
+                                {
+                                    //MainPage.Log($"A鍗忚鏇存柊鐘舵��:鏈湴閾炬帴锛岄櫎浜嗘秱楦﹁澶囨暟鎹箣澶栫殑浜戠鏁版嵁涓嶅鐞�...");
+                                    return;
+                                }
+                            }
+                        }
+
+
+
+
                         var localFunction = allLocalFuntion.Find((obj) => obj.sid == updateTemp.sid);
                         if (localFunction == null)
                         {
@@ -812,6 +911,25 @@
                             case SPK.SensorTVOC:
                             case SPK.SensorTemperature:
                             case SPK.SensorHumidity:
+                                if(localFunction.spk == SPK.SensorTemperature)
+                                {
+                                    HomePage.LoadEvent_RefreshEnvirIndoorTemp();
+                                }
+                                else if (localFunction.spk == SPK.SensorHumidity)
+                                {
+                                    HomePage.LoadEvent_RefreshEnvirIndoorHumi();
+                                }
+                                EnvironmentalPage.LoadEvent_UpdataStatus(localFunction);
+                                break;
+                            case SPK.SensorEnvironment:
+                                if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Temperature))
+                                {
+                                    HomePage.LoadEvent_RefreshEnvirIndoorTemp();
+                                }
+                                if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Humidity))
+                                {
+                                    HomePage.LoadEvent_RefreshEnvirIndoorHumi();
+                                }
                                 EnvironmentalPage.LoadEvent_UpdataStatus(localFunction);
                                 break;
                             case SPK.ElectricSocket:
@@ -829,7 +947,9 @@
                             case SPK.SensorWater:
                             case SPK.ClothesHanger:
                             case SPK.AcIr:
+                            case SPK.SenesorMegahealth:
                                 //璁惧鐘舵�佹帹閫�
+                                //鐘舵�佹洿鏂�
                                 Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);
                                 break;
                         }

--
Gitblit v1.8.0