add automation

This commit is contained in:
hannathkadher
2024-11-02 23:09:21 +04:00
parent 7e9894b1d3
commit 015b139428
4 changed files with 145 additions and 90 deletions

View File

@ -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,
);
}
}
}