| | |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared; |
| | | |
| | | namespace ZigBee.Device |
| | | { |
| | |
| | | { |
| | | 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); |
| | |
| | | return; |
| | | } |
| | | Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 判断是否是空气质量传感器 |
| | | /// </summary> |
| | | /// <param name="dev"></param> |
| | | /// <returns></returns> |
| | | public bool isAirQualitySensor(CommonDevice dev) |
| | | { |
| | | bool hasT = false; |
| | | bool hasH = false; |
| | | bool hasPM = false; |
| | | bool hasCo2 = false; |
| | | foreach (var clu in dev.InClusterList) |
| | | { |
| | | switch (clu.InCluster) |
| | | { |
| | | case 1026: |
| | | hasT = true; |
| | | break; |
| | | case 1029: |
| | | hasH = true; |
| | | break; |
| | | case 1037: |
| | | hasCo2 = true; |
| | | break; |
| | | case 1066: |
| | | hasPM = true; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (hasT == true && hasH == true && hasPM == true && hasCo2 == true) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | else if (this.Type == DeviceType.TemperatureSensor) |
| | | { |
| | | if (((TemperatureSensor)this).SensorDiv == 1) |
| | | if (isAirQualitySensor(this)) |
| | | { |
| | | //温度传感器 |
| | | IconPath = "Device/SensorTemperature.png"; |
| | | //空气质量传感器 |
| | | IconPath = "Device/AirQualitySensorEpoint.png"; |
| | | } |
| | | else if (((TemperatureSensor)this).SensorDiv == 2) |
| | | else |
| | | { |
| | | //湿度传感器 |
| | | IconPath = "Device/SensorHumidity.png"; |
| | | if (((TemperatureSensor)this).SensorDiv == 1) |
| | | { |
| | | //温度传感器 |
| | | IconPath = "Device/SensorTemperature.png"; |
| | | } |
| | | else if (((TemperatureSensor)this).SensorDiv == 2) |
| | | { |
| | | //湿度传感器 |
| | | IconPath = "Device/SensorHumidity.png"; |
| | | } |
| | | } |
| | | } |
| | | else if (this.Type != DeviceType.UnKown) |
| | |
| | | //其他的图标有点特殊 |
| | | string unSelectPic = string.Empty; |
| | | string selectPic = string.Empty; |
| | | Shared.Phone.HdlDeviceCommonLogic.Current.GetDeviceObjectIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic); |
| | | Shared.Common.LocalDevice.Current.GetDeviceObjectIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic); |
| | | IconPath = unSelectPic; |
| | | } |
| | | Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | |
| | | /// 设置可写属性的值 |
| | | /// </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; |
| | | } |
| | |
| | | } |
| | | } |
| | | }; |
| | | gateway.Actions += action; |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | |
| | | 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 { } |
| | | |
| | |
| | | { |
| | | d = new SetWritableValueResponAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | gateway.Actions -= action; |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("SetWritableValue_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | |
| | | public static void DebugPrintLog(string msg, bool flage = true) |
| | | { |
| | | #if DEBUG |
| | | if (flage == true) |
| | | { |
| | | if (msg.Contains("DeviceStatusReport") == false) |
| | | { |
| | | System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond); |
| | | } |
| | | } |
| | | if (flage == true) |
| | | { |
| | | if (msg.Contains("DeviceStatusReport") == false) |
| | | { |
| | | System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond); |
| | | } |
| | | } |
| | | #endif |
| | | } |
| | | |