From 944b87b6bcccb095cd73f13f4410fb20faf48f74 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期三, 25 十二月 2019 11:21:06 +0800
Subject: [PATCH] 2019.12.25

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/AC.cs |  254 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 249 insertions(+), 5 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/AC.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/AC.cs
index 15ee0ba..b70e603 100644
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/AC.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/AC.cs
@@ -27,6 +27,11 @@
         public int currentCoolingSetpoint = 0;
 
         /// <summary>
+        /// 褰撳墠鑷姩娓╁害
+        /// </summary>
+        public int currentAutoSetpoint;
+
+        /// <summary>
         ///鎭掓俯璁惧绫诲瀷
         /// <para>鎭掓俯璁惧鍏峰鍔熻兘锛孉ttribute Values濡備笅</para>
         /// <para>0:(Cooling Only) 鏃燞eat鍜孍mergency鍔熻兘</para>
@@ -66,6 +71,17 @@
         public int currentFanMode = 0;
 
         /// <summary>
+        /// 椋庢墖zz鎵褰撳墠妯″紡
+        /// <para>0:1鎸� </para>
+        /// <para>1:2</para>
+        /// <para>2:3</para>
+        /// <para>3:4 </para>
+        /// <para>4:5 </para>
+        /// <para>7:Auto </para>
+        /// </summary>
+        public int currentFanSwingMode = 0;
+
+        /// <summary>
         /// 鏀寔鐨勬帶鍒舵ā寮�
         /// </summary>
         public List<AcMode> acModes = new List<AcMode> { };
@@ -74,7 +90,17 @@
         /// 鏀寔鐨勯閫熸ā寮�
         /// </summary>
         public List<FanMode> fanModes = new List<FanMode> { };
+        /// <summary>
+        /// <para>鑷畾涔夌┖璋冩敮鎸佺殑妯″紡(榛樿鍏ㄥ叧)</para>
+        /// <para>鏁扮粍绱㈠紩 -> 0:鍒跺喎 1:鍒剁儹 2:閫侀 3:闄ゆ箍 4:鑷姩</para>
+        /// <para>鍊� -> 1:浠h〃浣跨敤  0:浠h〃涓嶄娇鐢�</para>
+        /// </summary>
+        public int[] listSupportMode = new int[5] { 0, 0, 0, 0, 0 };
 
+        /// <summary>
+        /// 杩囨护缃戞竻娲楃姸鎬�
+        /// </summary>
+        public bool CleanStatu = false;
 
         /// <summary>
         /// 鑾峰彇褰撳墠瀹ゅ唴娓╁害.
@@ -101,6 +127,16 @@
         public void ReadHeatingSetpoint()
         {
             ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.HeatingSetpoint);
+        }
+
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠鑷姩搴︽暟.
+        /// <para>AttriButeId=18 (鍏堣皟鐢ㄥ彂鐜板睘鎬ф帴鍙o紝鏌ョ湅璁惧鏄惁鏀寔璇ユ帴鍙g殑灞炴�э級</para>
+        /// </summary>
+        public void ReadAutoSetpoint()
+        {
+            ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.AutoSetpoint);
         }
 
         /// <summary>
@@ -138,6 +174,140 @@
         {
             ReadAttri(Device.Cluster_ID.FanControl, AttriButeId.FanModeSequence);
         }
+
+        /// <summary>
+        /// 鑾峰彇绌鸿皟鑷畾涔夎缃殑鏀寔妯″紡
+        /// </summary>
+        public void ReadModeSupport()
+        {
+            ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.AcModeSupport);
+        }
+
+        /// <summary>
+        /// 杩囨护缃戞竻娲楃姸鎬�
+        /// </summary>
+        public void ReadCleanStatu()
+        {
+            ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.CleanStatu);
+        }
+
+        /// <summary>
+        /// 鎵妯″紡
+        /// </summary>
+        public enum FanSwingMode
+        {
+            /// <summary>
+            /// 涓�妗�
+            /// </summary>
+            First = 0,
+            /// <summary>
+            /// 浜屾尅
+            /// </summary>
+            Second = 1,
+            /// <summary>
+            /// 涓夋尅
+            /// </summary>
+            Thrid = 2,
+            /// <summary>
+            /// 鍥涙尅
+            /// </summary>
+            Fourth = 3,
+            /// <summary>
+            /// 浜旀。
+            /// </summary>
+            Fifth = 4,
+            /// <summary>
+            /// 鑷姩
+            /// </summary>
+            Auto = 7
+        }
+        /// <summary>
+        /// 鑾峰彇鎵妯″紡
+        /// </summary>
+        public void ReadSystemFansSwingMode()
+        {
+            ReadAttri(Device.Cluster_ID.FanSwing, AttriButeId.FanSwing);
+        }
+        /// <summary>
+        /// 璁剧疆鎵妯″紡
+        /// </summary>
+        /// <param name="fanSwing"></param>
+        /// <returns></returns>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetFanSwingAsyncMode(FanSwingMode fanSwing)
+        {
+            if (Gateway == null)
+            {
+                return null;
+            }
+            return await System.Threading.Tasks.Task.Run(async () =>
+            {
+                SetWritableValueResponAllData d = null;
+                Action<string, string> action = (topic, message) =>
+                {
+                    var gatewayID = topic.Split('/')[0];
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+
+                    if (topic == gatewayID + "/" + "Error_Respon")
+                    {
+                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+
+                        if (temp == null)
+                        {
+                            d = new SetWritableValueResponAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+                        }
+                        else
+                        {
+                            d = new SetWritableValueResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                        }
+                    }
+
+                    if (topic == gatewayID + "/" + "SetWritableValue_Respon")
+                    {
+                        var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
+                        var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
+
+                        if (tempData == null)
+                        {
+                            d = new SetWritableValueResponAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                        }
+                        else
+                        {
+                            d = new SetWritableValueResponAllData { setWritableValueResponData = tempData };
+                            DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
+                        }
+                    }
+                };
+                Gateway.Actions += action;
+                DebugPrintLog("SetWritableValue_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
+                try
+                {
+                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 514 }, { "Command", 120 } };
+                    var data = new JObject { { "Undivided", 0 }, { "AttributeId", 4096 }, { "AttributeDataType", 48 }, { "AttributeData", (int)fanSwing } };
+                    jObject.Add("Data", data);
+                    Gateway.Send("SetWritableValue", jObject.ToString());
+                }
+                catch { }
+
+                var dateTime = DateTime.Now;
+                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
+                {
+                    await System.Threading.Tasks.Task.Delay(10);
+                    if (d != null)
+                    {
+                        break;
+                    }
+                }
+                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
+                {
+                    d = new SetWritableValueResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                }
+                Gateway.Actions -= action;
+                DebugPrintLog("SetWritableValue_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+                return d;
+            });
+        }
+
 
         ///<summary >
         ///璁剧疆鍒跺喎搴︽暟.
@@ -271,6 +441,84 @@
                 {
                     var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 513 }, { "Command", 120 } };
                     var data = new JObject { { "Undivided", 0 }, { "AttributeId", 18 }, { "AttributeDataType", 41 }, { "AttributeData", (int)temperature } };
+                    jObject.Add("Data", data);
+                    Gateway.Send("SetWritableValue", jObject.ToString());
+                }
+                catch { }
+
+                var dateTime = DateTime.Now;
+                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
+                {
+                    await System.Threading.Tasks.Task.Delay(10);
+                    if (d != null)
+                    {
+                        break;
+                    }
+                }
+                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
+                {
+                    d = new SetWritableValueResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+                }
+                Gateway.Actions -= action;
+                DebugPrintLog("SetWritableValue_Actions 閫�鍑�" + System.DateTime.Now.ToString());
+                return d;
+            });
+        }
+
+        ///<summary >
+        ///璁剧疆鑷姩搴︽暟.
+        /// </summary>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetAutoTemperatureAsync(int temperature)
+        {
+            if (Gateway == null)
+            {
+                return null;
+            }
+            return await System.Threading.Tasks.Task.Run(async () =>
+            {
+                SetWritableValueResponAllData d = null;
+                Action<string, string> action = (topic, message) =>
+                {
+                    var gatewayID = topic.Split('/')[0];
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+
+                    if (topic == gatewayID + "/" + "Error_Respon")
+                    {
+                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
+                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+
+                        if (temp == null)
+                        {
+                            d = new SetWritableValueResponAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+                        }
+                        else
+                        {
+                            d = new SetWritableValueResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+                        }
+                    }
+
+                    if (topic == gatewayID + "/" + "SetWritableValue_Respon")
+                    {
+                        var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
+                        var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
+
+                        if (tempData == null)
+                        {
+                            d = new SetWritableValueResponAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+                        }
+                        else
+                        {
+                            d = new SetWritableValueResponAllData { setWritableValueResponData = tempData };
+                            DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
+                        }
+                    }
+                };
+                Gateway.Actions += action;
+                DebugPrintLog("SetWritableValue_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
+                try
+                {
+                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 513 }, { "Command", 120 } };
+                    var data = new JObject { { "Undivided", 0 }, { "AttributeId", 4096 }, { "AttributeDataType", 41 }, { "AttributeData", (int)temperature } };
                     jObject.Add("Data", data);
                     Gateway.Send("SetWritableValue", jObject.ToString());
                 }
@@ -647,7 +895,6 @@
 
                 try
                 {
-                    OpenPassthroughControl(Gateway);
                     var passData = ReadACFirewareVersionData(reserve);
                     var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                     var data = new JObject { { "PassData", passData } };
@@ -815,7 +1062,6 @@
 
                 try
                 {
-                    OpenPassthroughControl(Gateway);
                     var passData = UpggradeACNotificationData(firewareVer, firewareSize);
                     var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                     var data = new JObject { { "PassData", passData } };
@@ -968,7 +1214,6 @@
 
             try
             {
-                OpenPassthroughControl(Gateway);
                 string passData = "";
                 if (upgradeData != null)
                 {
@@ -1031,7 +1276,7 @@
                     status = "ff";
                 }
 
-              
+
                 offset = upgradeData.offset;
 
                 var dl = Convert.ToString(upgradeData.dataLength, 16);
@@ -1116,7 +1361,6 @@
 
             try
             {
-                OpenPassthroughControl(Gateway);
                 var passData = SendFinishDataString(status);
                 var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                 var data = new JObject { { "PassData", passData } };

--
Gitblit v1.8.0