Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions api/src/unraid-api/graph/resolvers/ups/ups.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ export class UPSPower {
'Current load on the UPS as a percentage of its capacity. Unit: percent (%). Example: 25 means UPS is loaded at 25% of its maximum capacity',
})
loadPercentage!: number;

@Field(() => Int, {
nullable: true,
description:
'Nominal power capacity of the UPS. Unit: watts (W). Example: 1000 means the UPS is rated for 1000 watts. This is the maximum power the UPS can deliver',
})
nominalPower?: number;

@Field(() => Float, {
nullable: true,
description:
'Current power consumption calculated from load percentage and nominal power. Unit: watts (W). Example: 350 means 350 watts currently being used. Calculated as: nominalPower * (loadPercentage / 100)',
})
currentPower?: number;
}

@ObjectType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('UPSResolver', () => {
LINEV: '120.5',
OUTPUTV: '120.5',
LOADPCT: '25',
NOMPOWER: '600',
};

beforeEach(async () => {
Expand Down
11 changes: 10 additions & 1 deletion api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export class UPSResolver {
) {}

private createUPSDevice(upsData: UPSData, id: string): UPSDevice {
const loadPercentage = parseInt(upsData.LOADPCT || '25', 10);
const nominalPower = upsData.NOMPOWER ? parseInt(upsData.NOMPOWER, 10) : undefined;
const currentPower =
nominalPower !== undefined
? parseFloat(((nominalPower * loadPercentage) / 100).toFixed(2))
: undefined;

return {
id,
name: upsData.MODEL || 'My UPS',
Expand All @@ -28,7 +35,9 @@ export class UPSResolver {
power: {
inputVoltage: parseFloat(upsData.LINEV || '120.5'),
outputVoltage: parseFloat(upsData.OUTPUTV || '120.5'),
loadPercentage: parseInt(upsData.LOADPCT || '25', 10),
loadPercentage,
nominalPower,
currentPower,
},
};
}
Expand Down
1 change: 1 addition & 0 deletions api/src/unraid-api/graph/resolvers/ups/ups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const UPSSchema = z.object({
LINEV: z.string().optional(),
OUTPUTV: z.string().optional(),
LOADPCT: z.string().optional(),
NOMPOWER: z.string().optional(),
});

export type UPSData = z.infer<typeof UPSSchema>;
Expand Down
Loading