Skip to content

Commit b531aed

Browse files
authored
feat: add UPS power (#1874)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added nominal and current power metrics for UPS devices (nominal can be sourced from an optional field; current is derived from nominal and load), improving capacity and consumption visibility. * **Tests** * Updated UPS mock data to include nominal power for validation. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 38a6f0c commit b531aed

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

api/src/unraid-api/graph/resolvers/ups/ups.model.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ export class UPSPower {
4040
'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',
4141
})
4242
loadPercentage!: number;
43+
44+
@Field(() => Int, {
45+
nullable: true,
46+
description:
47+
'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',
48+
})
49+
nominalPower?: number;
50+
51+
@Field(() => Float, {
52+
nullable: true,
53+
description:
54+
'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)',
55+
})
56+
currentPower?: number;
4357
}
4458

4559
@ObjectType()

api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('UPSResolver', () => {
2626
LINEV: '120.5',
2727
OUTPUTV: '120.5',
2828
LOADPCT: '25',
29+
NOMPOWER: '600',
2930
};
3031

3132
beforeEach(async () => {

api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ export class UPSResolver {
1414
) {}
1515

1616
private createUPSDevice(upsData: UPSData, id: string): UPSDevice {
17+
const loadPercentage = parseInt(upsData.LOADPCT || '25', 10);
18+
const nominalPower = upsData.NOMPOWER ? parseInt(upsData.NOMPOWER, 10) : undefined;
19+
const currentPower =
20+
nominalPower !== undefined
21+
? parseFloat(((nominalPower * loadPercentage) / 100).toFixed(2))
22+
: undefined;
23+
1724
return {
1825
id,
1926
name: upsData.MODEL || 'My UPS',
@@ -28,7 +35,9 @@ export class UPSResolver {
2835
power: {
2936
inputVoltage: parseFloat(upsData.LINEV || '120.5'),
3037
outputVoltage: parseFloat(upsData.OUTPUTV || '120.5'),
31-
loadPercentage: parseInt(upsData.LOADPCT || '25', 10),
38+
loadPercentage,
39+
nominalPower,
40+
currentPower,
3241
},
3342
};
3443
}

api/src/unraid-api/graph/resolvers/ups/ups.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const UPSSchema = z.object({
1515
LINEV: z.string().optional(),
1616
OUTPUTV: z.string().optional(),
1717
LOADPCT: z.string().optional(),
18+
NOMPOWER: z.string().optional(),
1819
});
1920

2021
export type UPSData = z.infer<typeof UPSSchema>;

0 commit comments

Comments
 (0)