1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-02-15 07:25:54 +00:00

Switch energy now chart to watts, format values to W, kW etc (#28555)

* Switch energy now chart to watts

* Add kW

* Scale formatted value based on powers of 1000

1000 W -> 1 kW
W → kW → MW → GW → TW

* Explainers

* Use 3 dp for kW+ and 0 for W

* Add non-integer test
This commit is contained in:
Aidan Timson
2025-12-16 12:33:45 +00:00
committed by GitHub
parent 24a797e46a
commit 3425837de3
4 changed files with 70 additions and 20 deletions

View File

@@ -12,6 +12,7 @@ import {
computeConsumptionSingle,
formatConsumptionShort,
calculateSolarConsumedGauge,
formatPowerShort,
} from "../../src/data/energy";
import type { HomeAssistant } from "../../src/types";
@@ -171,6 +172,17 @@ describe("Energy Short Format Test", () => {
"151 MWh"
);
});
it("Power Short Format", () => {
assert.strictEqual(formatPowerShort(hass, 0), "0 W");
assert.strictEqual(formatPowerShort(hass, 10), "10 W");
assert.strictEqual(formatPowerShort(hass, 12.2), "12 W");
assert.strictEqual(formatPowerShort(hass, 999), "999 W");
assert.strictEqual(formatPowerShort(hass, 1000), "1 kW");
assert.strictEqual(formatPowerShort(hass, 1234), "1.234 kW");
assert.strictEqual(formatPowerShort(hass, 10_500), "10.5 kW");
assert.strictEqual(formatPowerShort(hass, 1_500_000), "1.5 MW");
assert.strictEqual(formatPowerShort(hass, -1500), "-1.5 kW");
});
});
describe("Energy Usage Calculation Tests", () => {