mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 19:07:54 +00:00
Add new automation actions and repository
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
} from '@app/common/modules/scene/repositories';
|
||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
||||
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule, SpaceRepositoryModule, DeviceStatusFirebaseModule],
|
||||
@@ -28,6 +29,7 @@ import { SceneDeviceRepository } from '@app/common/modules/scene-device/reposito
|
||||
SceneIconRepository,
|
||||
SceneRepository,
|
||||
SceneDeviceRepository,
|
||||
AutomationRepository,
|
||||
],
|
||||
exports: [SceneService],
|
||||
})
|
||||
|
||||
@@ -23,7 +23,10 @@ import {
|
||||
SceneDetailsResult,
|
||||
} from '../interface/scene.interface';
|
||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import { ActionExecutorEnum } from '@app/common/constants/automation.enum';
|
||||
import {
|
||||
ActionExecutorEnum,
|
||||
ActionTypeEnum,
|
||||
} from '@app/common/constants/automation.enum';
|
||||
import {
|
||||
SceneIconRepository,
|
||||
SceneRepository,
|
||||
@@ -40,6 +43,7 @@ import { HttpStatusCode } from 'axios';
|
||||
import { ConvertedAction } from '@app/common/integrations/tuya/interfaces';
|
||||
import { DeviceService } from 'src/device/services';
|
||||
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
||||
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
||||
|
||||
@Injectable()
|
||||
export class SceneService {
|
||||
@@ -48,6 +52,7 @@ export class SceneService {
|
||||
private readonly sceneIconRepository: SceneIconRepository,
|
||||
private readonly sceneRepository: SceneRepository,
|
||||
private readonly sceneDeviceRepository: SceneDeviceRepository,
|
||||
private readonly automationRepository: AutomationRepository,
|
||||
private readonly tuyaService: TuyaService,
|
||||
@Inject(forwardRef(() => DeviceService))
|
||||
private readonly deviceService: DeviceService,
|
||||
@@ -460,6 +465,12 @@ export class SceneService {
|
||||
);
|
||||
|
||||
if (sceneDetails.id) {
|
||||
if (sceneDetails.type === ActionTypeEnum.AUTOMATION) {
|
||||
const automation = await this.automationRepository.findOne({
|
||||
where: { automationTuyaUuid: action.entityId },
|
||||
});
|
||||
action.entityId = automation.uuid;
|
||||
}
|
||||
action.name = sceneDetails.name;
|
||||
action.type = sceneDetails.type;
|
||||
}
|
||||
@@ -568,6 +579,17 @@ export class SceneService {
|
||||
if (device) {
|
||||
action.entity_id = device.deviceTuyaUuid;
|
||||
}
|
||||
} else if (
|
||||
action.action_executor === ActionExecutorEnum.RULE_DISABLE ||
|
||||
action.action_executor === ActionExecutorEnum.RULE_ENABLE
|
||||
) {
|
||||
const automation = await this.automationRepository.findOne({
|
||||
where: { uuid: action.entity_id },
|
||||
});
|
||||
|
||||
if (automation) {
|
||||
action.entity_id = automation.automationTuyaUuid;
|
||||
}
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user