HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-12-31 fe3b2466c68b5db70d38e78039703add3b8b1dfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace ZigBee.Device
{
  /// <summary>
  ///注意事项:晾衣架,只显示并存储1端点,其他端点(2~5)过滤,不存储,
  ///因为其他端点只有控制作用,(端点2:控制照明,端点3:控制风干,端点4:控制烘干,端点5:控制消毒)
  /// </summary>
  [System.Serializable]
  public class Airer : CommonDevice
  {
    public Airer()
    {
      this.Type = DeviceType.Airer;
    }
 
    /// <summary>
    /// 开光状态:0=关,1=开,
    ///注意事项:晾衣架,只显示并存储1端点,其他端点(2~5)过滤,不存储,
    ///因为其他端点只有控制作用,(端点2:控制照明,端点3:控制风干,端点4:控制烘干,端点5:控制消毒)
    /// </summary>
    [Newtonsoft.Json.JsonIgnore]
    public int OnOffStatus = 0;
 
    /// <summary>
    /// 烘干状态:0=关,1=开,
    /// </summary>
    [Newtonsoft.Json.JsonIgnore]
    public int DryOnOffStatus = 0;
 
    /// <summary>
    /// 风干状态:0=关,1=开,
    /// </summary>
    [Newtonsoft.Json.JsonIgnore]
    public int WindOnOffStatus = 0;
 
    /// <summary>
    /// 消毒状态:0=关,1=开,
    /// </summary>
    [Newtonsoft.Json.JsonIgnore]
    public int DisinfectOnOffStatus = 0;
 
    /// <summary>
    /// 烘干时间  
    /// </summary>
    [Newtonsoft.Json.JsonIgnore]
    public int DryTime = 0;
    /// <summary>
    /// 剩余烘干时间 (默认0秒)
    /// </summary>
    [Newtonsoft.Json.JsonIgnore]
    public int DryRemainTime = 0;
 
    /// <summary>
    /// 风干时间  
    /// </summary>
    [Newtonsoft.Json.JsonIgnore]
    public int WindTime = 0;
    /// <summary>
    /// 剩余风干时间 (默认0秒)
    /// </summary>
    [Newtonsoft.Json.JsonIgnore]
    public int WindRemainTime = 0;
 
    /// <summary>
    /// 消毒时间  
    /// </summary>
    [Newtonsoft.Json.JsonIgnore]
    public int DisinfectTime = 0;
    /// <summary>
    /// 剩余消毒时间 (默认0秒)
    /// </summary>
    [Newtonsoft.Json.JsonIgnore]
    public int DisinfectRemainTime = 0;
 
    #region 开关
    ///<summary >
    ///衣架开关停控制
    /// <para>command的值</para>
    ///<para>0 : 衣架设备上拉或打开</para>
    ///<para>1: 衣架设备下降或关闭</para>
    ///<para>2:衣架设备停止</para>
    ///<para>注意事项:晾衣架,只显示并存储1端点,其他端点(2~5)过滤,不存储,</para>
    ///<para>因为其他端点只有控制作用,(端点2:控制照明,端点3:控制风干,端点4:控制烘干,端点5:控制消毒) </para>
    /// </summary>
    public void AirerUpDownStopControl(int command)
    {
      var jobject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", command }, { "SendMode", 2 } };
      Gateway?.Send("DeviceControl", jobject.ToString());
      System.Console.WriteLine("CurtainOpenControl_发送数据" + "_" + jobject.ToString() + "_" + System.DateTime.Now.ToString());
    }
    #endregion
 
    #region ■ 设备时间设置___________________________
    ///<summary >
    ///设备时间设
    ///<para>注意事项:晾衣架,只显示并存储1端点,其他端点(2~5)过滤,不存储,</para>
    ///<para>因为其他端点只有控制作用,(端点2:控制照明,端点3:控制风干,端点4:控制烘干,端点5:控制消毒) </para>
    /// </summary>
    public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetAirerTimeAsync(int time, int controlEpoint)
    {
      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", controlEpoint }, { "Cluster_ID", 6 }, { "Command", 120 } };
          var data = new JObject { { "Undivided", 0 }, { "AttributeId", 16385 }, { "AttributeDataType", 33 }, { "AttributeData", time } };
          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;
      });
    }
    #endregion
 
    #region ■ 设备时间设置___________________________
    /// <summary>
    /// 设置时间到衣架
    ///<para>注意事项:晾衣架,只显示并存储1端点,其他端点(2~5)过滤,不存储,</para>
    ///<para>因为其他端点只有控制作用,(端点2:控制照明,端点3:控制风干,端点4:控制烘干,端点5:控制消毒) </para> 
    /// </summary>
    public async void SetAirerFunTimeDevice(int time, int controlEpoint)
    {
      await SetAirerTimeAsync(time, controlEpoint);
    }
    #endregion
 
    #region 开关
    ///<summary >
    ///开关控制(仅用于cluster=6的设备)
    /// <para>设备支持cluster=6的设备才能调用该接口</para>
    /// <para>command的值</para>
    ///<para>0 : 关闭</para>
    ///<para>1: 打开</para>
    ///<para>2:取反</para>
    /// </summary>
    public void SwitchControl(int command, int ctrlEpoint)
    {
      try
      {
        var jobject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", ctrlEpoint }, { "Cluster_ID", 6 }, { "Command", command }, { "SendMode", 2 } };
        Gateway?.Send(("DeviceControl"), jobject.ToString());
        System.Console.WriteLine("SwitchControl_发送数据" + "_" + jobject.ToString() + "_" + System.DateTime.Now.ToString());
 
      }
      catch { }
    }
    #endregion
  }
}