@@ -219,8 +219,8 @@ class B2500DCard extends LitElement {
219219 right:0; left:auto;
220220 background: rgb(84, 158,164);
221221 }
222- .barlabels{ display:flex; justify-content:space-between ; margin-top:8px; font-weight:400; color: #549EA4; }
223- .barlabels .hint{ color: #549EA4; font-weight:400; font-size:12px; margin-top:2px }
222+ .barlabels{ display:flex; justify-content:space-around ; margin-top:8px; font-weight:400; color: #549EA4; align-items: center ; }
223+ .barlabels .hint{ color: #549EA4; font-weight:400; font-size:12px; margin-top:2px; }
224224
225225 .battery{
226226 display:flex; align-items:center; justify-content:center; padding:10px 0 4px;
@@ -384,6 +384,7 @@ class B2500DCard extends LitElement {
384384 settings : true ,
385385 solar : true ,
386386 compact : false ,
387+ icon : true ,
387388 ...config
388389 } ;
389390 if ( this . _hass ) {
@@ -533,7 +534,7 @@ class B2500DCard extends LitElement {
533534 const date = new Date ( isoString ) ;
534535
535536 const year = date . getFullYear ( ) ;
536- const month = String ( date . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ; // Monate 0-11
537+ const month = String ( date . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
537538 const day = String ( date . getDate ( ) ) . padStart ( 2 , '0' ) ;
538539 const hour = String ( date . getHours ( ) ) . padStart ( 2 , '0' ) ;
539540 const minute = String ( date . getMinutes ( ) ) . padStart ( 2 , '0' ) ;
@@ -544,40 +545,20 @@ class B2500DCard extends LitElement {
544545
545546
546547
547- render ( ) {
548- if ( this . _configError ) {
549- return html `< ha-alert alert-type ="error "> ${ this . _configError } </ ha-alert > ` ;
550- }
551-
552- const solar = Number ( this . _solarPower ) ;
553- const output = Number ( this . _outputPower ) ;
548+ //RENDER COMPACT
549+ _renderCompact ( batteryClass ) {
550+ const percent = this . _batteryPercent ?? 0 ;
554551
555- const lang = this . _hass ?. language || "en" ;
556- const batteryClass = solar > output && this . _batteryPercent < 100
557- ? 'charging'
558- : output > solar && this . _batteryPercent > 0
559- ? 'discharging'
560- : '' ;
561-
562-
563-
564- if ( this . config . compact ) {
565- const percent = this . _batteryPercent ?? 0 ;
566-
567- // Farbe bestimmen
568552 let color = "green" ;
569553 if ( percent <= 19 ) {
570554 color = "red" ;
571555 } else if ( percent <= 59 ) {
572556 color = "orange" ;
573557 }
574- // Icon abhängig vom Prozentwert wählen (auf nächste 10 abrunden)
575558 let icon = "" ;
576559 if ( percent >= 100 ) {
577- // Sonderfall: 100% hat eigenes Icon
578560 icon = "mdi:battery" ;
579561 } else if ( percent < 10 ) {
580- // Unter 10% gibt es nur die Outline-Version
581562 icon = "mdi:battery-outline" ;
582563 } else {
583564 let level = Math . floor ( percent / 10 ) * 10 ;
@@ -614,14 +595,52 @@ class B2500DCard extends LitElement {
614595 </ div >
615596 </ div >
616597 ` ;
598+ }
599+
600+ //RENDER UNIT
601+ _renderUnit ( batteryClass ) {
602+ return html `
603+ < div class ="unit ">
604+ < div class ="battery-bar ">
605+ < div class ="battery-fill ${ batteryClass } " style ="height:${ Math . min ( this . _batteryPercent , 98 ) } % "> </ div >
606+ </ div >
607+ </ div >
608+ `
609+ }
610+
611+
612+ /////////////////
613+ // RENDER
614+ /////////////////
615+ render ( ) {
616+ if ( this . _configError ) {
617+ return html `< ha-alert alert-type ="error "> ${ this . _configError } </ ha-alert > ` ;
618+ }
619+
620+ const solar = Number ( this . _solarPower ) ;
621+ const output = Number ( this . _outputPower ) ;
622+
623+ const lang = this . _hass ?. language || "en" ;
624+ const batteryClass = solar > output && this . _batteryPercent < 100
625+ ? 'charging'
626+ : output > solar && this . _batteryPercent > 0
627+ ? 'discharging'
628+ : '' ;
629+
630+ if ( this . config . compact ) {
631+ return this . _renderCompact ( batteryClass ) ;
617632 }
618633
619634 // Fallback: 600 wenn nix übergeben (standard beim b2500d)
620635 const maxInputPower = this . config . max_input_power || 600 ;
636+ const maxInputPower2 = this . config . max_input_power2 || 600 ;
637+ const maxInputPower3 = this . config . max_input_power3 || 600 ;
638+ const maxInputPower4 = this . config . max_input_power4 || 600 ;
639+
621640 const p1Pct = Math . round ( ( this . _p1 / maxInputPower ) * 100 ) ;
622- const p2Pct = Math . round ( ( this . _p2 / maxInputPower ) * 100 ) ;
623- const p3Pct = Math . round ( ( this . _p3 / maxInputPower ) * 100 ) ;
624- const p4Pct = Math . round ( ( this . _p4 / maxInputPower ) * 100 ) ;
641+ const p2Pct = Math . round ( ( this . _p2 / maxInputPower2 ) * 100 ) ;
642+ const p3Pct = Math . round ( ( this . _p3 / maxInputPower3 ) * 100 ) ;
643+ const p4Pct = Math . round ( ( this . _p4 / maxInputPower4 ) * 100 ) ;
625644
626645
627646 const selectEntity = this . _hass . states [ `select.${ this . config . device } _charging_mode` ] ;
@@ -642,11 +661,7 @@ class B2500DCard extends LitElement {
642661 </ div >
643662
644663 <!-- Unit mit Akku-Balken -->
645- < div class ="unit ">
646- < div class ="battery-bar ">
647- < div class ="battery-fill ${ batteryClass } " style ="height:${ Math . min ( this . _batteryPercent , 98 ) } % "> </ div >
648- </ div >
649- </ div >
664+ ${ this . config . icon ? this . _renderUnit ( batteryClass ) :"" }
650665 </ div >
651666
652667 < section class ="grid ">
@@ -667,9 +682,9 @@ class B2500DCard extends LitElement {
667682 < div class ="barwrap ">
668683 < div class ="bar "> < div class ="fill " style ="width:${ p1Pct } % "> </ div > </ div >
669684 < div class ="bar ${ this . _p3 == null && this . _p4 == null ? "r" : "" } "> < div class ="fill " style ="width:${ p2Pct } % "> </ div > </ div >
670- ${ this . _p3 != null ? html `< div class ="bar r "> < div class ="fill " style ="width:${ p3Pct } % "> </ div > </ div > `
685+ ${ this . _p3 != null ? html `< div class ="bar "> < div class ="fill " style ="width:${ p3Pct } % "> </ div > </ div > `
671686 : "" }
672- ${ this . _p4 != null ? html `< div class ="bar r "> < div class ="fill " style ="width:${ p4Pct } % "> </ div > </ div > `
687+ ${ this . _p4 != null ? html `< div class ="bar "> < div class ="fill " style ="width:${ p4Pct } % "> </ div > </ div > `
673688 : "" }
674689 </ div >
675690 < div class ="barlabels ">
@@ -832,7 +847,7 @@ class B2500DCard extends LitElement {
832847 ? html `< div class ="divider "> </ div > `
833848 : html `` ;
834849
835- // Switch
850+
836851 if ( entity . entity_id . startsWith ( "switch." ) ) {
837852 return html `
838853 < div class ="row ">
@@ -854,7 +869,7 @@ class B2500DCard extends LitElement {
854869 ` ;
855870 }
856871
857- // Select
872+
858873 if ( entity . entity_id . startsWith ( "select." ) ) {
859874 return html `
860875 < div class ="row ">
@@ -882,7 +897,6 @@ class B2500DCard extends LitElement {
882897 ` ;
883898 }
884899
885- // Fallback (read-only)
886900 return html `
887901 < div class ="row ">
888902 < div class ="left ">
@@ -927,15 +941,18 @@ class B2500DCardEditor extends LitElement {
927941
928942
929943 setConfig ( config ) {
930- // Defaults behalten, damit Felder sichtbar sind
931944 this . _config = {
932945 output : true ,
933946 battery : true ,
934947 production : true ,
935948 settings : true ,
936949 solar : true ,
950+ icon : true ,
937951 compact : false ,
938952 max_input_power : 600 ,
953+ max_input_power2 : 600 ,
954+ max_input_power3 : 600 ,
955+ max_input_power4 : 600 ,
939956 entities : {
940957 battery_percentage : "" ,
941958 battery_capacity : "" ,
@@ -960,7 +977,6 @@ class B2500DCardEditor extends LitElement {
960977
961978 const newConfig = { ...ev . detail . value } ;
962979
963- // Wenn entities leer oder alle Werte leer, entfernen
964980 if ( newConfig . entities ) {
965981 const isEmpty = Object . values ( newConfig . entities ) . every (
966982 ( v ) => v === null || v === undefined || v === ""
@@ -1028,13 +1044,16 @@ class B2500DCardEditor extends LitElement {
10281044 } ,
10291045 } ,
10301046 { name : "compact" , selector : { boolean : { } } } ,
1047+ { name : "icon" , selector : { boolean : { } } } ,
10311048 { name : "solar" , selector : { boolean : { } } } ,
10321049 { name : "output" , selector : { boolean : { } } } ,
10331050 { name : "battery" , selector : { boolean : { } } } ,
10341051 { name : "production" , selector : { boolean : { } } } ,
10351052 { name : "settings" , selector : { boolean : { } } } ,
1036- { name : "max_input_power" , selector : { number : { min : 100 , max : 5000 , step : 50 } } ,
1037- } ,
1053+ { name : "max_input_power" , selector : { number : { min : 100 , max : 5000 , step : 50 } } } ,
1054+ { name : "max_input_power2" , selector : { number : { min : 100 , max : 5000 , step : 50 } } } ,
1055+ { name : "max_input_power3" , selector : { number : { min : 100 , max : 5000 , step : 50 } } } ,
1056+ { name : "max_input_power4" , selector : { number : { min : 100 , max : 5000 , step : 50 } } } ,
10381057 ] ;
10391058
10401059 return html `
@@ -1060,4 +1079,4 @@ window.customCards.push({
10601079 preview : false ,
10611080 description : "Visualizing solar storage systems" ,
10621081
1063- } ) ;
1082+ } ) ;
0 commit comments