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