mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 14:54:54 +00:00
add automation
This commit is contained in:
@ -133,4 +133,45 @@ export class TuyaService {
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async createAutomation(
|
||||
spaceId: string,
|
||||
automationName: string,
|
||||
effectiveTime: any,
|
||||
decisionExpr: string,
|
||||
conditions: any[],
|
||||
actions: any[],
|
||||
) {
|
||||
const path = `/v2.0/cloud/scene/rule`;
|
||||
|
||||
try {
|
||||
const response = await this.tuya.request({
|
||||
method: 'POST',
|
||||
path,
|
||||
body: {
|
||||
space_id: spaceId,
|
||||
name: automationName,
|
||||
effective_time: {
|
||||
...effectiveTime,
|
||||
timezone_id: 'Asia/Dubai',
|
||||
},
|
||||
type: 'automation',
|
||||
decision_expr: decisionExpr,
|
||||
conditions: conditions,
|
||||
actions: actions,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
throw new HttpException(response.msg, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
return response.result;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Failed to create automation in Tuya',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user