mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
Merge pull request #68 from SyncrowIOT/fix-automation-scene-issue
Fix automation scene issue
This commit is contained in:
@ -43,3 +43,8 @@ export interface AutomationResponseData {
|
|||||||
conditions: Condition[];
|
conditions: Condition[];
|
||||||
[key: string]: any; // Allow additional properties
|
[key: string]: any; // Allow additional properties
|
||||||
}
|
}
|
||||||
|
export interface AutomationDetailsResult {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
@ -17,6 +17,7 @@ import { convertKeysToSnakeCase } from '@app/common/helper/snakeCaseConverter';
|
|||||||
import { DeviceService } from 'src/device/services';
|
import { DeviceService } from 'src/device/services';
|
||||||
import {
|
import {
|
||||||
AddAutomationInterface,
|
AddAutomationInterface,
|
||||||
|
AutomationDetailsResult,
|
||||||
AutomationResponseData,
|
AutomationResponseData,
|
||||||
DeleteAutomationInterface,
|
DeleteAutomationInterface,
|
||||||
GetAutomationByUnitInterface,
|
GetAutomationByUnitInterface,
|
||||||
@ -186,6 +187,38 @@ export class AutomationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async getTapToRunSceneDetailsTuya(
|
||||||
|
sceneId: string,
|
||||||
|
): Promise<AutomationDetailsResult> {
|
||||||
|
try {
|
||||||
|
const path = `/v2.0/cloud/scene/rule/${sceneId}`;
|
||||||
|
const response = await this.tuya.request({
|
||||||
|
method: 'GET',
|
||||||
|
path,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.success) {
|
||||||
|
throw new HttpException(response.msg, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
const camelCaseResponse = convertKeysToCamelCase(response);
|
||||||
|
const { id, name, type } = camelCaseResponse.result;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
} as AutomationDetailsResult;
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof BadRequestException) {
|
||||||
|
throw err; // Re-throw BadRequestException
|
||||||
|
} else {
|
||||||
|
throw new HttpException(
|
||||||
|
'Scene not found for Tuya',
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
async getAutomationDetails(automationId: string, withSpaceId = false) {
|
async getAutomationDetails(automationId: string, withSpaceId = false) {
|
||||||
try {
|
try {
|
||||||
const path = `/v2.0/cloud/scene/rule/${automationId}`;
|
const path = `/v2.0/cloud/scene/rule/${automationId}`;
|
||||||
@ -215,6 +248,18 @@ export class AutomationService {
|
|||||||
if (device) {
|
if (device) {
|
||||||
action.entityId = device.uuid;
|
action.entityId = device.uuid;
|
||||||
}
|
}
|
||||||
|
} else if (
|
||||||
|
action.actionExecutor !== 'device_issue' &&
|
||||||
|
action.actionExecutor !== 'delay'
|
||||||
|
) {
|
||||||
|
const sceneDetails = await this.getTapToRunSceneDetailsTuya(
|
||||||
|
action.entityId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (sceneDetails.id) {
|
||||||
|
action.name = sceneDetails.name;
|
||||||
|
action.type = sceneDetails.type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,3 +21,8 @@ export interface DeleteTapToRunSceneInterface {
|
|||||||
msg?: string;
|
msg?: string;
|
||||||
result: boolean;
|
result: boolean;
|
||||||
}
|
}
|
||||||
|
export interface SceneDetailsResult {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
@ -15,6 +15,7 @@ import {
|
|||||||
AddTapToRunSceneInterface,
|
AddTapToRunSceneInterface,
|
||||||
DeleteTapToRunSceneInterface,
|
DeleteTapToRunSceneInterface,
|
||||||
GetTapToRunSceneByUnitInterface,
|
GetTapToRunSceneByUnitInterface,
|
||||||
|
SceneDetailsResult,
|
||||||
} from '../interface/scene.interface';
|
} from '../interface/scene.interface';
|
||||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||||
|
|
||||||
@ -256,6 +257,18 @@ export class SceneService {
|
|||||||
if (device) {
|
if (device) {
|
||||||
action.entityId = device.uuid;
|
action.entityId = device.uuid;
|
||||||
}
|
}
|
||||||
|
} else if (
|
||||||
|
action.actionExecutor !== 'device_issue' &&
|
||||||
|
action.actionExecutor !== 'delay'
|
||||||
|
) {
|
||||||
|
const sceneDetails = await this.getTapToRunSceneDetailsTuya(
|
||||||
|
action.entityId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (sceneDetails.id) {
|
||||||
|
action.name = sceneDetails.name;
|
||||||
|
action.type = sceneDetails.type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,6 +288,38 @@ export class SceneService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async getTapToRunSceneDetailsTuya(
|
||||||
|
sceneId: string,
|
||||||
|
): Promise<SceneDetailsResult> {
|
||||||
|
try {
|
||||||
|
const path = `/v2.0/cloud/scene/rule/${sceneId}`;
|
||||||
|
const response = await this.tuya.request({
|
||||||
|
method: 'GET',
|
||||||
|
path,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.success) {
|
||||||
|
throw new HttpException(response.msg, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
const camelCaseResponse = convertKeysToCamelCase(response);
|
||||||
|
const { id, name, type } = camelCaseResponse.result;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
} as SceneDetailsResult;
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof BadRequestException) {
|
||||||
|
throw err; // Re-throw BadRequestException
|
||||||
|
} else {
|
||||||
|
throw new HttpException(
|
||||||
|
'Scene not found for Tuya',
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
async updateTapToRunScene(
|
async updateTapToRunScene(
|
||||||
updateSceneTapToRunDto: UpdateSceneTapToRunDto,
|
updateSceneTapToRunDto: UpdateSceneTapToRunDto,
|
||||||
sceneId: string,
|
sceneId: string,
|
||||||
|
Reference in New Issue
Block a user