mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 10:46:17 +00:00
finished get power clamp status
This commit is contained in:
@ -15,4 +15,5 @@ export enum ProductType {
|
||||
WL = 'WL',
|
||||
GD = 'GD',
|
||||
CUR = 'CUR',
|
||||
PC = 'PC',
|
||||
}
|
||||
|
@ -191,4 +191,14 @@ export class DeviceController {
|
||||
batchFactoryResetDevicesDto,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
// @UseGuards(JwtAuthGuard)
|
||||
@Get(':powerClampUuid/power-clamp/status')
|
||||
async getPowerClampInstructionStatus(
|
||||
@Param('powerClampUuid') powerClampUuid: string,
|
||||
) {
|
||||
return await this.deviceService.getPowerClampInstructionStatus(
|
||||
powerClampUuid,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -70,3 +70,10 @@ export interface getDeviceLogsInterface {
|
||||
endTime: string;
|
||||
deviceUuid?: string;
|
||||
}
|
||||
export interface GetPowerClampFunctionsStatusInterface {
|
||||
result: {
|
||||
properties: [];
|
||||
};
|
||||
success: boolean;
|
||||
msg: string;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
GetDeviceDetailsFunctionsInterface,
|
||||
GetDeviceDetailsFunctionsStatusInterface,
|
||||
GetDeviceDetailsInterface,
|
||||
GetPowerClampFunctionsStatusInterface,
|
||||
controlDeviceInterface,
|
||||
getDeviceLogsInterface,
|
||||
updateDeviceFirmwareInterface,
|
||||
@ -965,4 +966,49 @@ export class DeviceService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async getPowerClampInstructionStatus(powerClampUuid: string) {
|
||||
try {
|
||||
const deviceDetails = await this.getDeviceByDeviceUuid(powerClampUuid);
|
||||
if (!deviceDetails) {
|
||||
throw new NotFoundException('Device Not Found');
|
||||
} else if (deviceDetails.productDevice.prodType !== ProductType.PC) {
|
||||
throw new BadRequestException('This is not a power clamp device');
|
||||
}
|
||||
const deviceStatus = await this.getPowerClampInstructionStatusTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
);
|
||||
|
||||
return {
|
||||
productUuid: deviceDetails.productDevice.uuid,
|
||||
productType: deviceDetails.productDevice.prodType,
|
||||
status: deviceStatus.result.properties,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Error fetching power clamp functions status',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
async getPowerClampInstructionStatusTuya(
|
||||
deviceUuid: string,
|
||||
): Promise<GetPowerClampFunctionsStatusInterface> {
|
||||
try {
|
||||
const path = `/v2.0/cloud/thing/${deviceUuid}/shadow/properties`;
|
||||
const response = await this.tuya.request({
|
||||
method: 'GET',
|
||||
path,
|
||||
query: {
|
||||
device_ids: deviceUuid,
|
||||
},
|
||||
});
|
||||
const camelCaseResponse = convertKeysToCamelCase(response);
|
||||
return camelCaseResponse as GetPowerClampFunctionsStatusInterface;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Error fetching power clamp functions status from Tuya',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user