mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:54:54 +00:00
finished get power clamp status
This commit is contained in:
@ -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