mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 10:46:17 +00:00
Merge pull request #119 from SyncrowIOT/fix-power-clamp-response
edit power clamp response
This commit is contained in:
@ -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,
|
||||||
|
@ -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(
|
||||||
|
Reference in New Issue
Block a user