From 068c68295cad1967f7aafb4e5e951260ef03d4ce Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期五, 09 七月 2021 09:16:43 +0800
Subject: [PATCH] 状态属性更改,不要轻易合并

---
 HDL_ON/Entity/Function/Function.cs |  206 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 177 insertions(+), 29 deletions(-)

diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs
index a6beab4..d918442 100644
--- a/HDL_ON/Entity/Function/Function.cs
+++ b/HDL_ON/Entity/Function/Function.cs
@@ -1,4 +1,4 @@
-锘縰sing System;
+using System;
 using System.Collections.Generic;
 using HDL_ON.Common;
 using HDL_ON.DAL.Server;
@@ -126,7 +126,6 @@
         /// <returns>淇敼缁撴灉</returns>
         public bool SetAttrState(string key, object value)
         {
-            //var attrState = status.Find((s) => s.key == key.ToString());
             var attr = attributes.Find((s) => s.key == key);
             if (attr == null)
             {
@@ -135,7 +134,6 @@
             else
             {
                 attr.state = value.ToString();
-                attr.curValue = value.ToString();
             }
             return true;
         }
@@ -173,7 +171,7 @@
         #endregion
 
 
-        #region base info
+        #region base info    
         public string sid = "0301011234567801012301230123";
         /// <summary>
         /// 澶囨敞
@@ -272,16 +270,21 @@
                             max = 1,
                             min = 0,
                         };
-                        _trait_on_off.curValue = "off";
+                        _trait_on_off.state = "off";
                     }
                 }
-                if(_trait_on_off.curValue.ToString() != "on"&& _trait_on_off.curValue.ToString() != "off" && _trait_on_off.curValue.ToString() != "stop")
+                if(_trait_on_off.state.ToString() != "on"&& _trait_on_off.state.ToString() != "off" && _trait_on_off.state.ToString() != "stop")
                 {
-                    _trait_on_off.curValue = "off";
+                    _trait_on_off.state = "off";
                 }
                 return _trait_on_off;
             }
         }
+        /// <summary>
+        /// 鍔熻兘鐨勫睘鎬х姸鎬佸垪琛�
+        /// </summary>
+        public List<AttributesStatus> status = new List<AttributesStatus>();
+
 
         /// <summary>
         /// 浣跨敤娆℃暟
@@ -423,6 +426,19 @@
             var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
             FileUtlis.Files.WriteFileByBytes(savePath, ssd);
         }
+
+        /// <summary>
+        /// 閫氳繃鐘舵�佸垪琛ㄧ粍瑁呭睘鎬ч噷闈㈢殑鐘舵��
+        /// </summary>
+        public void AssembleStatus()
+        {
+            foreach(var sta in status)
+            {
+                SetAttrState(sta.key, sta.value);
+            }
+        }
+
+
         /// <summary>
         /// 淇濆瓨鎴块棿缁戝畾淇℃伅
         /// </summary>
@@ -502,26 +518,48 @@
                     case FunctionAttributeKey.FanSpeed:
                     case FunctionAttributeKey.Percent:
                     //case FunctionAttributeKey.FadeTime:
-                        if (attr.curValue.ToString() == "{}")
+                        if (attr.state.ToString() == "{}")
                         {
                             if (attr.key == FunctionAttributeKey.OnOff)
                             {
-                                attr.curValue = "off";
+                                attr.state = "off";
                             }
-                            else
+                            else if (attr.key == FunctionAttributeKey.Mode )
                             {
-                                attr.curValue = "0";
+                                if (DB_ResidenceData.Instance.GatewayType == 0)
+                                {
+                                    attr.state = "0";
+                                }
+                                else
+                                {
+                                    if (SPK.AcSpkList().Contains(spk))
+                                    {
+                                        attr.state = "cool";
+                                    }
+                                    else if (SPK.FhSpkList().Contains(spk))
+                                    {
+                                        attr.state = "day";
+                                    }
+                                }
+                            }
+                            else 
+                            {
+                                attr.state = "0";
                             }
                         }
                         if (attr.key == FunctionAttributeKey.SetTemp)
                         {
                             double vv = 16;
-                            Double.TryParse(attr.curValue.ToString(), out vv);
+                            Double.TryParse(attr.state.ToString(), out vv);
+                            if (vv == 0)
+                            {
+                                vv = 26;
+                            }
                             sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = Convert.ToInt32(vv).ToString() });
                         }
                         else
                         {
-                            sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = attr.curValue.ToString() });
+                            sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = attr.state.ToString() });
                         }
                         break;
                 }
@@ -639,7 +677,7 @@
         public List<AttributesStatus> status = new List<AttributesStatus>();
     }
     /// <summary>
-    /// a鍗忚鎺у埗鍔ㄤ綔鏁版嵁
+    /// 鍔熻兘灞炴�х姸鎬�
     /// </summary>
     public class AttributesStatus
     {
@@ -654,6 +692,20 @@
         /// </summary>
         public string value = "";
     }
+
+    public class attttttt
+    {
+        /// <summary>
+        /// 褰撳墠鐘舵��
+        /// </summary>
+        public string state = "";
+        /// <summary>
+        /// 褰撳墠鍊�
+        /// </summary>
+        public object curValue = new object();
+
+    }
+
 
     /// <summary>
     /// 鍔熻兘灞炴��
@@ -686,11 +738,8 @@
         /// 褰撳墠鐘舵��
         /// </summary>
         public string state = "";
-        /// <summary>
-        /// 褰撳墠鍊�
-        /// </summary>
-        public object curValue = new object();
     }
+
     /// <summary>
     /// 鍔熻兘灞炴�ч敭鍚嶅垪琛�
     /// </summary>
@@ -717,6 +766,10 @@
         /// 妯″紡
         /// </summary>
         public const string Mode = "mode";
+        /// <summary>
+        /// 鎵
+        /// </summary>
+        public const string Swing = "swing";
         /// <summary>
         /// 宸ヤ綔妯″紡
         /// 鍦扮儹/鍦板喎/鍔熺巼鍦扮儹/鍔熺巼鍦板喎
@@ -748,6 +801,7 @@
         /// 绌鸿皟銆佸湴鐑�//app鑷姞
         /// </summary>
         public const string TempType = "temperature_type";
+
         /// <summary>
         /// 鏃堕棿鏍囪
         /// 鍦扮儹//app鑷姞
@@ -777,6 +831,10 @@
         /// 鐘舵��,浼犳劅鍣�
         /// </summary>
         public const string Status = "status";
+        /// <summary>
+        /// 姣背娉紶鎰熷櫒锛屽姩浣滅姸鎬�
+        /// </summary>
+        public const string ActionStatus = "action_state";
         /// <summary>
         /// 鐢甸噺鐘舵��
         /// </summary>
@@ -855,6 +913,10 @@
         /// </summary>
         public const string Humidity = "humidity";
         /// <summary>
+        /// 娓╁害
+        /// </summary>
+        public const string Temperature = "temperature";
+        /// <summary>
         /// 瀹ゅ唴娓╁害
         /// </summary>
         public const string IndoorTemp = "indoor_temp";
@@ -877,6 +939,14 @@
         /// </summary>
         public const string TuyaWaterTime = "countdown_1";
         #endregion
+        /// <summary>
+        /// 鍔熺巼
+        /// </summary>
+        public const string Power = "power";
+        /// <summary>
+        /// 鎬荤數閲�
+        /// </summary>
+        public const string TotalElectricity = "total_electricity";
 
 
     }
@@ -934,6 +1004,8 @@
 
     public static class SPK
     {
+       
+
 
         #region 鐏厜
         /// <summary>
@@ -1075,6 +1147,11 @@
         /// 鑳芥簮妯″潡
         /// </summary>
         public const string EnergyStandard = "energy.standard";
+
+        /// <summary>
+        /// 鑳芥簮-鐢佃兘
+        /// </summary>
+        public const string ElectricEnergy = "energy.electric";
         /// <summary>
         /// 鑳芥簮spk鍒楄〃
         /// </summary>
@@ -1082,7 +1159,7 @@
         public static List<string> EnergySpkList()
         {
             var spkList = new List<string>();
-            spkList.Add(EnergyStandard);
+            spkList.Add(ElectricEnergy);
             return spkList;
         }
         #endregion
@@ -1142,12 +1219,15 @@
         /// <summary>
         /// 瓒呭0娉紶鎰熷櫒
         /// </summary>
-        public const string SensoruUtrasonic = "sensor.ultrasonic";
+        public const string SensorUtrasonic = "sensor.ultrasonic";
         /// <summary>
         /// 锛堝共鎺ョ偣锛�
         /// </summary>
         public const string SensorDryContact = "sensor.dryContact";
-
+        /// <summary>
+        /// 姣背娉紶鎰熷櫒
+        /// </summary>
+        public const string SenesorMegahealth = "sensor.megahealth";
         /// <summary>
         /// 瀹夐槻浼犳劅鍣╯pk鍒楄〃
         /// </summary>
@@ -1155,16 +1235,17 @@
         public static List<string> ArmSensorSpkList()
         {
             var spkList = new List<string>();
-            spkList.Add(SensorLight);
+            //spkList.Add(SensorLight);
             spkList.Add(SensorPir);
             spkList.Add(SensorDoorWindow);
             spkList.Add(SensorSmoke);
             spkList.Add(SensorWater);
-            spkList.Add(SensorGas);
-            spkList.Add(SensorShanLan);
-            spkList.Add(SensorDuiShe);
-            spkList.Add(SensoruUtrasonic);
-            spkList.Add(SensorDryContact);
+            //spkList.Add(SensorGas);
+            //spkList.Add(SensorShanLan);
+            //spkList.Add(SensorDuiShe);
+            //spkList.Add(SensoruUtrasonic);
+            //spkList.Add(SensorDryContact);
+            spkList.Add(SenesorMegahealth);
             return spkList;
         }
         #endregion
@@ -1190,6 +1271,13 @@
         /// 婀垮害浼犳劅鍣�
         /// </summary>
         public const string SensorHumidity = "sensor.humidity";
+        /// <summary>
+        /// 鐜浼犳劅鍣�
+        /// 鐜妫�娴嬩紶鎰熷櫒
+        /// 鐗规畩绫籹pk
+        /// 璇pk鍔熻兘鏄幆澧冧紶鎰熷櫒鍔熻兘鐨勯泦鎴�
+        /// </summary>
+        public const string SensorEnvironment = "sensor.environment";
 
         /// <summary>
         /// 鐜浼犳劅鍣╯pk鍒楄〃
@@ -1203,6 +1291,7 @@
             spkList.Add(SensorCO2);
             spkList.Add(SensorTVOC);
             spkList.Add(SensorHumidity);
+            spkList.Add(SensorEnvironment);
             return spkList;
         }
         #endregion
@@ -1222,6 +1311,10 @@
         /// </summary>
         public const string TvIr = "ir.tv";
         /// <summary>
+        /// 绾㈠銆佸皬绫崇數瑙�
+        /// </summary>
+        public const string TvXmIr = "ir.tvxm";
+        /// <summary>
         /// 瀹剁數銆侀鎵�
         /// </summary>
         public const string ElectricFan = "electrical.fan";
@@ -1233,6 +1326,30 @@
         /// 绾㈠閬ユ帶鍣�
         /// </summary>
         public const string IrLearn = "ir.learn";
+        /// <summary>
+        /// 绾㈠鎶曞奖浠�
+        /// </summary>
+        public const string PjtIr = "ir.pjt";
+        /// <summary>
+        /// 绾㈠鏈洪《鐩�
+        /// </summary>
+        public const string StbIr = "ir.stb";
+        /// <summary>
+        /// 绾㈠褰辩鏈�
+        /// </summary>
+        public const string DvDIr = "ir.dvd";
+        /// <summary>
+        /// 绾㈠绌烘皵鍑�鍖栧櫒
+        /// </summary>
+        public const string PurifierIr = "ir.air_purifier";
+        /// <summary>
+        /// 绾㈠鐑按鍣�
+        /// </summary>
+        public const string HeaterIr = " ir.water_heater";
+        /// <summary>
+        /// 绾㈠椋庢墖
+        /// </summary>
+        public const string FanIr = "ir.fan";
 
         #region 娑傞甫
         /// <summary>
@@ -1264,9 +1381,13 @@
             spkList.Add(ElectricSocket);
             spkList.Add(ElectricTV);
             spkList.Add(TvIr);
+            spkList.Add(TvXmIr);
             spkList.Add(ElectricFan);
+            spkList.Add(FanIr);
             spkList.Add(ClothesHanger);
             spkList.Add(IrLearn);
+            spkList.Add(PjtIr);
+            spkList.Add(StbIr);
             spkList.Add(ElectricTuyaAirCleaner);
             spkList.Add(ElectricTuyaFan);
             spkList.Add(ElectricTuyaWeepRobot);
@@ -1295,7 +1416,21 @@
         }
         #endregion
 
-
+        #region 绗笁鏂箂pk鍒楄〃
+        /// <summary>
+        /// 鑾峰彇鎵�鏈夌涓夋柟鍝佺墝鍔熻兘鐨剆pk
+        /// </summary>
+        /// <returns></returns>
+        public static List<string> GetAll3tySPK()
+        {
+            var spkList = new List<string>();
+            spkList.Add(ElectricTuyaAirCleaner);
+            spkList.Add(ElectricTuyaFan);
+            spkList.Add(ElectricTuyaWaterValve);
+            spkList.Add(ElectricTuyaWeepRobot);
+            spkList.Add(SenesorMegahealth);
+            return spkList;
+        }
         /// <summary>
         /// 鑾峰彇绗笁鏂硅澶噑pk
         /// </summary>
@@ -1306,17 +1441,26 @@
 
             switch (brandType)
             {
-                case BrandType.All3tyBrand:
                 case BrandType.Tuya:
                     list.Add(ElectricTuyaAirCleaner);
                     list.Add(ElectricTuyaFan);
                     list.Add(ElectricTuyaWaterValve);
                     list.Add(ElectricTuyaWeepRobot);
                     break;
+                case BrandType.All3tyBrand:
+                    list.Add(SenesorMegahealth);//鍏嗚
+                    break;
             }
             return list;
         }
+        #endregion
 
+        /// <summary>
+        /// 娌℃湁鐘舵�佹樉绀虹殑鍔熻兘spk鍒楄〃
+        /// </summary>
+        public static List<string> NotStatusSpkList = new List<string> {
+            ElectricTV, FanIr, TvIr, TvXmIr, StbIr, PjtIr, IrLearn
+        };
 
         /// <summary>
         /// 绗笁鏂瑰搧鐗屽垪琛�
@@ -1326,6 +1470,10 @@
             All = 0,
             Hdl = 1,
             Tuya = 2,
+            /// <summary>
+            /// 鍏嗚
+            /// </summary>
+            Megahealth = 3,
 
 
             All3tyBrand = 999,

--
Gitblit v1.8.0