Don't change default UPS text response colour to white (#143)

This commit is contained in:
Meliox 2025-10-11 09:27:15 +02:00 committed by GitHub
parent bb56097710
commit b2bf77dad3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1372,32 +1372,34 @@ generate_ups_widget() {
// If objValue is null or empty, return N/A // If objValue is null or empty, return N/A
if (!objValue || Object.keys(objValue).length === 0) { if (!objValue || Object.keys(objValue).length === 0) {
return '<div style="text-align: right;"><span style="color: white;">N/A</span></div>'; return '<div style="text-align: right;"><span>N/A</span></div>';
} }
// Helper function to get status color // Helper function to get status color
// Returns a CSS color string for non-default states, or null for default (no inline color)
function getStatusColor(status) { function getStatusColor(status) {
if (!status) return '#999'; if (!status) return '#999';
const statusUpper = status.toUpperCase(); const statusUpper = status.toUpperCase();
if (statusUpper.includes('OL')) return 'white'; // White for online if (statusUpper.includes('OL')) return null; // default (no explicit color)
if (statusUpper.includes('OB')) return '#d9534f'; // Red for on battery if (statusUpper.includes('OB')) return '#d9534f'; // Red for on battery
if (statusUpper.includes('LB')) return '#d9534f'; // Red for low battery if (statusUpper.includes('LB')) return '#d9534f'; // Red for low battery
return '#f0ad4e'; // Orange for other states return '#f0ad4e'; // Orange for other states
} }
// Helper function to get load/charge color // Helper function to get load/charge color
// Returns null for default/good values so no inline style is emitted
function getPercentageColor(value, isLoad = false) { function getPercentageColor(value, isLoad = false) {
if (!value || isNaN(value)) return '#999'; if (!value || isNaN(value)) return '#999';
const num = parseFloat(value); const num = parseFloat(value);
if (isLoad) { if (isLoad) {
if (num >= 80) return '#d9534f'; // Red for high load if (num >= 80) return '#d9534f'; // Red for high load
if (num >= 60) return '#f0ad4e'; // Orange for medium load if (num >= 60) return '#f0ad4e'; // Orange for medium load
return 'white'; // White for low load return null; // default (no explicit color)
} else { } else {
// For battery charge // For battery charge
if (num <= 20) return '#d9534f'; // Red for low charge if (num <= 20) return '#d9534f'; // Red for low charge
if (num <= 50) return '#f0ad4e'; // Orange for medium charge if (num <= 50) return '#f0ad4e'; // Orange for medium charge
return 'white'; // White for good charge return null; // default (no explicit color)
} }
} }
@ -1425,12 +1427,12 @@ generate_ups_widget() {
// Build the status display // Build the status display
let displayItems = []; let displayItems = [];
// First line: Model info // First line: Model info (no explicit color for default)
let modelLine = ''; let modelLine = '';
if (upsModel) { if (upsModel) {
modelLine = `<span style="color: white;">${upsModel}</span>`; modelLine = `<span>${upsModel}</span>`;
} else { } else {
modelLine = `<span style="color: white;">N/A</span>`; modelLine = `<span>N/A</span>`;
} }
displayItems.push(modelLine); displayItems.push(modelLine);
@ -1445,7 +1447,7 @@ generate_ups_widget() {
if (statusUpper.includes('OL')) { if (statusUpper.includes('OL')) {
statusText = 'Online'; statusText = 'Online';
statusColor = 'white'; // White for good status statusColor = null; // default (no explicit color)
} else if (statusUpper.includes('OB')) { } else if (statusUpper.includes('OB')) {
statusText = 'On Battery'; statusText = 'On Battery';
statusColor = '#d9534f'; // Red for on battery statusColor = '#d9534f'; // Red for on battery
@ -1457,27 +1459,30 @@ generate_ups_widget() {
statusColor = '#f0ad4e'; // Orange for unknown status statusColor = '#f0ad4e'; // Orange for unknown status
} }
statusLine += `Status: <span style="color: ${statusColor};">${statusText}</span>`; let statusStyle = statusColor ? ('color: ' + statusColor + ';') : '';
statusLine += 'Status: <span style="' + statusStyle + '">' + statusText + '</span>';
} else { } else {
statusLine += `Status: <span style="color: white;">N/A</span>`; statusLine += 'Status: <span>N/A</span>';
} }
// Battery charge // Battery charge
if (statusLine) statusLine += ' | '; if (statusLine) statusLine += ' | ';
if (batteryCharge) { if (batteryCharge) {
const chargeColor = getPercentageColor(batteryCharge, false); const chargeColor = getPercentageColor(batteryCharge, false);
statusLine += `Battery: <span style="color: ${chargeColor};">${batteryCharge}%</span>`; let chargeStyle = chargeColor ? ('color: ' + chargeColor + ';') : '';
statusLine += 'Battery: <span style="' + chargeStyle + '">' + batteryCharge + '%</span>';
} else { } else {
statusLine += `Battery: <span style="color: white;">N/A</span>`; statusLine += 'Battery: <span>N/A</span>';
} }
// Load percentage // Load percentage
if (statusLine) statusLine += ' | '; if (statusLine) statusLine += ' | ';
if (upsLoad) { if (upsLoad) {
const loadColor = getPercentageColor(upsLoad, true); const loadColor = getPercentageColor(upsLoad, true);
statusLine += `Load: <span style="color: ${loadColor};">${upsLoad}%</span>`; let loadStyle = loadColor ? ('color: ' + loadColor + ';') : '';
statusLine += 'Load: <span style="' + loadStyle + '">' + upsLoad + '%</span>';
} else { } else {
statusLine += `Load: <span style="color: white;">N/A</span>`; statusLine += 'Load: <span>N/A</span>';
} }
// Runtime // Runtime
@ -1485,21 +1490,21 @@ generate_ups_widget() {
if (batteryRuntime) { if (batteryRuntime) {
const runtime = parseInt(batteryRuntime); const runtime = parseInt(batteryRuntime);
const runtimeLowThreshold = batteryRuntimeLow ? parseInt(batteryRuntimeLow) : 600; const runtimeLowThreshold = batteryRuntimeLow ? parseInt(batteryRuntimeLow) : 600;
let runtimeColor = 'white'; let runtimeColor = null;
if (runtime <= runtimeLowThreshold / 2) runtimeColor = '#d9534f'; // Red if less than half of low threshold if (runtime <= runtimeLowThreshold / 2) runtimeColor = '#d9534f'; // Red if less than half of low threshold
else if (runtime <= runtimeLowThreshold) runtimeColor = '#f0ad4e'; // Orange if at low threshold else if (runtime <= runtimeLowThreshold) runtimeColor = '#f0ad4e'; // Orange if at low threshold
let runtimeStyle = runtimeColor ? ('color: ' + runtimeColor + ';') : '';
statusLine += `Runtime: <span style="color: ${runtimeColor};">${formatRuntime(runtime)}</span>`; statusLine += 'Runtime: <span style="' + runtimeStyle + '">' + formatRuntime(runtime) + '</span>';
} else { } else {
statusLine += `Runtime: <span style="color: white;">N/A</span>`; statusLine += 'Runtime: <span>N/A</span>';
} }
// Input voltage // Input voltage
if (statusLine) statusLine += ' | '; if (statusLine) statusLine += ' | ';
if (inputVoltage) { if (inputVoltage) {
statusLine += `Input: <span style="color: white;">${parseFloat(inputVoltage).toFixed(0)}V</span>`; statusLine += 'Input: <span>' + parseFloat(inputVoltage).toFixed(0) + 'V</span>';
} else { } else {
statusLine += `Input: <span style="color: white;">N/A</span>`; statusLine += 'Input: <span>N/A</span>';
} }
// Calculate actual watt usage // Calculate actual watt usage
@ -1515,9 +1520,9 @@ generate_ups_widget() {
// Real power (calculated watt usage) // Real power (calculated watt usage)
if (actualWattage !== null) { if (actualWattage !== null) {
statusLine += `Output: <span style="color: white;">${actualWattage}W</span>`; statusLine += 'Output: <span>' + actualWattage + 'W</span>';
} else { } else {
statusLine += `Output: <span style="color: white;">N/A</span>`; statusLine += 'Output: <span>N/A</span>';
} }
displayItems.push(statusLine); displayItems.push(statusLine);
@ -1525,16 +1530,17 @@ generate_ups_widget() {
// Combined battery and test line // Combined battery and test line
let batteryTestLine = ''; let batteryTestLine = '';
if (batteryMfrDate) { if (batteryMfrDate) {
batteryTestLine += `<span style="color: white;">Battery MFD: ${batteryMfrDate}</span>`; batteryTestLine += '<span>Battery MFD: ' + batteryMfrDate + '</span>';
} else { } else {
batteryTestLine += `<span style="color: white;">Battery MFD: N/A</span>`; batteryTestLine += '<span>Battery MFD: N/A</span>';
} }
if (testResult && !testResult.toLowerCase().includes('no test')) { if (testResult && !testResult.toLowerCase().includes('no test')) {
const testColor = testResult.toLowerCase().includes('passed') ? 'white' : '#d9534f'; const testColor = testResult.toLowerCase().includes('passed') ? null : '#d9534f';
batteryTestLine += ` | <span style="color: ${testColor};">Test: ${testResult}</span>`; let testStyle = testColor ? ('color: ' + testColor + ';') : '';
batteryTestLine += ' | <span style="' + testStyle + '">Test: ' + testResult + '</span>';
} else { } else {
batteryTestLine += ` | <span style="color: white;">Test: N/A</span>`; batteryTestLine += ' | <span>Test: N/A</span>';
} }
displayItems.push(batteryTestLine); displayItems.push(batteryTestLine);