From b02e8275a21dc06bf54b66273485d44e007a2616 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期一, 20 七月 2020 14:50:17 +0800
Subject: [PATCH] 新代码

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

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/FreshAir.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/FreshAir.cs
new file mode 100755
index 0000000..15d44e8
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/FreshAir.cs
@@ -0,0 +1,231 @@
+锘縰sing System;
+using Newtonsoft.Json.Linq;
+
+namespace ZigBee.Device
+{
+    [System.Serializable]
+    public class FreshAir : CommonDevice
+    {
+        /// <summary>
+        /// 璇ョ被锛堟柊椋庡璞★級鍖呭惈鏂伴璁惧鍜屾柊椋庨潰鏉� 
+        /// </summary>
+        public FreshAir()
+        {
+            this.Type = DeviceType.FreshAir;
+        }
+
+        /// <summary>
+        /// 椋庨�熸ā寮� 
+        /// <para>5:鑷姩</para>
+        /// <para>6:Smart</para>
+        /// <para>15:鎵嬪姩</para> 
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public int currentFanMode = 0;
+        /// <summary>
+        /// 椋庨�熸。浣� 
+        /// <para>1:浣庨</para>
+        /// <para>2:涓</para>
+        /// <para>3:楂橀 </para> 
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public int currentFanSpeed = 0;
+        /// <summary>
+        /// 椋庢墖鐘舵��
+        /// <para>0:鍏抽棴 </para> 
+        /// <para>4:鎵撳紑 </para> 
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public int currentFanStatus = 0;
+
+        /// <summary>
+        /// 鍏抽棴
+        /// </summary>
+        /// <returns>The close.</returns>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> Close()
+        {
+            return await SetFanModeAsync(FanMode.Off);
+        }
+
+        /// <summary>
+        /// 寮�鍚�
+        /// </summary>
+        /// <returns>The open.</returns>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> Open()
+        {
+            return await SetFanModeAsync(FanMode.On);
+        }
+
+        /// <summary>
+        /// 楂橀
+        /// </summary>
+        /// <returns>The close.</returns>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetHighSpeed()
+        {
+            return await SetFanModeAsync(FanMode.High);
+        }
+
+        /// <summary>
+        /// 浣庨
+        /// </summary>
+        /// <returns>The open.</returns>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetLowSpeed()
+        {
+            return await SetFanModeAsync(FanMode.Low);
+        }
+
+
+        /// <summary>
+        /// 鎵嬪姩
+        /// </summary>
+        /// <returns>The close.</returns>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetManual()
+        {
+            return await SetFanModeAsync(FanMode.Manual);
+        }
+
+        /// <summary>
+        /// 鑷姩
+        /// </summary>
+        /// <returns>The open.</returns>
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetAuto()
+        {
+            return await SetFanModeAsync(FanMode.Auto);
+        }
+
+        ///<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;
+            });
+        }
+
+
+        #region 鈼� 褰撳墠鏂伴寮�鍏崇姸鎬乢___________________
+
+        /// <summary>
+        /// 褰撳墠鏂伴寮�鍏崇姸鎬�
+        /// </summary>
+        /// <param name="freshAir"></param>
+        /// <returns></returns>
+        public bool IsOpen(FreshAir freshAir)
+        {
+            if (freshAir.currentFanStatus == 4)
+            {
+                return true;
+            }
+            return false;
+        }
+
+        #endregion
+
+
+        /// <summary>
+        /// 椋庨�熸。浣�
+        /// </summary>
+        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>
+            /// Smart
+            /// </summary>
+            Smart = 6,
+            /// <summary>
+            /// 鎵嬪姩
+            /// </summary>
+            Manual = 15,
+        }
+    }
+}

--
Gitblit v1.8.0