finished refactor devices module

This commit is contained in:
faris Aljohari
2025-03-24 02:32:44 +03:00
parent 2712ce673a
commit 8efd8cfba2
11 changed files with 557 additions and 446 deletions

View File

@ -123,6 +123,7 @@ export class AutomationService {
);
const formattedCondition = await this.prepareConditions(
params.conditions,
projectUuid,
);
const response = await this.tuyaService.createAutomation(
@ -585,7 +586,10 @@ export class AutomationService {
updateAutomationDto;
try {
const formattedActions = await this.prepareActions(actions, projectUuid);
const formattedCondition = await this.prepareConditions(conditions);
const formattedCondition = await this.prepareConditions(
conditions,
projectUuid,
);
const response = await this.tuyaService.updateAutomation(
automationUuid,
spaceTuyaUuid,
@ -722,6 +726,7 @@ export class AutomationService {
const device = await this.deviceService.getDeviceByDeviceUuid(
action.entity_id,
false,
projectUuid,
);
if (device) {
action.entity_id = device.deviceTuyaUuid;
@ -759,7 +764,10 @@ export class AutomationService {
return convertedData;
}
private async prepareConditions(conditions: Condition[]) {
private async prepareConditions(
conditions: Condition[],
projectUuid: string,
) {
const convertedData = convertKeysToSnakeCase(conditions);
await Promise.all(
convertedData.map(async (condition) => {
@ -767,6 +775,7 @@ export class AutomationService {
const device = await this.deviceService.getDeviceByDeviceUuid(
condition.entity_id,
false,
projectUuid,
);
if (device) {
condition.entity_id = device.deviceTuyaUuid;