1
wei
2021-01-21 62d098cb78296feaa6f786a20748921338db838c
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//
// TuyaSmartTimer.h
// TuyaSmartTimerKit
//
// Copyright (c) 2014-2021 Tuya Inc. (https://developer.tuya.com)
 
#ifndef TuyaSmart_TuyaSmartTimer
#define TuyaSmart_TuyaSmartTimer
 
#import <TuyaSmartUtil/TuyaSmartUtil.h>
 
@interface TYTimerModel : NSObject
 
@property (nonatomic, strong) NSString *timerId;
@property (nonatomic, strong) NSString *date;
@property (nonatomic, strong) NSString *time;
@property (nonatomic, assign) BOOL     status;
@property (nonatomic, strong) NSString *loops;
@property (nonatomic, strong) NSDictionary *dps;
@property (nonatomic, strong) NSString *timezoneId;
@property (nonatomic, copy)   NSString *aliasName;
@property (nonatomic, assign) BOOL     isAppPush;
 
@end
 
@interface TYTimerTaskModel : NSObject
 
@property (nonatomic, strong) NSString  *taskName;
@property (nonatomic, assign) NSInteger status;
 
@end
 
 
/// @brief TuyaSmartTimer provides basic timing capability, supporting device timing (including WiFi devices, Bluetooth Mesh sub-devices, Zigbee sub-devices) and group timing.
///
/// It also encapsulates the interface of adding, deleting and checking timer information for device dp points. After the application sets up the timer information through the timing interface, the hardware module will automatically perform the booked operations according to the timing requirements. Multiple timers can be included under each timing task.
@interface TuyaSmartTimer : NSObject
 
/// Get a list of timer task.
/// @param devId Provides the device ID which is needed to get the timer task.
/// @param success Called when the task finishes successfully. A list of TYTimerTaskModel will be returned.
/// @param failure Called when the task is interrupted by an error.
- (void)getTimerTaskStatusWithDeviceId:(NSString *)devId
                               success:(void(^)(NSArray<TYTimerTaskModel *> *list))success
                               failure:(TYFailureError)failure;
 
 
/// Call this method to get all timers that the specified device has.
/// @param devId Provides the device ID which is needed to get all timers.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)getAllTimerWithDeviceId:(NSString *)devId
                        success:(TYSuccessDict)success
                        failure:(TYFailureError)failure;
 
 
/// Call this method to update the timezone of a specified device.
/// @param devId Provides the device ID which is needed to update the timezone.
/// @param timezoneId The ID of the time zone, for example, "Asia/Shanghai".
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateTimerWithDeviceId:(NSString *)devId
                     timezoneId:(NSString *)timezoneId
                        success:(TYSuccessHandler)success
                        failure:(TYFailureError)failure;
 
 
/// Call this method to cancel the ongoing request.
- (void)cancelRequest;
 
 
#pragma mark - Timer
 
/// Set timers for each device or group.
/// @note The maximum number of timings per device or group is 30.
/// @param task The task name of the timer.
/// @param loops Number of loop.
/// @param bizId If it is a device, here is the device Id; if it is a group, here is the group id.
/// @param bizType Pass 0 if the type is device, otherwise, 1 for the group.
/// @param time Timed clocks under timed tasks.
/// @param dps Command Dictionary.
/// @param status A boolean value indicates whether to turn on the timer.
/// @param isAppPush A boolean value indicates whether to turn on the push notification.
/// @param aliasName The remark for the task.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)addTimerWithTask:(NSString *)task
                   loops:(NSString *)loops
                   bizId:(NSString *)bizId
                 bizType:(NSUInteger)bizType
                    time:(NSString *)time
                     dps:(NSDictionary *)dps
                  status:(BOOL)status
               isAppPush:(BOOL)isAppPush
               aliasName:(NSString *)aliasName
                 success:(TYSuccessHandler)success
                 failure:(TYFailureError)failure;
 
 
/// Get the timer under the specified task of the device or group.
/// @param task The name of the timer task.
/// @param bizId If it is a device, here is the device Id; if it is a group, here is the group id.
/// @param bizType Pass 0 if the type is device, otherwise, 1 for the group.
/// @param success Called when the task finishes successfully. A list of TYTimerTaskModel will be returned.
/// @param failure Called when the task is interrupted by an error.
- (void)getTimerListWithTask:(NSString *)task
                       bizId:(NSString *)bizId
                     bizType:(NSUInteger)bizType
                     success:(void(^)(NSArray<TYTimerModel *> *list))success
                     failure:(TYFailureError)failure;
 
 
/// Update the specified timer information for the specified task under the device or group.
/// @param timerId The timer ID for the update process.
/// @param loops Number of cycles, format "0000000". Each bit 0:off, 1:on, from left to right: Sunday Monday Tuesday Wednesday Thursday Friday Saturday. For example, each Monday: 0100000.
/// @param bizId If it is a device, here is the device Id; if it is a group, here is the group id.
/// @param bizType Pass 0 if the type is device, otherwise, 1 for the group.
/// @param time Timed time, e.g. 18:00.
/// @param dps Command Dictionary.
/// @param status A boolean value indicates whether to turn on the timer.
/// @param isAppPush A boolean value indicates whether to turn on the push notification.
/// @param aliasName The remark for the task.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateTimerWithTimerId:(NSString *)timerId
                         loops:(NSString *)loops
                         bizId:(NSString *)bizId
                       bizType:(NSUInteger)bizType
                          time:(NSString *)time
                           dps:(NSDictionary *)dps
                        status:(BOOL)status
                     isAppPush:(BOOL)isAppPush
                     aliasName:(NSString *)aliasName
                       success:(TYSuccessHandler)success
                       failure:(TYFailureError)failure;
 
 
/// Update the specified timer status for the specified task under the device or group.
/// @param timerId The timer ID for the update process.
/// @param bizId If it is a device, here is the device Id; if it is a group, here is the group id.
/// @param bizType Pass 0 if the type is device, otherwise, 1 for the group.
/// @param status A boolean value indicates whether to turn on the timer.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateTimerStatusWithTimerId:(NSString *)timerId
                               bizId:(NSString *)bizId
                             bizType:(NSUInteger)bizType
                              status:(BOOL)status
                             success:(TYSuccessHandler)success
                             failure:(TYFailureError)failure;
 
 
/// Update the status of all time clocks under a specific task.
/// @param task The name of the timer task.
/// @param bizId If it is a device, here is the device Id; if it is a group, here is the group id.
/// @param bizType Pass 0 if the type is device, otherwise, 1 for the group.
/// @param status A boolean value indicates whether to turn on the timer.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateTimerStatusWithTask:(NSString *)task
                            bizId:(NSString *)bizId
                          bizType:(NSUInteger)bizType
                           status:(BOOL)status
                          success:(TYSuccessHandler)success
                          failure:(TYFailureError)failure;
 
 
/// Delete a single timer.
/// @param timerId The timer ID for the delete process.
/// @param bizId If it is a device, here is the device Id; if it is a group, here is the group id.
/// @param bizType Pass 0 if the type is device, otherwise, 1 for the group.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)removeTimerWithTimerId:(NSString *)timerId
                         bizId:(NSString *)bizId
                       bizType:(NSUInteger)bizType
                       success:(TYSuccessHandler)success
                       failure:(TYFailureError)failure;
 
 
/// Delete all timers under a specific task.
/// @param task The name of the timer task.
/// @param bizId If it is a device, here is the device Id; if it is a group, here is the group id.
/// @param bizType Pass 0 if the type is device, otherwise, 1 for the group.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)removeTimerWithTask:(NSString *)task
                      bizId:(NSString *)bizId
                    bizType:(NSUInteger)bizType
                    success:(TYSuccessHandler)success
                    failure:(TYFailureError)failure;
 
 
/// Batch modification of common timing status or deletion of timers.
/// @param timerIds Batch modified timing ids.
/// @param bizId Service id, in case of device, here is the device id; in case of group, here is the group id.
/// @param bizType Service type, 0:Device; 1:Device group.
/// @param updateType Update Type 0: Turn off the timer 1: Turn on the timer 2: Delete the timer.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateTimerStatusWithTimerIds:(NSArray<NSString *> *)timerIds
                                bizId:(NSString *)bizId
                              bizType:(NSUInteger)bizType
                           updateType:(int)updateType
                              success:(TYSuccessHandler)success
                              failure:(TYFailureError)failure;
 
 
/// Modify all timing status under a timing task or delete a timer.
/// @param task Timing task name.
/// @param bizId Service id, in case of device, here is the device id; in case of group, here is the group id.
/// @param bizType Service type, 0:Device; 1:Device group.
/// @param updateType Update Type 0: Turn off the timer 1: Turn on the timer 2: Delete the timer.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateTimerTaskStatusWithTask:(NSString *)task
                                bizId:(NSString *)bizId
                              bizType:(NSUInteger)bizType
                           updateType:(NSUInteger)updateType
                              success:(TYSuccessHandler)success
                              failure:(TYFailureError)failure;
 
@end
 
#endif