wxr
2024-04-11 9802cf8c8ad9f392c5c5342a352a17efeef55fc9
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
using System;
using System.Collections.Generic;
using Foundation;
using HDLSceneSiri;
using ObjCRuntime;
using UIKit;
//using HdlSiri;
 
namespace SiriIntents
{
    public class HDLRunSceneIntentHandlder : HDLRunSceneIntentHandling
    {
        public override void ConfirmHDLRunScene (HDLRunSceneIntent intent,  Action<HDLRunSceneIntentResponse> completion)
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
            {
                if (Server.HttpServerRequest.Ins.DataManager.IsLgoin)
                {
                    var rsp = new HDLRunSceneIntentResponse(HDLRunSceneIntentResponseCode.InProgress, null);
                    if (NSLocale.PreferredLanguages[0].Contains("zh-"))
                    {
                        rsp.SuccessMessage = "请等待...";
                    }
                    else
                    {
                        rsp.SuccessMessage = "Please wait...";
                    }
                    completion(rsp);
                }
                else
                {
                    var rsp = new HDLRunSceneIntentResponse(HDLRunSceneIntentResponseCode.Error, null);
                    if (NSLocale.PreferredLanguages[0].Contains("zh-"))
                    {
                        rsp.SuccessMessage = "账号未登录";
                    }
                    else
                    {
                        rsp.SuccessMessage = "Not logged in to the app.";
                    }
                    completion(rsp);
                }
            }
            else
            {
                var rsp = new HDLRunSceneIntentResponse(HDLRunSceneIntentResponseCode.ContinueInApp, null);
                rsp.SuccessMessage = "Ok";
                completion(rsp);
            }
        }
 
        public override void HandleHDLRunScene(HDLRunSceneIntent intent,Action<HDLRunSceneIntentResponse> completion)
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
            {
                if (Server.HttpServerRequest.Ins.DataManager.IsLgoin)
                {
                    if(Server.HttpServerRequest.Ins.DataManager.HomeId!= intent.HomeId)
                    {
                        var rsp = new HDLRunSceneIntentResponse(HDLRunSceneIntentResponseCode.Error, null);
                        if (NSLocale.PreferredLanguages[0].Contains("zh-"))
                        {
                            rsp.SuccessMessage = "住宅不匹配";
                        }
                        else
                        {
                            rsp.SuccessMessage = "Residential mismatch.";
                        }
                        completion(rsp);
                        return;
                    }
 
                    var result = "-1";
                    if (intent.ControlType == "1")
                    {
                        result = Server.HttpServerRequest.Ins.ExecuteScene(intent.ControlId);
                    }
                    else
                    {
 
                        var security = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityState>(intent.ControlJSONStr);
                        var sendObj = new List<SecurityState>() { new SecurityState() {
                             gatewayId =security.gatewayId,sid = security.sid, status = security.status, userSecurityId = security.userSecurityId
                        } };
                        result = Server.HttpServerRequest.Ins.SetSecurityStatus(sendObj);
                    }
                    if (result == "0")
                    {
                        var rsp = new HDLRunSceneIntentResponse(HDLRunSceneIntentResponseCode.Success, null);
                        if (NSLocale.PreferredLanguages[0].Contains("zh-"))
                        {
                            rsp.SuccessMessage = "执行成功";
                        }
                        else
                        {
                            rsp.SuccessMessage = "Successful execution ";
                        }
                        completion(rsp);
                    }
                    else
                    {
                        var rsp = new HDLRunSceneIntentResponse(HDLRunSceneIntentResponseCode.Error, null);
                        if (NSLocale.PreferredLanguages[0].Contains("zh-"))
                        {
                            rsp.SuccessMessage = "执行失败";
                        }
                        else
                        {
                            rsp.SuccessMessage = "Execution failed.";
                        }
                        completion(rsp);
                    }
                }
                else
                {
                    var rsp = new HDLRunSceneIntentResponse(HDLRunSceneIntentResponseCode.Error, null);
                    if (NSLocale.PreferredLanguages[0].Contains("zh-"))
                    {
                        rsp.SuccessMessage = "账号未登录";
                    }
                    else
                    {
                        rsp.SuccessMessage = "Not logged in to the app.";
                    }
                    completion(rsp);
                }
            }
            else
            {
                var rsp = new HDLRunSceneIntentResponse(HDLRunSceneIntentResponseCode.ContinueInApp, null);
                rsp.SuccessMessage = "Ok";
                completion(rsp);
            }
        }
    }
 
 
    /// <summary>
    /// 安防状态配置
    /// </summary>
    public class SecurityState
    {
        /// <summary>
        /// 安防云端id
        /// </summary>
        public string userSecurityId;
        /// <summary>
        /// 网关id 网关id 如果传的是sid该字段需要传
        /// </summary>
        public string gatewayId;
        /// <summary>
        /// 安防sid
        /// </summary>
        public string sid;
        /// <summary>
        /// 状态 enable布防、disable撒防
        /// </summary>
        public string status;
    }
 
}