From 3aa397ab145382935492b11c1f18c9634e69910b Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 10 十二月 2020 16:45:00 +0800
Subject: [PATCH] 请合并,门锁和晾衣架第一版代码

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs |  140 ++++++++++++++++++++++++++++------------------
 1 files changed, 84 insertions(+), 56 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
old mode 100755
new mode 100644
index bda2e51..2688a0a
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
@@ -61,7 +61,7 @@
         /// </summary>
         public int DeviceEpoint;
         /// <summary>
-        /// 璁惧id
+        /// 瀹為檯鐨勮澶噄d
         /// <para>258:color dimmable light,璋冨叧鐏� </para>
         /// <para>10:Door lock,闂ㄩ攣</para>
         /// <para>514:Window covering device,绐楀笜</para>
@@ -72,7 +72,17 @@
         /// <para>262:Light sensor,鍏夌収浼犳劅鍣�</para>
         /// <para>1026:sensor,浼犳劅鍣紝鍏蜂綋绫诲瀷鐨勪紶鎰熷櫒DeviceType鏉ュ尯鍒�</para>
         /// </summary>
-        public int DeviceID;
+        public int DeviceID;
+        /// <summary>
+        /// <para>2020.09.21杩藉姞:涓轰簡瀵瑰簲绗笁鏂硅澶�,浠ュ強涔嬪悗鐨勫璁惧ID闂,杩藉姞鐨勫彉閲�</para>
+        /// <para>杩欐槸涓壒娈婄殑,骞朵笖涓嶄繚瀛樺湪鏂囦欢褰撲腑鐨処D, DeviceType鐢辨鍊兼槧灏勫嚭鏉�</para>
+        /// <para>褰撹澶囨槸娌充笢璁惧鏃�,瀹冧笌DeviceID鐩哥瓑</para>
+        /// <para>褰撴槸鐪熸鐨勭涓夋柟璁惧鏃�,瀹冩湁鍙兘涓嶥eviceID涓嶇浉绛�</para>
+        /// <para>姣斿锛�2鍜�256閮芥槸缁х數鍣�,閭d箞銆怐eviceID涓�2 鎴栬�� DeviceID涓�256銆� 鑰� 銆怑xDeviceID鍥哄畾涓�2銆�,銆怐eviceType涓篛nOffOutput銆�</para>
+        /// <para>閫氫織鏉ヨ锛欴eviceID鏄疄闄呮纭殑ID,鑰屻�怑xDeviceID鏄竴绉嶆墍灞炴蹇电殑ID銆�</para>
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public int ExDeviceID;
         /// <summary>
         /// 璇ュ瓧娈典富瑕侀拡瀵笽AS瀹夐槻璁惧璁剧珛銆傛墍鏈塈AS瀹夐槻璁惧鍏辩敤涓�涓狣eviceID涓�1026銆傛墍浠ヨ鍖哄垎瀛愯澶囩被鍨嬶紝闇�瑕佽瀛楁銆�
         /// 鐬棿鏁版嵁涓婃姤鐨勪紶鎰熷櫒 (MomentStatus=1    TriggerZoneStatus>=1锛滄姤璀︼紴)
@@ -230,10 +240,8 @@
         {
             get
             {
-                var deviceType = Type.ToString();
-                var fileName = "Device_" + deviceType + "_" + DeviceAddr;
-                fileName += "_" + (DeviceEpoint.ToString().Length < 2 ? "0" + DeviceEpoint.ToString() : DeviceEpoint.ToString());
-                return fileName;
+                //2020.09.21 瀵瑰簲绗笁鏂硅澶囧彲浠ュ叆缃�,璁惧鏂囦欢鍚嶅瓧,鍘绘帀 deviceType
+                return "Device_" + DeviceAddr + "_" + DeviceEpoint.ToString().PadLeft(2, '0');
             }
         }
 
@@ -244,112 +252,133 @@
         /// <summary>
         /// 鐢辫澶囧瓧绗︿覆姣旂壒鎭㈠璁惧瀵硅薄
         /// </summary>
-        /// <param name="strDeviceType">璁惧DeviceType鐨勫瓧绗︿覆绫诲瀷</param>
+        /// <param name="intDeviceType">璁惧DeviceType鐨勬暣鍨嬪��</param>
         /// <param name="strDeviceByte">璁惧Json鏂囦欢杞负姣旂壒鍚庡啀杞负鐨勫瓧绗︿覆</param>
         /// <returns></returns>
-        public static CommonDevice CommonDeviceByByteString(string strDeviceType, string strDeviceByte)
-        {
+        public static CommonDevice CommonDeviceByByteString(int intDeviceType, string strDeviceByte)
+        {
+            //杩欐槸娌充笢鐨勭壒娈婄鐐�,涓嶉渶瑕佸鐞�
+            if (intDeviceType == 49408)
+            {
+                return null;
+            }
+
             CommonDevice device = null;
-            if (strDeviceType == ZigBee.Device.DeviceType.DimmableLight.ToString())
+            if (intDeviceType == (int)DeviceType.DimmableLight || intDeviceType == 3)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight>(strDeviceByte);
+                device.ExDeviceID = (int)DeviceType.DimmableLight;
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.OnOffOutput.ToString())
+            else if (intDeviceType == (int)DeviceType.OnOffOutput || intDeviceType == 256)
             {
-                device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte);
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte);
+                device.ExDeviceID = (int)DeviceType.OnOffOutput;
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.ColorDimmerSwitch.ToString())
+            else if (intDeviceType == (int)DeviceType.ColorDimmerSwitch)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmerSwitch>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.LevelControlSwitch.ToString())
+            else if (intDeviceType == (int)DeviceType.LevelControlSwitch)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<LevelControlSwitch>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringDevice.ToString())
+            else if (intDeviceType == (int)DeviceType.WindowCoveringDevice)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringController.ToString())
+            else if (intDeviceType == (int)DeviceType.WindowCoveringController)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<WindowCoveringController>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.OnOffSwitch.ToString())
+            else if (intDeviceType == (int)DeviceType.OnOffSwitch)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.IASZone.ToString())
+            else if (intDeviceType == (int)DeviceType.IASZone)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.OtaDevice.ToString() || strDeviceType == ZigBee.Device.DeviceType.OtaPanelDevice.ToString())
+            else if (intDeviceType == (int)DeviceType.OtaDevice || intDeviceType == (int)DeviceType.OtaPanelDevice)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<OTADevice>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.AirSwitch.ToString())
+            else if (intDeviceType == (int)DeviceType.AirSwitch)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.Repeater.ToString())
+            else if (intDeviceType == (int)DeviceType.Repeater)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.Thermostat.ToString())
+            else if (intDeviceType == (int)DeviceType.Thermostat)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.Transverter.ToString())
+            else if (intDeviceType == (int)DeviceType.Transverter)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.DoorLock.ToString())
+            else if (intDeviceType == (int)DeviceType.DoorLock)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.TemperatureSensor.ToString())
+            else if (intDeviceType == (int)DeviceType.TemperatureSensor)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.FreshAirHumiditySensor.ToString())
+            else if (intDeviceType == (int)DeviceType.FreshAirHumiditySensor)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<HumiditySensor>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.FreshAir.ToString())
+            else if (intDeviceType == (int)DeviceType.FreshAir)
             {
                 device = Newtonsoft.Json.JsonConvert.DeserializeObject<FreshAir>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.PMSensor.ToString())
+            else if (intDeviceType == (int)DeviceType.PMSensor)
             {
-                return Newtonsoft.Json.JsonConvert.DeserializeObject<PMSensor>(strDeviceByte);
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<PMSensor>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.ColorTemperatureLight.ToString())
+            else if (intDeviceType == (int)DeviceType.ColorTemperatureLight)
             {
-                return Newtonsoft.Json.JsonConvert.DeserializeObject<ColorTemperatureLight>(strDeviceByte);
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorTemperatureLight>(strDeviceByte);
             }
-            else if (strDeviceType == ZigBee.Device.DeviceType.Buzzer.ToString())
+            else if (intDeviceType == (int)DeviceType.Buzzer)
             {
-                return Newtonsoft.Json.JsonConvert.DeserializeObject<Buzzer>(strDeviceByte);
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<Buzzer>(strDeviceByte);
             }
-            else { return null; }
+            else if (intDeviceType == (int)DeviceType.ColorDimmableLight)
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmableLight>(strDeviceByte);
+            }
+            else if (intDeviceType == (int)DeviceType.DimmerSwitch)
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmerSwitch>(strDeviceByte);
+            }
+            else if (intDeviceType == (int)DeviceType.Airer)
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<Airer>(strDeviceByte);
+            }
+            else
+            {
+                device = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice>(strDeviceByte);
+            }
+
+            //杩欐槸娌充笢鐨勭壒娈婄鐐�,涓嶉渶瑕佸鐞�
+            if (device.DeviceEpoint == 242 && intDeviceType == 97)
+            {
+                return null;
+            }
+
+            if (device.ExDeviceID == 0)
+            {
+                //璧嬪垵濮嬪��
+                device.ExDeviceID = device.DeviceID;
+            }
+
             //鑳藉皯瀛樹竴涓彉閲忓氨灏戝瓨涓�涓�
-            device.Type = (DeviceType)device.DeviceID;
+            device.Type = (DeviceType)device.ExDeviceID;
 
             return device;
-        }
-
-        /// <summary>
-        /// 鐢辫澶囪矾寰勬仮澶嶈澶囧璞�
-        /// </summary>
-        /// <returns>The device by file path.</returns>
-        /// <param name="deviceFilePath">Device file path.</param>
-        public static CommonDevice CommonDeviceByFilePath(string deviceFilePath)
-        {
-            var v = deviceFilePath.Split('_');
-            if (v.Length < 3)
-            {
-                return null;
-            }
-            return CommonDeviceByByteString(v[1], System.Text.Encoding.UTF8.GetString(Shared.Common.Global.ReadFileByHomeId(deviceFilePath)));
         }
 
         /// <summary>
@@ -1277,12 +1306,11 @@
         /// 璁剧疆鍙啓灞炴�х殑鍊�
         /// </summary>
         /// <returns>The writable value async.</returns>
-        /// <param name="gateway">Gateway.</param>
         /// <param name="clusterID">瑕侀厤缃殑灞炴�ф墍鍦ㄧ殑cluster.</param>
         /// <param name="setWritableValue">璁剧疆鍙啓灞炴�х殑鏁版嵁</param>
-        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetWritableValueAsync(ZigBee.Device.ZbGateway gateway, int clusterID, SetWritableValueData setWritableValue)
+        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetWritableValueAsync(int clusterID, SetWritableValueData setWritableValue)
         {
-            if (gateway == null || setWritableValue == null)
+            if (Gateway == null || setWritableValue == null)
             {
                 return null;
             }
@@ -1323,7 +1351,7 @@
                         }
                     }
                 };
-                gateway.Actions += action;
+                Gateway.Actions += action;
                 System.Console.WriteLine("SetWritableValue_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
 
                 try
@@ -1331,7 +1359,7 @@
                     var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", clusterID }, { "Command", 120 } };
                     var data = new JObject { { "Undivided", setWritableValue.Undivided }, { "AttributeId", setWritableValue.AttributeId }, { "AttributeDataType", setWritableValue.AttributeDataType }, { "AttributeData", setWritableValue.AttributeData } };
                     jObject.Add("Data", data);
-                    gateway.Send("SetWritableValue", jObject.ToString());
+                    Gateway.Send("SetWritableValue", jObject.ToString());
                 }
                 catch { }
 
@@ -1348,7 +1376,7 @@
                 {
                     d = new SetWritableValueResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
                 }
-                gateway.Actions -= action;
+                Gateway.Actions -= action;
                 System.Console.WriteLine("SetWritableValue_Actions 閫�鍑�" + System.DateTime.Now.ToString());
 
                 return d;

--
Gitblit v1.8.0