Merge pull request #119 from SyncrowIOT/fix-power-clamp-response

edit power clamp response
This commit is contained in:
faris Aljohari
2024-10-19 13:36:25 -05:00
committed by GitHub
2 changed files with 34 additions and 2 deletions

View File

@ -192,7 +192,7 @@ export class DeviceController {
); );
} }
@ApiBearerAuth() @ApiBearerAuth()
// @UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Get(':powerClampUuid/power-clamp/status') @Get(':powerClampUuid/power-clamp/status')
async getPowerClampInstructionStatus( async getPowerClampInstructionStatus(
@Param('powerClampUuid') powerClampUuid: string, @Param('powerClampUuid') powerClampUuid: string,

View File

@ -977,11 +977,43 @@ export class DeviceService {
const deviceStatus = await this.getPowerClampInstructionStatusTuya( const deviceStatus = await this.getPowerClampInstructionStatusTuya(
deviceDetails.deviceTuyaUuid, deviceDetails.deviceTuyaUuid,
); );
const statusList = deviceStatus.result.properties as {
code: string;
value: any;
}[];
const groupedStatus = statusList.reduce(
(acc, currentStatus) => {
const { code } = currentStatus;
if (code.includes('A')) {
acc.phaseA.push(currentStatus);
} else if (code.includes('B')) {
acc.phaseB.push(currentStatus);
} else if (code.includes('C')) {
acc.phaseC.push(currentStatus);
} else {
acc.general.push(currentStatus);
}
return acc;
},
{
phaseA: [] as { code: string; value: any }[],
phaseB: [] as { code: string; value: any }[],
phaseC: [] as { code: string; value: any }[],
general: [] as { code: string; value: any }[],
},
);
return { return {
productUuid: deviceDetails.productDevice.uuid, productUuid: deviceDetails.productDevice.uuid,
productType: deviceDetails.productDevice.prodType, productType: deviceDetails.productDevice.prodType,
status: deviceStatus.result.properties, status: {
phaseA: groupedStatus.phaseA,
phaseB: groupedStatus.phaseB,
phaseC: groupedStatus.phaseC,
general: groupedStatus.general,
},
}; };
} catch (error) { } catch (error) {
throw new HttpException( throw new HttpException(