From f19730ff1da1e8c8815e8df6d04bfd6361369831 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 10 Mar 2026 10:27:27 +0100 Subject: [PATCH] Fix: Secondary sensor display - Wh/EUR precision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Separate Wh from W in getSecondaryVal: Wh values >= 1000 now display as kWh (e.g., 794 Wh -> 0.79 kWh) - EUR/ct/€ units now show 2 decimal places (0.28 EUR/kWh instead of 0.3) - W values continue using _formatPower() as before Co-Authored-By: Claude Opus 4.6 --- dist/power-flux-card.js | 8 +------- src/power-flux-card.js | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/dist/power-flux-card.js b/dist/power-flux-card.js index d65ef37..2400503 100644 --- a/dist/power-flux-card.js +++ b/dist/power-flux-card.js @@ -1820,13 +1820,7 @@ console.log( const val = parseFloat(state.state); if (isNaN(val)) return state.state + (state.attributes.unit_of_measurement ? ' ' + state.attributes.unit_of_measurement : ''); const unit = state.attributes.unit_of_measurement || ''; - if (unit === 'W' || unit === 'Wh') { - return this._formatPower(val); - } - if (unit === 'kWh' || unit === 'kW') { - return val.toFixed(1) + ' ' + unit; - } - return val.toFixed(1) + (unit ? ' ' + unit : ''); + if (unit === 'W') { return this._formatPower(val); } if (unit === 'Wh') { if (Math.abs(val) >= 1000) return (val / 1000).toFixed(2) + ' kWh'; return Math.round(val) + ' Wh'; } if (unit === 'kWh' || unit === 'kW') { return val.toFixed(1) + ' ' + unit; } if (unit.includes('EUR') || unit.includes('ct') || unit.includes('€')) { return val.toFixed(2) + ' ' + unit; } return val.toFixed(1) + (unit ? ' ' + unit : ''); }; // Determine existence of main entities diff --git a/src/power-flux-card.js b/src/power-flux-card.js index 4db2e67..842366d 100644 --- a/src/power-flux-card.js +++ b/src/power-flux-card.js @@ -820,13 +820,7 @@ console.log( const val = parseFloat(state.state); if (isNaN(val)) return state.state + (state.attributes.unit_of_measurement ? ' ' + state.attributes.unit_of_measurement : ''); const unit = state.attributes.unit_of_measurement || ''; - if (unit === 'W' || unit === 'Wh') { - return this._formatPower(val); - } - if (unit === 'kWh' || unit === 'kW') { - return val.toFixed(1) + ' ' + unit; - } - return val.toFixed(1) + (unit ? ' ' + unit : ''); + if (unit === 'W') { return this._formatPower(val); } if (unit === 'Wh') { if (Math.abs(val) >= 1000) return (val / 1000).toFixed(2) + ' kWh'; return Math.round(val) + ' Wh'; } if (unit === 'kWh' || unit === 'kW') { return val.toFixed(1) + ' ' + unit; } if (unit.includes('EUR') || unit.includes('ct') || unit.includes('€')) { return val.toFixed(2) + ' ' + unit; } return val.toFixed(1) + (unit ? ' ' + unit : ''); }; // Determine existence of main entities