mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
Add RULE_TRIGGER
to ActionExecutorEnum
and introduce ActionTypeEnum
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
export enum ActionExecutorEnum {
|
||||
DEVICE_ISSUE = 'device_issue',
|
||||
DELAY = 'delay',
|
||||
RULE_TRIGGER = 'rule_trigger',
|
||||
}
|
||||
|
||||
export enum EntityTypeEnum {
|
||||
@ -18,3 +19,8 @@ export const AUTOMATION_CONFIG = {
|
||||
};
|
||||
export const AUTOMATION_TYPE = 'automation';
|
||||
export const AUTO_PREFIX = 'Auto_';
|
||||
|
||||
export enum ActionTypeEnum {
|
||||
SCENE = 'scene',
|
||||
AUTOMATION = 'automation',
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { ActionTypeEnum } from '@app/common/constants/automation.enum';
|
||||
|
||||
export interface ConvertedExecutorProperty {
|
||||
function_code?: string;
|
||||
function_value?: any;
|
||||
@ -7,5 +9,6 @@ export interface ConvertedExecutorProperty {
|
||||
export interface ConvertedAction {
|
||||
entity_id: string;
|
||||
action_executor: string;
|
||||
action_type?: ActionTypeEnum;
|
||||
executor_property?: ConvertedExecutorProperty;
|
||||
}
|
||||
|
@ -7,8 +7,10 @@ import {
|
||||
IsOptional,
|
||||
IsNumber,
|
||||
IsBoolean,
|
||||
IsEnum,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { ActionTypeEnum } from '@app/common/constants/automation.enum';
|
||||
|
||||
export class EffectiveTime {
|
||||
@ApiProperty({ description: 'Start time', required: true })
|
||||
@ -102,6 +104,11 @@ class Action {
|
||||
@IsNotEmpty()
|
||||
public actionExecutor: string;
|
||||
|
||||
@ApiProperty({ description: 'Action type', required: false })
|
||||
@IsOptional()
|
||||
@IsEnum(ActionTypeEnum)
|
||||
public actionType?: ActionTypeEnum;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Executor property',
|
||||
required: false,
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { ActionTypeEnum } from '@app/common/constants/automation.enum';
|
||||
import { EffectiveTime } from '../dtos';
|
||||
|
||||
export interface AddAutomationInterface {
|
||||
@ -26,6 +27,7 @@ export interface DeleteAutomationInterface {
|
||||
export interface Action {
|
||||
actionExecutor: string;
|
||||
entityId: string;
|
||||
actionType?: ActionTypeEnum;
|
||||
[key: string]: any; // Allow additional properties
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import {
|
||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import {
|
||||
ActionExecutorEnum,
|
||||
ActionTypeEnum,
|
||||
AUTO_PREFIX,
|
||||
AUTOMATION_TYPE,
|
||||
EntityTypeEnum,
|
||||
@ -247,23 +248,22 @@ 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,
|
||||
action.entityId,
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const conditions = responseData.conditions.map((condition) => ({
|
||||
...condition,
|
||||
@ -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