Add RULE_TRIGGER to ActionExecutorEnum and introduce ActionTypeEnum

This commit is contained in:
faris Aljohari
2024-12-02 05:25:11 -06:00
parent 7dca9ea5ff
commit b507bcbdf1
5 changed files with 45 additions and 12 deletions

View File

@ -26,6 +26,7 @@ import {
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
import {
ActionExecutorEnum,
ActionTypeEnum,
AUTO_PREFIX,
AUTOMATION_TYPE,
EntityTypeEnum,
@ -247,20 +248,19 @@ export class AutomationService {
action.actionExecutor !== ActionExecutorEnum.DEVICE_ISSUE &&
action.actionExecutor !== ActionExecutorEnum.DELAY
) {
const scene = await this.sceneRepository.findOne({
where: {
uuid: action.entityId,
},
});
if (scene.uuid) {
const sceneDetails = await this.getTapToRunSceneDetailsTuya(
scene.sceneTuyaUuid,
);
const sceneDetails = await this.getTapToRunSceneDetailsTuya(
action.entityId,
);
if (sceneDetails.id) {
action.name = sceneDetails.name;
action.type = sceneDetails.type;
if (sceneDetails.id) {
if (sceneDetails.type === ActionTypeEnum.SCENE) {
const scene = await this.sceneRepository.findOne({
where: { sceneTuyaUuid: action.entityId },
});
action.entityId = scene.uuid;
}
action.name = sceneDetails.name;
action.type = sceneDetails.type;
}
}
}
@ -463,6 +463,21 @@ export class AutomationService {
if (device) {
action.entity_id = device.deviceTuyaUuid;
}
} else if (action.action_executor === ActionExecutorEnum.RULE_TRIGGER) {
// Check if action_type is missing
if (!action.action_type) {
throw new Error(`actionType is required for rule_trigger actions`);
}
if (action.action_type === ActionTypeEnum.SCENE) {
const scene = await this.sceneRepository.findOne({
where: { uuid: action.entity_id },
});
if (scene) {
action.entity_id = scene.sceneTuyaUuid;
}
}
}
}),
);