mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 18:05:48 +00:00
Add RULE_TRIGGER
to ActionExecutorEnum
and introduce ActionTypeEnum
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
Reference in New Issue
Block a user