@@ -17,7 +17,6 @@ import type { PropertyValues } from "lit";
17
17
import { css , html , LitElement , svg , nothing } from "lit" ;
18
18
import { customElement , property , state } from "lit/decorators" ;
19
19
import { classMap } from "lit/directives/class-map" ;
20
- import { formatNumber } from "../../../../common/number/format_number" ;
21
20
import "../../../../components/ha-card" ;
22
21
import "../../../../components/ha-svg-icon" ;
23
22
import type { EnergyData } from "../../../../data/energy" ;
@@ -26,6 +25,7 @@ import {
26
25
getEnergyDataCollection ,
27
26
getEnergyGasUnit ,
28
27
getEnergyWaterUnit ,
28
+ formatConsumptionShort ,
29
29
} from "../../../../data/energy" ;
30
30
import { calculateStatisticsSumGrowth } from "../../../../data/recorder" ;
31
31
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin" ;
@@ -308,10 +308,11 @@ class HuiEnergyDistrubutionCard
308
308
rel= "noopener no referrer"
309
309
>
310
310
<ha- svg- icon .path = ${ mdiLeaf } > </ ha- svg- icon>
311
- ${ formatNumber ( lowCarbonEnergy || 0 , this . hass . locale , {
312
- maximumFractionDigits : 1 ,
313
- } ) }
314
- kWh
311
+ ${ formatConsumptionShort (
312
+ this . hass ,
313
+ lowCarbonEnergy ,
314
+ "kWh"
315
+ ) }
315
316
</ a>
316
317
<svg width= "80" height = "30">
317
318
<line x1= "40" y1 = "0" x2= "40" y2= "30"> </ line>
@@ -326,12 +327,11 @@ class HuiEnergyDistrubutionCard
326
327
>
327
328
<div class= "circle" >
328
329
<ha- svg- icon .path = ${ mdiSolarPower } > </ ha- svg- icon>
329
- ${ formatNumber (
330
- totalSolarProduction || 0 ,
331
- this . hass . locale ,
332
- { maximumFractionDigits : 1 }
330
+ ${ formatConsumptionShort (
331
+ this . hass ,
332
+ totalSolarProduction ,
333
+ "kWh"
333
334
) }
334
- kWh
335
335
</ div>
336
336
</ div> `
337
337
: hasGas || hasWater
@@ -346,13 +346,14 @@ class HuiEnergyDistrubutionCard
346
346
>
347
347
<div class= "circle" >
348
348
<ha- svg- icon .path = ${ mdiFire } > </ ha- svg- icon>
349
- ${ formatNumber ( gasUsage || 0 , this . hass . locale , {
350
- maximumFractionDigits : 1 ,
351
- } ) }
352
- ${ getEnergyGasUnit (
349
+ ${ formatConsumptionShort (
353
350
this . hass ,
354
- prefs ,
355
- this . _data . statsMetadata
351
+ gasUsage ,
352
+ getEnergyGasUnit (
353
+ this . hass ,
354
+ prefs ,
355
+ this . _data . statsMetadata
356
+ )
356
357
) }
357
358
</ div>
358
359
<svg width= "80" height = "30">
@@ -383,10 +384,11 @@ class HuiEnergyDistrubutionCard
383
384
>
384
385
<div class= "circle" >
385
386
<ha- svg- icon .path = ${ mdiWater } > </ ha- svg- icon>
386
- ${ formatNumber ( waterUsage || 0 , this . hass . locale , {
387
- maximumFractionDigits : 1 ,
388
- } ) }
389
- ${ getEnergyWaterUnit ( this . hass ) }
387
+ ${ formatConsumptionShort (
388
+ this . hass ,
389
+ waterUsage ,
390
+ getEnergyWaterUnit ( this . hass )
391
+ ) }
390
392
</ div>
391
393
<svg width= "80" height = "30">
392
394
<path d= "M40 0 v30" id = "water" / >
@@ -420,10 +422,11 @@ class HuiEnergyDistrubutionCard
420
422
class= "small"
421
423
.path = ${ mdiArrowLeft }
422
424
> </ ha- svg- icon
423
- > ${ formatNumber ( returnedToGrid , this . hass . locale , {
424
- maximumFractionDigits : 1 ,
425
- } ) }
426
- kWh
425
+ > ${ formatConsumptionShort (
426
+ this . hass ,
427
+ returnedToGrid ,
428
+ "kWh"
429
+ ) }
427
430
</ span> `
428
431
: "" }
429
432
<span class= "consumption" >
@@ -432,10 +435,11 @@ class HuiEnergyDistrubutionCard
432
435
class= "small"
433
436
.path = ${ mdiArrowRight }
434
437
> </ ha- svg- icon> `
435
- : "" } ${ formatNumber ( totalFromGrid , this . hass . locale , {
436
- maximumFractionDigits : 1 ,
437
- } ) }
438
- kWh
438
+ : "" } ${ formatConsumptionShort (
439
+ this . hass ,
440
+ totalFromGrid ,
441
+ "kWh"
442
+ ) }
439
443
</ span>
440
444
</ div>
441
445
<span class= "label"
@@ -453,10 +457,11 @@ class HuiEnergyDistrubutionCard
453
457
} ) } "
454
458
>
455
459
<ha- svg- icon .path = ${ mdiHome } > </ ha- svg- icon>
456
- ${ formatNumber ( totalHomeConsumption , this . hass . locale , {
457
- maximumFractionDigits : 1 ,
458
- } ) }
459
- kWh
460
+ ${ formatConsumptionShort (
461
+ this . hass ,
462
+ totalHomeConsumption ,
463
+ "kWh"
464
+ ) }
460
465
${ homeSolarCircumference !== undefined ||
461
466
homeLowCarbonCircumference !== undefined
462
467
? html `<svg>
@@ -550,29 +555,23 @@ class HuiEnergyDistrubutionCard
550
555
class= "small"
551
556
.path = ${ mdiArrowDown }
552
557
> </ ha- svg- icon
553
- > ${ formatNumber (
554
- totalBatteryIn || 0 ,
555
- this . hass . locale ,
556
- {
557
- maximumFractionDigits : 1 ,
558
- }
558
+ > ${ formatConsumptionShort (
559
+ this . hass ,
560
+ totalBatteryIn ,
561
+ "kWh"
559
562
) }
560
- kWh </ span
561
- >
563
+ </ span>
562
564
<span class= "battery-out" >
563
565
<ha- svg- icon
564
566
class= "small"
565
567
.path = ${ mdiArrowUp }
566
568
> </ ha- svg- icon
567
- > ${ formatNumber (
568
- totalBatteryOut || 0 ,
569
- this . hass . locale ,
570
- {
571
- maximumFractionDigits : 1 ,
572
- }
569
+ > ${ formatConsumptionShort (
570
+ this . hass ,
571
+ totalBatteryOut ,
572
+ "kWh"
573
573
) }
574
- kWh </ span
575
- >
574
+ </ span>
576
575
</ div>
577
576
<span class= "label"
578
577
> ${ this . hass . localize (
@@ -603,10 +602,11 @@ class HuiEnergyDistrubutionCard
603
602
</ svg>
604
603
<div class= "circle" >
605
604
<ha- svg- icon .path = ${ mdiWater } > </ ha- svg- icon>
606
- ${ formatNumber ( waterUsage || 0 , this . hass . locale , {
607
- maximumFractionDigits : 1 ,
608
- } ) }
609
- ${ getEnergyWaterUnit ( this . hass ) }
605
+ ${ formatConsumptionShort (
606
+ this . hass ,
607
+ waterUsage ,
608
+ getEnergyWaterUnit ( this . hass )
609
+ ) }
610
610
</ div>
611
611
<span class= "label"
612
612
> ${ this . hass . localize (
0 commit comments