From f71e74b5f0d2716fbf05da016cdaa18d64e09f80 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 31 十二月 2020 17:01:18 +0800
Subject: [PATCH] 又换完成最新门锁。空气质量传感器完成数据和基本配置功能。开发图表和自动化的同事可下载此代码

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

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/AC.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/AC.cs
new file mode 100755
index 0000000..7de29dc
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/AC.cs
@@ -0,0 +1,798 @@
+锘縰sing System;
+using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
+namespace ZigBee.Device
+{
+    [System.Serializable]
+    public class AC : CommonDevice
+    {
+        public AC()
+        {
+            this.Type = DeviceType.Thermostat;
+        }
+
+        /// <summary>
+        ///褰撳墠瀹ゅ唴娓╁害
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public int currentLocalTemperature = 0;
+        /// <summary>
+        /// 褰撳墠鍔犵儹搴︽暟
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public int currentHeatingSetpoint = 0;
+        /// <summary>
+        /// 褰撳墠鍒跺喎搴︽暟
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public int currentCoolingSetpoint = 0;
+        /// <summary>
+        /// 褰撳墠鑷姩娓╁害
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public int currentAutoSetpoint;
+        /// <summary>
+        /// 鎭掓俯璁惧褰撳墠妯″紡
+        /// <para>鎭掓俯璁惧鍏峰鍔熻兘锛孲ystemMode Attribute Values濡備笅</para>
+        /// <para>0:Off </para>
+        /// <para>1:Auto </para>
+        /// <para>3:Cool </para>
+        /// <para>4:Heat </para>
+        /// <para>5:Emergency heating </para>
+        /// <para>6:Precooling</para>
+        /// <para>7:Fan only </para>
+        /// <para>8:Dry </para>
+        /// <para>9:Sleep</para>
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public int currentSystemMode = 0;
+        /// <summary>
+        /// 椋庢墖褰撳墠妯″紡
+        /// <para>0:Off </para>
+        /// <para>1:Low </para>
+        /// <para>2:Medium</para>
+        /// <para>3:High </para>
+        /// <para>4:On </para>
+        /// <para>5:Auto </para>
+        /// <para>6:Smart</para>
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        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>
+        [Newtonsoft.Json.JsonIgnore]
+        public int currentFanSwingMode = 0;
+        /// <summary>
+        /// <para>鑷畾涔夌┖璋冩敮鎸佺殑妯″紡(榛樿鍏ㄥ紑)</para>
+        /// <para>鏁扮粍绱㈠紩 -> 0:鍒跺喎 1:鍒剁儹 2:閫侀 3:闄ゆ箍 4:鑷姩</para>
+        /// <para>鍊� -> 1:浠h〃浣跨敤  0:浠h〃涓嶄娇鐢�</para>
+        /// </summary>
+        public int[] listSupportMode = new int[5] { 1, 1, 1, 1, 1 };
+        /// <summary>
+        /// 鏄惁鍚敤鎽嗛鍔熻兘 false:涓嶄娇鐢ㄦ憜椋庡姛鑳� true:浣跨敤鎽嗛鍔熻兘
+        /// </summary>
+        public bool UseSwingFunction = true;
+        /// <summary>
+        /// 绌鸿皟妯″潡鐗堟湰
+        /// </summary>
+        public string AcModelVersion = string.Empty;
+        /// <summary>
+        /// 杩囨护缃戞竻娲楃姸鎬�
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public bool CleanStatu = false;
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠瀹ゅ唴娓╁害.
+        /// <para>AttriButeId=0 (鍏堣皟鐢ㄥ彂鐜板睘鎬ф帴鍙o紝鏌ョ湅璁惧鏄惁鏀寔璇ユ帴鍙g殑灞炴�э級</para>
+        /// </summary>
+        public void ReadLocalTemperature()
+        {
+            ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.LocalTemperature);
+        }
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠鍒跺喎搴︽暟.
+        /// <para>AttriButeId=17 (鍏堣皟鐢ㄥ彂鐜板睘鎬ф帴鍙o紝鏌ョ湅璁惧鏄惁鏀寔璇ユ帴鍙g殑灞炴�э級</para>
+        /// </summary>
+        public void ReadCoolingSetpoint()
+        {
+            ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.CoolingSetpoint);
+        }
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠鍔犵儹搴︽暟.
+        /// <para>AttriButeId=18 (鍏堣皟鐢ㄥ彂鐜板睘鎬ф帴鍙o紝鏌ョ湅璁惧鏄惁鏀寔璇ユ帴鍙g殑灞炴�э級</para>
+        /// </summary>
+        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>
+        /// 鑾峰彇鎭掓俯璁惧绫诲瀷(******娴嬭瘯璁惧杩斿洖鐨凙ttriBute灞炴�ф槸绌�)
+        /// <para>AttriButeId=27 (鍏堣皟鐢ㄥ彂鐜板睘鎬ф帴鍙o紝鏌ョ湅璁惧鏄惁鏀寔璇ユ帴鍙g殑灞炴�э級</para>
+        /// </summary>
+        public void ReadControlSequenceOfOperation()
+        {
+            ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.ControlSequenceOfOperation);
+        }
+
+        /// <summary>
+        /// 鑾峰彇鎭掓俯璁惧褰撳墠宸ヤ綔妯″紡
+        /// <para>AttriButeId=28 (鍏堣皟鐢ㄥ彂鐜板睘鎬ф帴鍙o紝鏌ョ湅璁惧鏄惁鏀寔璇ユ帴鍙g殑灞炴�э級</para>
+        /// </summary>
+        public void ReadSystemMode()
+        {
+            ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.SystemMode);
+        }
+
+        /// <summary>
+        /// 鑾峰彇椋庢墖妯″紡銆�
+        /// <para>AttriButeId=0 (鍏堣皟鐢ㄥ彂鐜板睘鎬ф帴鍙o紝鏌ョ湅璁惧鏄惁鏀寔璇ユ帴鍙g殑灞炴�э級</para>
+        /// </summary>
+        public void ReadFanMode()
+        {
+            ReadAttri(Device.Cluster_ID.FanControl, AttriButeId.FanMode);
+        }
+
+        /// <summary>
+        /// 鑾峰彇椋庢墖鎷ユ湁鐨勫伐浣滄ā寮忕绫�.
+        /// <para>AttriButeId=1 (鍏堣皟鐢ㄥ彂鐜板睘鎬ф帴鍙o紝鏌ョ湅璁惧鏄惁鏀寔璇ユ帴鍙g殑灞炴�э級</para>
+        /// </summary>
+        public void ReadFanModeSequence()
+        {
+            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 void ReadUseSwingFunctionStatu()
+        {
+            ReadAttri(Device.Cluster_ID.FanControl, AttriButeId.UseAcSwingFunctionStatu);
+        }
+
+        /// <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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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 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 >
+        ///璁剧疆鍒跺喎搴︽暟.
+        /// </summary>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetCoolingTemperatureAsync(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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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 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", 17 }, { "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> SetHeatingTemperatureAsync(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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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 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", 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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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 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());
+                }
+                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> SetSystemModeAsync(AcMode acMode)
+        {
+            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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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 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", 28 }, { "AttributeDataType", 48 }, { "AttributeData", (int)acMode } };
+                    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;
+            });
+        }
+
+        public enum AcMode
+        {
+            /// <summary>
+            /// 鍏抽棴妯″紡锛堟祴璇曟亽娓╅潰鏉挎椂鍙戠幇锛�2锛�5锛�6锛�7锛�8锛�9閮芥槸鍙互鎵撳紑鐨勶級
+            /// </summary>
+            Off = 0,
+            /// <summary>
+            /// 鑷姩妯″紡
+            /// </summary>
+            Auto = 1,
+            /// <summary>
+            /// 鍒跺喎妯″紡
+            /// </summary>
+            Cool = 3,
+            /// <summary>
+            /// 鍒剁儹妯″紡
+            /// </summary>
+            Heat = 4,
+            /// <summary>
+            /// 绱ф�ュ埗鐑ā寮�
+            /// </summary>
+            EmergencyHeating = 5,
+            /// <summary>
+            /// 棰勫喎妯″紡
+            /// </summary>
+            Precooling = 6,
+            /// <summary>
+            /// 鍙湁椋庨�熸ā寮�
+            /// </summary>
+            FanOnly = 7,
+            /// <summary>
+            /// 骞茬嚗妯″紡
+            /// </summary>
+            Dry = 8,
+            /// <summary>
+            /// 鐫$湢妯″紡
+            /// </summary>
+            Sleep = 9
+        }
+
+        ///<summary >
+        ///璁剧疆鎭掓俯鍣ㄨ澶囧綋鍓嶉閫�.
+        /// </summary>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetFanModeAsync(FanMode fanMode)
+        {
+            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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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 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", 0 }, { "AttributeDataType", 48 }, { "AttributeData", (int)fanMode } };
+                    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;
+            });
+        }
+
+        public enum FanMode
+        {
+            /// <summary>
+            /// 鍏抽棴椋庨��
+            /// </summary>
+            Off = 0,
+            /// <summary>
+            /// 浣庨
+            /// </summary>
+            Low = 1,
+            /// <summary>
+            /// 涓
+            /// </summary>
+            Medium = 2,
+            /// <summary>
+            /// 楂橀
+            /// </summary>
+            High = 3,
+            /// <summary>
+            /// 鎵撳紑椋庨��
+            /// </summary>
+            On = 4,
+            /// <summary>
+            /// 鑷姩
+            /// </summary>
+            Auto = 5,
+            /// <summary>
+            /// 鑱槑fe
+            /// </summary>
+            Smart = 6,
+        }
+
+        ///<summary >
+        ///璁剧疆鎭掓俯璁惧鍔犵儹鎴栧埗鍐峰害鏁�(娌℃湁娴嬭瘯鎴愬姛)
+        /// <para>mode瑕佽皟鑺傜殑妯″紡 0锛氬姞鐑紱1锛氬埗鍐凤紱2锛氳嚜鍔ㄨ皟鑺�</para>
+        ///<para>temperature:瑕佸彉鍖栫殑搴︽暟锛屽崟浣嶏細0.1鈩�</para>
+        /// </summary>
+        public void SetTemperature(int mode, int temperature)
+        {
+            var jObject = new JObject {
+                { "DeviceAddr", DeviceAddr},
+                { "Epoint", DeviceEpoint},
+                    { "Cluster_ID",513},
+                    { "Command", 0},
+                    { "SendMode", 2 }
+                };
+            var data = new JObject {
+                    { "Mode", mode },
+                { "Amount", temperature }
+                 };
+            jObject.Add("Data", data);
+            Gateway?.Send("DeviceControl", jObject.ToString());
+        }
+
+        /// <summary>
+        /// 鍏抽棴
+        /// </summary>
+        /// <returns>The close.</returns>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> Close()
+        {
+            return await SetSystemModeAsync(AcMode.Off);
+        }
+
+        /// <summary>
+        /// 寮�鍚�
+        /// </summary>
+        /// <returns>The open.</returns>
+        /// <param name="acMode">Ac mode.</param>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> Open(AcMode acMode = AcMode.Cool)
+        {
+            return await SetSystemModeAsync(acMode);
+        }
+    }
+}

--
Gitblit v1.8.0