mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 10:44:55 +00:00
add constants values
This commit is contained in:
@ -7,3 +7,13 @@ export enum ActionExecutorEnum {
|
||||
export enum EntityTypeEnum {
|
||||
DEVICE_REPORT = 'device_report',
|
||||
}
|
||||
export const AUTOMATION_CONFIG = {
|
||||
DEFAULT_START_TIME: '00:00',
|
||||
DEFAULT_END_TIME: '23:59',
|
||||
DEFAULT_LOOPS: '1111111',
|
||||
DECISION_EXPR: 'and',
|
||||
CONDITION_TYPE: 'device_report',
|
||||
ACTION_EXECUTOR: 'rule_trigger',
|
||||
COMPARATOR: '==',
|
||||
SCENE_STATUS_VALUE: 'scene',
|
||||
};
|
||||
|
||||
@ -54,6 +54,7 @@ import { AddAutomationDto } from 'src/automation/dtos';
|
||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
||||
import { SceneSwitchesTypeEnum } from '@app/common/constants/scene-switch-type.enum';
|
||||
import { AUTOMATION_CONFIG } from '@app/common/constants/automation.enum';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceService {
|
||||
@ -1220,6 +1221,7 @@ export class DeviceService {
|
||||
|
||||
return descendants;
|
||||
}
|
||||
|
||||
async addSceneToSceneDevice(
|
||||
deviceUuid: string,
|
||||
addSceneToFourSceneDeviceDto: AddSceneToFourSceneDeviceDto,
|
||||
@ -1237,7 +1239,6 @@ export class DeviceService {
|
||||
this.getDeviceByDeviceUuid(deviceUuid),
|
||||
]);
|
||||
|
||||
// Generate a shorter automation name (e.g., "Auto_ABC123_169")
|
||||
const shortUuid = deviceUuid.slice(0, 6); // First 6 characters of the UUID
|
||||
const timestamp = Math.floor(Date.now() / 1000); // Current timestamp in seconds
|
||||
const automationName = `Auto_${shortUuid}_${timestamp}`;
|
||||
@ -1245,33 +1246,32 @@ export class DeviceService {
|
||||
const addAutomationData: AddAutomationDto = {
|
||||
spaceUuid: spaceData.spaceTuyaUuid,
|
||||
automationName,
|
||||
decisionExpr: 'and',
|
||||
decisionExpr: AUTOMATION_CONFIG.DECISION_EXPR,
|
||||
effectiveTime: {
|
||||
start: '00:00',
|
||||
end: '23:59',
|
||||
loops: '1111111',
|
||||
start: AUTOMATION_CONFIG.DEFAULT_START_TIME,
|
||||
end: AUTOMATION_CONFIG.DEFAULT_END_TIME,
|
||||
loops: AUTOMATION_CONFIG.DEFAULT_LOOPS,
|
||||
},
|
||||
conditions: [
|
||||
{
|
||||
code: 1,
|
||||
entityId: deviceData.deviceTuyaUuid,
|
||||
entityType: 'device_report',
|
||||
entityType: AUTOMATION_CONFIG.CONDITION_TYPE,
|
||||
expr: {
|
||||
comparator: '==',
|
||||
comparator: AUTOMATION_CONFIG.COMPARATOR,
|
||||
statusCode: switchName,
|
||||
statusValue: 'scene',
|
||||
statusValue: AUTOMATION_CONFIG.SCENE_STATUS_VALUE,
|
||||
},
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
actionExecutor: 'rule_trigger',
|
||||
actionExecutor: AUTOMATION_CONFIG.ACTION_EXECUTOR,
|
||||
entityId: sceneData.sceneTuyaUuid,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Create automation
|
||||
const automation = await this.tuyaService.createAutomation(
|
||||
addAutomationData.spaceUuid,
|
||||
addAutomationData.automationName,
|
||||
@ -1328,7 +1328,7 @@ export class DeviceService {
|
||||
where: {
|
||||
device: { uuid: deviceUuid },
|
||||
switchName:
|
||||
getSceneFourSceneDeviceDto.switchName as SceneSwitchesTypeEnum, // Cast the string to the enum
|
||||
getSceneFourSceneDeviceDto.switchName as SceneSwitchesTypeEnum,
|
||||
},
|
||||
relations: ['device', 'scene'],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user