mirror of
https://github.com/unraid/api.git
synced 2026-02-05 23:48:59 -06:00
fix(ups): convert estimatedRuntime from minutes to seconds (#1822)
## Summary Fixes the `estimatedRuntime` field in the UPS GraphQL query to return values in **seconds** as documented, instead of **minutes**. ## Problem The `TIMELEFT` value from `apcupsd` is returned in minutes (e.g., `6.0` for 6 minutes), but the GraphQL schema documentation states: > Estimated runtime remaining on battery power. **Unit: seconds**. Example: 3600 means 1 hour of runtime remaining Currently, the API returns `6` (minutes) instead of `360` (seconds). ## Solution Convert the `TIMELEFT` value from minutes to seconds by multiplying by 60: ```typescript // Before estimatedRuntime: parseInt(upsData.TIMELEFT || '3600', 10), // After estimatedRuntime: Math.round(parseFloat(upsData.TIMELEFT || '60') * 60), ``` ## Testing 1. Query `upsDevices` before the fix → `estimatedRuntime: 6` (incorrect - minutes) 2. Query `upsDevices` after the fix → `estimatedRuntime: 360` (correct - seconds) Tested on Unraid server with APC UPS connected via apcupsd. ## Related Issues Fixes #1821 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Corrected UPS battery runtime calculation to interpret provider TIMELEFT as minutes, convert to seconds, and use a sensible default when missing—improves displayed battery runtime accuracy. * **Tests** * Updated UPS test fixtures to match the minute-based TIMELEFT format used by the UPS provider. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -22,7 +22,7 @@ describe('UPSResolver', () => {
|
||||
MODEL: 'Test UPS',
|
||||
STATUS: 'Online',
|
||||
BCHARGE: '100',
|
||||
TIMELEFT: '3600',
|
||||
TIMELEFT: '60', // 60 minutes (apcupsd format)
|
||||
LINEV: '120.5',
|
||||
OUTPUTV: '120.5',
|
||||
LOADPCT: '25',
|
||||
|
||||
@@ -21,7 +21,8 @@ export class UPSResolver {
|
||||
status: upsData.STATUS || 'Online',
|
||||
battery: {
|
||||
chargeLevel: parseInt(upsData.BCHARGE || '100', 10),
|
||||
estimatedRuntime: parseInt(upsData.TIMELEFT || '3600', 10),
|
||||
// Convert TIMELEFT from minutes (apcupsd format) to seconds
|
||||
estimatedRuntime: Math.round(parseFloat(upsData.TIMELEFT || '60') * 60),
|
||||
health: 'Good',
|
||||
},
|
||||
power: {
|
||||
|
||||
Reference in New Issue
Block a user