Last Updated on : 2024-05-12 05:18:50download
The device schedule service enables you to:
The class IThingTimerManager
is responsible for scheduling tasks. This section uses the device schedule to describe the implementation. Group schedules work the same way, with the only difference being the request parameter groupId
.
The schedule service only works if a device or group exists in a home.
Get the schedule management class.
// Get the schedule management class.
IThingTimerManager timerManager = ThingDeviceDetailKit.getInstance().getDeviceTimerManager();
To schedule a device to execute a specific command at a set time, use addTimer()
to create a schedule.
Parameters:
Parameter | Required |
---|---|
deviceId | Yes |
category | Yes |
time | Yes |
dps | Yes |
loops | Yes |
aliasName | Yes |
isOpen | Yes |
isAppPush | Yes |
callback | Yes |
TimerManagerBuilder builder = new TimerManagerBuilder.Builder()
.setDeviceId(deviceId)
.setCategory("schedule")
.setTime("12:12")
.setDps({"1":false})
.setLoops("0000000")
.setAliasName("aliasName")
.isOpen(true)
.isAppPush(true)
.setCallback(new IThingTimerCallBack() {
@Override
public void successful(@Nullable List<? extends AlarmTimerBean> list) {
// After a schedule is created, a schedule list that includes the newly added one will be returned.
if (list!=null&&list.size()>0){
AlarmTimerBean alarmTimerBean = list.get(0);
// groupId is the schedule ID.
String groupId = alarmTimerBean.getGroupId();
}
}
@Override
public void fail(int i, @NonNull String s) {
}
})
.build();
timerManager.addTimer(builder);
Call editTimer()
to edit a schedule.
Parameters:
Parameter | Required |
---|---|
deviceid | Yes |
timerId | Yes |
time | Yes |
loops | Yes |
aliasName | Yes |
isAppPush | Yes |
callback | Yes |
TimerManagerBuilder builder = new TimerManagerBuilder.Builder()
.setDeviceId(deviceId)
.setTime("12:32")
.setTimerId("xxxx")
.setDps({"1":false})
.setLoops("1000000")
.setAliasName("aliasName")
.isOpen(true)
.isAppPush(false)
.setCallback(new IThingTimerCallBack() {
@Override
public void successful(@Nullable List<? extends AlarmTimerBean> list) {
// After a schedule is edited, a schedule list that includes the edited one will be returned.
if (list!=null&&list.size()>0){
AlarmTimerBean alarmTimerBean = list.get(0);
// groupId is the schedule ID.
String groupId = alarmTimerBean.getGroupId();
}
}
@Override
public void fail(int i, @NonNull String s) {
}
})
.build();
timerManager.editTimer(builder);
Call updateTimerStatus()
to update the schedule status.
Parameters:
Parameter | Required |
---|---|
deviceid | Yes |
timerId | Yes |
isOpen | Yes |
callback | Yes |
TimerManagerBuilder builder = new TimerManagerBuilder.Builder()
.setDeviceId(deviceId)
.setTimerId("xxxx")
.setCallback(new IThingTimerCallBack() {
@Override
public void successful(@Nullable List<? extends AlarmTimerBean> list) {
// Updating the schedule status will trigger the success callback, returning a null list of data.
}
@Override
public void fail(int i, @NonNull String s) {
}
})
.build();
timerManager.updateTimerStatus(builder);
Call deleteTimer()
to delete a schedule.
Parameters:
Parameter | Required |
---|---|
deviceid | Yes |
timerId | Yes |
callback | Yes |
TimerManagerBuilder builder = new TimerManagerBuilder.Builder()
.setDeviceId(deviceId)
.setTimerId("xxxx")
.setCallback(new IThingTimerCallBack() {
@Override
public void successful(@Nullable List<? extends AlarmTimerBean> list) {
// Deleting the schedule status will trigger the success callback, returning a null list of data.
}
@Override
public void fail(int i, @NonNull String s) {
}
})
.build();
timerManager.deleteTimer(builder);
Call getTimerList()
to get the list of schedules for a device.
Parameters:
Parameter | Required |
---|---|
deviceid | Yes |
callback | Yes |
TimerManagerBuilder builder = new TimerManagerBuilder.Builder()
.setDeviceId(deviceId)
.setCallback(new IThingTimerCallBack() {
@Override
public void successful(@Nullable List<? extends AlarmTimerBean> list) {
// A successful request returns the list of schedules.
}
@Override
public void fail(int i, @NonNull String s) {
}
})
.build();
timerManager.getTimerList(builder);
This topic describes the service implementation in the sequence of read, create, update, and delete operations. In real-world projects, you can implement them as needed. For more information, see the Device Schedule Module in the BizBundle SDK Demo.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback