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:
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user