Add updateAutomation method and update external service handling

This commit is contained in:
faris Aljohari
2024-12-03 03:10:32 -06:00
parent 6dd631ebb1
commit 5a698f8087
2 changed files with 93 additions and 14 deletions

View File

@ -218,6 +218,42 @@ export class TuyaService {
return response;
}
async updateAutomation(
automationUuid: string,
spaceId: string,
automationName: string,
actions: ConvertedAction[],
conditions: any[],
decisionExpr: string,
effectiveTime: any,
) {
const path = `/v2.0/cloud/scene/rule/${automationUuid}`;
const response = await this.tuya.request({
method: 'PUT',
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) {
return response;
} else {
throw new HttpException(
`Error fetching automation rule: ${response.msg}`,
HttpStatus.BAD_REQUEST,
);
}
}
async updateAutomationState(
spaceId: string,