@@ -532,7 +532,7 @@ class PVPCHourlyPricingCard extends LitElement {
532
532
</ svg >
533
533
534
534
< span class ="currentPrice "
535
- > ${ this . _getFixedFloat ( this . pvpcHourlyPricingObj . state ) } </ span
535
+ > ${ this . _formatNumber ( this . pvpcHourlyPricingObj . state ) } </ span
536
536
>
537
537
< span class ="currentPriceUnit ">
538
538
${ this . pvpcHourlyPricingObj . attributes . unit_of_measurement } </ span
@@ -546,37 +546,25 @@ class PVPCHourlyPricingCard extends LitElement {
546
546
return html `` ;
547
547
}
548
548
549
- const minPrice = this . _getFixedFloat ( this . despiction . minPrice ) ;
550
- const minPriceFrom = this . _getTimeString (
551
- new Date ( ) . setHours ( this . despiction . minIndex , 0 )
549
+ const minPrice = this . _formatNumber ( this . despiction . minPrice ) ;
550
+ const minPriceFrom = this . _formatHour ( this . despiction . minIndex ) ;
551
+ const minPriceTo = this . _formatHour ( this . despiction . minIndex + 1 ) ;
552
+ const maxPrice = this . _formatNumber ( this . despiction . maxPrice ) ;
553
+ const maxPriceFrom = this . _formatHour ( this . despiction . maxIndex ) ;
554
+ const maxPriceTo = this . _formatHour ( this . despiction . maxIndex + 1 ) ;
555
+ const minPriceNextDay = this . _formatNumber ( this . despiction . minPriceNextDay ) ;
556
+ const minPriceFromNextDay = this . _formatHour (
557
+ this . despiction . minIndexNextDay
552
558
) ;
553
- const minPriceTo = this . _getTimeString (
554
- new Date ( ) . setHours ( this . despiction . minIndex + 1 , 0 )
559
+ const minPriceToNextDay = this . _formatHour (
560
+ this . despiction . minIndexNextDay + 1
555
561
) ;
556
- const maxPrice = this . _getFixedFloat ( this . despiction . maxPrice ) ;
557
- const maxPriceFrom = this . _getTimeString (
558
- new Date ( ) . setHours ( this . despiction . maxIndex , 0 )
562
+ const maxPriceNextDay = this . _formatNumber ( this . despiction . maxPriceNextDay ) ;
563
+ const maxPriceFromNextDay = this . _formatHour (
564
+ this . despiction . maxIndexNextDay
559
565
) ;
560
- const maxPriceTo = this . _getTimeString (
561
- new Date ( ) . setHours ( this . despiction . maxIndex + 1 , 0 )
562
- ) ;
563
- const minPriceNextDay = this . _getFixedFloat (
564
- this . despiction . minPriceNextDay
565
- ) ;
566
- const minPriceFromNextDay = this . _getTimeString (
567
- new Date ( ) . setHours ( this . despiction . minIndexNextDay , 0 )
568
- ) ;
569
- const minPriceToNextDay = this . _getTimeString (
570
- new Date ( ) . setHours ( this . despiction . minIndexNextDay + 1 , 0 )
571
- ) ;
572
- const maxPriceNextDay = this . _getFixedFloat (
573
- this . despiction . maxPriceNextDay
574
- ) ;
575
- const maxPriceFromNextDay = this . _getTimeString (
576
- new Date ( ) . setHours ( this . despiction . maxIndexNextDay , 0 )
577
- ) ;
578
- const maxPriceToNextDay = this . _getTimeString (
579
- new Date ( ) . setHours ( this . despiction . maxIndexNextDay + 1 , 0 )
566
+ const maxPriceToNextDay = this . _formatHour (
567
+ this . despiction . maxIndexNextDay + 1
580
568
) ;
581
569
582
570
this . numberElements ++ ;
@@ -588,30 +576,28 @@ class PVPCHourlyPricingCard extends LitElement {
588
576
>
589
577
< li >
590
578
< ha-icon icon ="mdi:thumb-up-outline "> </ ha-icon >
591
- ${ this . _ll ( "minPrice" ) }
592
- ${ minPrice } ${ this . pvpcHourlyPricingObj . attributes . unit_of_measurement }
579
+ ${ this . _ll ( "minPrice" ) } ${ minPrice }
580
+ ${ this . pvpcHourlyPricingObj . attributes . unit_of_measurement }
593
581
${ this . _ll ( "from" ) } ${ minPriceFrom } ${ this . _ll ( "to" ) } ${ minPriceTo }
594
582
</ li >
595
583
< li >
596
584
< ha-icon icon ="mdi:thumb-down-outline "> </ ha-icon >
597
- ${ this . _ll ( "maxPrice" ) }
598
- ${ maxPrice } ${ this . pvpcHourlyPricingObj . attributes . unit_of_measurement }
585
+ ${ this . _ll ( "maxPrice" ) } ${ maxPrice }
586
+ ${ this . pvpcHourlyPricingObj . attributes . unit_of_measurement }
599
587
${ this . _ll ( "from" ) } ${ maxPriceFrom } ${ this . _ll ( "to" ) } ${ maxPriceTo }
600
588
</ li >
601
589
${ this . despiction . minPriceNextDay
602
590
? html ` < li >
603
591
< ha-icon icon ="mdi:thumb-up-outline "> </ ha-icon >
604
- ${ this . _ll ( "minPriceNextDay" ) }
605
- ${ minPriceNextDay } ${ this . pvpcHourlyPricingObj . attributes
606
- . unit_of_measurement }
592
+ ${ this . _ll ( "minPriceNextDay" ) } ${ minPriceNextDay }
593
+ ${ this . pvpcHourlyPricingObj . attributes . unit_of_measurement }
607
594
${ this . _ll ( "from" ) } ${ minPriceFromNextDay } ${ this . _ll ( "to" ) }
608
595
${ minPriceToNextDay }
609
596
</ li >
610
597
< li >
611
598
< ha-icon icon ="mdi:thumb-down-outline "> </ ha-icon >
612
- ${ this . _ll ( "maxPriceNextDay" ) }
613
- ${ maxPriceNextDay } ${ this . pvpcHourlyPricingObj . attributes
614
- . unit_of_measurement }
599
+ ${ this . _ll ( "maxPriceNextDay" ) } ${ maxPriceNextDay }
600
+ ${ this . pvpcHourlyPricingObj . attributes . unit_of_measurement }
615
601
${ this . _ll ( "from" ) } ${ maxPriceFromNextDay } ${ this . _ll ( "to" ) }
616
602
${ maxPriceToNextDay }
617
603
</ li > `
@@ -742,9 +728,9 @@ class PVPCHourlyPricingCard extends LitElement {
742
728
} ,
743
729
formatter : ( params ) => {
744
730
const hours = Math . min ( Number ( params [ 0 ] . axisValue . split ( ":" ) [ 0 ] ) , 23 ) ;
745
- let tooltipContent = `${ this . _getCategoryHour (
746
- hours
747
- ) } - ${ this . _getCategoryHour ( hours + 1 ) } <br/>`;
731
+ let tooltipContent = `${ this . _formatHour ( hours ) } - ${ this . _formatHour (
732
+ hours + 1
733
+ ) } <br/>`;
748
734
params . forEach ( ( item ) => {
749
735
tooltipContent += `${ item . marker } ${ item . seriesName } : ${ item . value } ${ this . pvpcHourlyPricingObj . attributes . unit_of_measurement } <br/>` ;
750
736
} ) ;
@@ -776,14 +762,14 @@ class PVPCHourlyPricingCard extends LitElement {
776
762
} ,
777
763
series : [
778
764
Object . assign ( { } , baseSeries , {
779
- name : this . _getDateString ( today ) ,
765
+ name : this . _formatDate ( today ) ,
780
766
data : data . prices ,
781
767
markArea : {
782
768
itemStyle : { color : splitLineColor } ,
783
769
data : [
784
770
[
785
- { xAxis : this . _getCategoryHour ( now . getHours ( ) ) } ,
786
- { xAxis : this . _getCategoryHour ( now . getHours ( ) + 1 ) } ,
771
+ { xAxis : this . _formatHour ( now . getHours ( ) ) } ,
772
+ { xAxis : this . _formatHour ( now . getHours ( ) + 1 ) } ,
787
773
] ,
788
774
] ,
789
775
} ,
@@ -797,7 +783,7 @@ class PVPCHourlyPricingCard extends LitElement {
797
783
) {
798
784
options . series . push (
799
785
Object . assign ( { } , baseSeries , {
800
- name : this . _getDateString ( tomorrow ) ,
786
+ name : this . _formatDate ( tomorrow ) ,
801
787
data : data . pricesTomorrow ,
802
788
} )
803
789
) ;
@@ -806,7 +792,7 @@ class PVPCHourlyPricingCard extends LitElement {
806
792
if ( data . injectionPrices . some ( ( value ) => value !== 0 ) ) {
807
793
options . series . push (
808
794
Object . assign ( { } , baseSeries , {
809
- name : this . _getDateString ( today ) ,
795
+ name : this . _formatDate ( today ) ,
810
796
data : data . injectionPrices ,
811
797
lineStyle : { type : "dotted" } ,
812
798
} )
@@ -819,7 +805,7 @@ class PVPCHourlyPricingCard extends LitElement {
819
805
) {
820
806
options . series . push (
821
807
Object . assign ( { } , baseSeries , {
822
- name : this . _getDateString ( tomorrow ) ,
808
+ name : this . _formatDate ( tomorrow ) ,
823
809
data : data . injectionPricesTomorrow ,
824
810
lineStyle : { type : "dotted" } ,
825
811
} )
@@ -845,7 +831,7 @@ class PVPCHourlyPricingCard extends LitElement {
845
831
const injectionPricesTomorrow = [ ] ;
846
832
847
833
for ( let i = 0 ; i < 24 ; i ++ ) {
848
- categories . push ( this . _getCategoryHour ( i ) ) ;
834
+ categories . push ( this . _formatHour ( i ) ) ;
849
835
prices . push ( attributes [ `price_${ this . _getPadStartNumber ( i ) } h` ] || 0 ) ;
850
836
pricesTomorrow . push (
851
837
attributes [ `price_next_day_${ this . _getPadStartNumber ( i ) } h` ] || 0
@@ -859,7 +845,7 @@ class PVPCHourlyPricingCard extends LitElement {
859
845
) ;
860
846
}
861
847
862
- categories . push ( this . _getCategoryHour ( 24 ) ) ;
848
+ categories . push ( this . _formatHour ( 24 ) ) ;
863
849
prices . push ( prices [ 23 ] ) ;
864
850
pricesTomorrow . push ( pricesTomorrow [ 23 ] ) ;
865
851
injectionPrices . push ( injectionPrices [ 23 ] ) ;
@@ -913,28 +899,39 @@ class PVPCHourlyPricingCard extends LitElement {
913
899
return data ;
914
900
}
915
901
916
- _getDateString ( datetime ) {
917
- return new Date ( datetime ) . toLocaleDateString ( this . lang , {
918
- day : "2-digit" ,
919
- month : "2-digit" ,
902
+ _formatDate ( value , language ) {
903
+ if ( ! language ) {
904
+ if ( this . hass ?. locale ?. date_format === "language" ) {
905
+ language = this . hass . locale . language ;
906
+ } else {
907
+ language = undefined ;
908
+ }
909
+ }
910
+
911
+ return new Intl . DateTimeFormat ( language , {
920
912
year : "numeric" ,
921
- } ) ;
913
+ month : "numeric" ,
914
+ day : "numeric" ,
915
+ } ) . format ( value ) ;
922
916
}
923
917
924
- _getTimeString ( datetime ) {
925
- return new Date ( datetime ) . toLocaleTimeString ( this . lang , {
926
- hour : "2-digit" ,
927
- minute : "2-digit" ,
928
- hour12 : false ,
929
- } ) ;
930
- }
918
+ _formatNumber ( value , language ) {
919
+ if ( ! language ) {
920
+ if ( this . hass ?. locale ?. number_format === "language" ) {
921
+ language = this . hass . locale . language ;
922
+ } else {
923
+ language = undefined ;
924
+ }
925
+ }
931
926
932
- _getFixedFloat ( number ) {
933
- return parseFloat ( number ) . toFixed ( 5 ) ;
927
+ return new Intl . NumberFormat ( language , {
928
+ maximumFractionDigits : 5 ,
929
+ minimumFractionDigits : 5 ,
930
+ } ) . format ( value ) ;
934
931
}
935
932
936
- _getCategoryHour ( hours ) {
937
- const padHours = this . _getPadStartNumber ( hours ) ;
933
+ _formatHour ( index ) {
934
+ const padHours = this . _getPadStartNumber ( index ) ;
938
935
return `${ padHours } :00` ;
939
936
}
940
937
0 commit comments