From 51cb254cbd616e84b7a466b195eb43ab097c3897 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 29 九月 2020 13:16:45 +0800
Subject: [PATCH] 20200928

---
 HDL_ON/DriverLayer/Control.cs |  142 ++++++++++++++++++++++-------------------------
 1 files changed, 67 insertions(+), 75 deletions(-)

diff --git a/HDL_ON/DriverLayer/Control.cs b/HDL_ON/DriverLayer/Control.cs
index 6f71392..84ec15d 100644
--- a/HDL_ON/DriverLayer/Control.cs
+++ b/HDL_ON/DriverLayer/Control.cs
@@ -3,6 +3,7 @@
 using HDL_ON.DAL;
 using HDL_ON.DAL.Net;
 using HDL_ON.Entity;
+using HDL_ON.UI;
 
 namespace HDL_ON
 {
@@ -13,7 +14,7 @@
         /// </summary>
         public static void Send(Function function)
         {
-            switch(function.functionCategory)
+            switch (function.functionCategory)
             {
                 case FunctionCategory.Scene:
                     ControlScene(function as Scene);
@@ -50,7 +51,7 @@
         {
             function.usageCount++;
             function.refreshTime = DateTime.Now;
-            if (function.bus_Data != null)
+            if (DB_ResidenceData.residenceData.GatewayType == 0)
             {
                 try
                 {
@@ -114,7 +115,7 @@
                         {
                             curtainState = 1;
                         }
-                        else if (function.trait_on_off.value.ToString() =="off")
+                        else if (function.trait_on_off.value.ToString() == "off")
                         {
                             curtainState = 2;
                         }
@@ -125,7 +126,7 @@
                             });
                         break;
                     case FunctionType.AC:
-                        var aC = function as AC;
+                        var aC = Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(Newtonsoft.Json.JsonConvert.SerializeObject(function));//as AC;
                         ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 3, aC.trait_on_off.value.ToString() == "on" ? (byte)1 : (byte)0, aC.bus_Data.LoopID });
                         ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 6, aC.curModeIndex, aC.bus_Data.LoopID });
                         ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 5, aC.curFanIndex, aC.bus_Data.LoopID });
@@ -154,7 +155,7 @@
                     case FunctionType.Relay:
                     case FunctionType.Dimmer:
                         byte brightness = 0;
-                        if(function.trait_on_off.value.ToString() == "on")
+                        if (function.trait_on_off.value.ToString() == "on")
                         {
                             var brightnessTrait = function.function.Find((obj) => obj.name == "brightness");
                             if (brightnessTrait != null)
@@ -173,10 +174,11 @@
                         //    });
                         break;
                     case FunctionType.FloorHeating:
-                        var fh = function as FloorHeating;
-                        if (fh.modeTemp.Count == 4)
+                        var fh = Newtonsoft.Json.JsonConvert.DeserializeObject<FloorHeating>(Newtonsoft.Json.JsonConvert.SerializeObject(function));//as AC;
+                        var fhModeTempTrait = function.function.Find((obj) => obj.name == "mode");
+                        if (fhModeTempTrait.value_key.Count == 4)
                         {
-                            byte b1 = fh.trait_on_off.value.ToString() == "on" ? (byte)1 : (byte)0;
+                            byte b1 = function.trait_on_off.value.ToString() == "on" ? (byte)1 : (byte)0;
                             if (fh.workMode > 0)
                             {
                                 b1 += (byte)(16 + fh.workMode);
@@ -185,8 +187,8 @@
                         }
                         break;
                     case FunctionType.Socket:
-                        var s = function as SwitchSocket;
-                        ControlBytesSend(Command.SetSingleLight, function.bus_Data.SubnetID, function.bus_Data.DeviceID, new byte[] { s.bus_Data.LoopID, s.trait_on_off.value.ToString() == "on" ? (byte)100 : (byte)0 });
+                        //var s = function as SwitchSocket;
+                        ControlBytesSend(Command.SetSingleLight, function.bus_Data.SubnetID, function.bus_Data.DeviceID, new byte[] { function.bus_Data.LoopID, function.trait_on_off.value.ToString() == "on" ? (byte)100 : (byte)0 });
                         break;
                 }
             }
@@ -219,7 +221,6 @@
                 var deviceId = function.bus_Data.DeviceID;
                 var loopId = function.bus_Data.LoopID;
 
-
                 switch (function.functionCategory)
                 {
                     case FunctionCategory.Light:
@@ -239,7 +240,7 @@
                                 }
                                 var bytes = new byte[] { function.bus_Data.LoopID,
                                             b,
-                                            254, 0,0,3,
+                                            254, 0,Convert.ToByte(light.fadeTime) ,3,
                                             (byte)light.redColor,(byte)light.greenColor,
                                             (byte)light.blueColor,
                                             0,0};
@@ -258,10 +259,12 @@
                                 ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] {
                                             function.bus_Data.LoopID,
                                             b1,
-                                            0, 0 });
+                                            0, Convert.ToByte(light.fadeTime) });
+                                DimmerPage.UpdataStates(light);
                                 break;
                             case FunctionType.Relay:
                                 ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { function.bus_Data.LoopID, light.trait_on_off.value.ToString() == "on" ? (byte)100 : (byte)0, 0, 0 });
+                                RelayPage.UpdataState(light);
                                 break;
                         }
                         break;
@@ -287,18 +290,33 @@
                                 break;
                             case FunctionType.MotorCurtain:
                             case FunctionType.RollingShutter:
+                                //if (commandDictionary.Count > 0)
+                                //{
                                 if (curtain.trait_on_off.value.ToString() == "stop")
                                 {
                                     ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { curtain.bus_Data.LoopID, 0 });
                                 }
-                                else if (curtain.trait_on_off.value.ToString() == "on")
+                                else
                                 {
-                                    ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, 100 });
+                                    ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, Convert.ToByte(curtain.percent) });
+
                                 }
-                                else if (curtain.trait_on_off.value.ToString() == "off")
-                                {
-                                    ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, 0 });
-                                }
+                                //}
+                                //else
+                                //{
+                                //    if (curtain.trait_on_off.value.ToString() == "stop")
+                                //    {
+                                //        ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { curtain.bus_Data.LoopID, 0 });
+                                //    }
+                                //    else if (curtain.trait_on_off.value.ToString() == "on")
+                                //    {
+                                //        ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, 100 });
+                                //    }
+                                //    else if (curtain.trait_on_off.value.ToString() == "off")
+                                //    {
+                                //        ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, 0 });
+                                //    }
+                                //}
                                 break;
                         }
                         break;
@@ -307,7 +325,7 @@
                         {
                             case FunctionType.AC:
                                 var aC = function as AC;
-                                ControlBytesSend(Command.SetACMode, subnetId, deviceId, new byte[] { aC.bus_Data.LoopID, (byte)aC.curTempType, 32, 32, 32, 32, 32, 0, aC.trait_on_off.value.ToString() == "on" ? (byte)1 : (byte)0, aC.curModeIndex, aC.curFanIndex, (byte)aC.trait_temp.value, 0 });
+                                ControlBytesSend(Command.SetACMode, subnetId, deviceId, new byte[] { aC.bus_Data.LoopID, (byte)aC.curTempType, 32, 32, 32, 32, 32, 0, aC.trait_on_off.value.ToString() == "on" ? (byte)1 : (byte)0, aC.curModeIndex, aC.curFanIndex, Convert.ToByte(aC.trait_temp.value), 0 });
                                 //ControlBytesSend(Command.InstructionPanelKey, aC.bus_Data.SubnetID, aC.bus_Data.DeviceID, new byte[] { 3, aC.on_off == "on" ? (byte)1 : (byte)0, aC.bus_Data.LoopID });
                                 foreach (var dic in commandDictionary)
                                 {
@@ -360,12 +378,29 @@
                                     {
                                         b1 += (byte)(16 + fh.workMode);
                                     }
+                                    if (commandDictionary.ContainsKey("temp"))
+                                    {
+                                        var dicTempString = "";
+                                        commandDictionary.TryGetValue("temp", out dicTempString);
+                                        var dicTemp = Convert.ToByte(dicTempString);
+                                        switch (fh.trait_mode.value)
+                                        {
+                                            case "day":
+                                                fh.modeTemp["day"] = dicTemp;
+                                                break;
+                                            case "night":
+                                                fh.modeTemp["night"] = dicTemp;
+                                                break;
+                                            case "away":
+                                                fh.modeTemp["away"] = dicTemp;
+                                                break;
+                                            case "normal":
+                                                fh.modeTemp["normal"] = dicTemp;
+                                                break;
+                                        }
+                                    }
                                     ControlBytesSend(Command.SetFloorHeat, subnetId, deviceId, new byte[] { fh.bus_Data.LoopID, b1, (byte)fh.curTempType, fh.curModeIndex, fh.modeTemp["normal"], fh.modeTemp["day"], fh.modeTemp["night"], fh.modeTemp["away"], 0, 0 });
                                 }
-                                //else
-                                //{
-                                //    ControlBytesSend(Command.ReadFloorHeat, subnetId,deviceId,new byte[] { fh.bus_Data.LoopID});
-                                //}
                                 break;
                         }
                         break;
@@ -394,55 +429,12 @@
                         }
                         break;
                 }
-
-
-                foreach (var dic in commandDictionary)
-                {
-                    switch (dic.Key)
-                    {
-                        case "on_off":
-                            break;
-                        case "brightness":
-                            break;
-                        case "color":
-                            break;
-                        default:
-                            MainPage.Log($"鍔熻兘鏈敮鎸� : {dic.Key}");
-                            break;
-                            //case "cct":
-                            //case "delay":
-                            //case "fade_time":
-                            //case "open_level":
-                            //case "lock":
-                            //case "ico":
-                            //case "mode":
-                            //case "fan":
-                            //case "temp":
-                            //case "swing":
-                            //case "set_ point":
-                            //case "pm25":
-                            //case "volume":
-                            //case "vol_step":
-                            //case "source":
-                            //case "treble":
-                            //case "bass":
-                            //case "playlist":
-                            //case "song_name":
-                            //case "current_status":
-                            //case "enable":
-                            //case "lux":
-                            //case "adjust_value":
-                            //case "range":
-                            //case "humidity":
-                            //case "type":
-                            //case "state":
-                            //case "sensitivity":
-                            //case "pm25value":
-                    }
-                }
-
-
-
+                #region 鍙戦�佸懡浠ょ珛鍗虫洿鏂癠I
+                HomePage.UpdataFunctionStates(function);
+                RoomPage.UpdataStates(function);
+                FunctionPage.UpdataStates(function);
+                ClassificationPage.UpdataInfo(function);
+                #endregion
             }
             catch (Exception ex)
             {
@@ -501,7 +493,7 @@
                         {
                             case FunctionType.Fan:
                                 var fan = function as Fan;
-                                ControlBytesSend(Command.SetSingleLightACK, subnetId, deviceId, new byte[] { fan.bus_Data.LoopID });
+                                ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { fan.bus_Data.LoopID });
                                 break;
                         }
                         break;
@@ -510,7 +502,7 @@
                         {
                             case FunctionType.Socket:
                                 var s = function as SwitchSocket;
-                                ControlBytesSend(Command.SetSingleLightACK, subnetId, deviceId, new byte[] { s.bus_Data.LoopID });
+                                ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { s.bus_Data.LoopID });
                                 break;
                         }
                         break;

--
Gitblit v1.8.0