@@ -9,7 +9,7 @@ const languages = { en, de, es, fr };
99
1010function _getLangCode ( langInput ) {
1111 const raw = ( langInput || ( typeof navigator !== "undefined" && navigator . language ) || "en" ) . toString ( ) . toLowerCase ( ) ;
12- return raw . split ( / [ _ - ] / ) [ 0 ] ;
12+ return raw . split ( / [ _ - ] / ) [ 0 ] ;
1313}
1414
1515function localize ( key , langInput ) {
@@ -387,6 +387,27 @@ class B2500DCard extends LitElement {
387387 throw new Error ( localize ( "errors.missing" , this . _hass ?. language ) ) ;
388388 }
389389
390+
391+ if ( entities ) {
392+ // Nur die relevanten Keys p1–p4 prüfen
393+ const powerKeys = [ "p1_power" , "p2_power" , "p3_power" , "p4_power" ]
394+ . filter ( k => entities [ k ] !== undefined ) ;
395+
396+ const valid2 =
397+ powerKeys . length === 2 &&
398+ powerKeys . includes ( "p1_power" ) &&
399+ powerKeys . includes ( "p2_power" ) ;
400+
401+ const valid4 =
402+ powerKeys . length === 4 &&
403+ [ "p1_power" , "p2_power" , "p3_power" , "p4_power" ] . every ( k =>
404+ powerKeys . includes ( k )
405+ ) ;
406+
407+ if ( ! valid2 && ! valid4 ) {
408+ throw new Error ( localize ( "errors.entities_invalid" , this . _hass ?. language ) ) ;
409+ }
410+ }
390411 this . config = {
391412 output : true ,
392413 battery : true ,
@@ -439,6 +460,13 @@ class B2500DCard extends LitElement {
439460 this . _solarPower = Number ( this . _hass . states [ e . solar_power ] ?. state ) || 0 ;
440461 this . _p1 = Number ( this . _hass . states [ e . p1_power ] ?. state ) || 0 ;
441462 this . _p2 = Number ( this . _hass . states [ e . p2_power ] ?. state ) || 0 ;
463+ this . _p3 = this . _hass . states [ e . p3_power ] ?. state !== undefined
464+ ? Number ( this . _hass . states [ e . p3_power ] . state )
465+ : null ;
466+
467+ this . _p4 = this . _hass . states [ e . p4_power ] ?. state !== undefined
468+ ? Number ( this . _hass . states [ e . p4_power ] . state )
469+ : null ;
442470 this . _outputPower = Number ( this . _hass . states [ e . output_power ] ?. state ) || 0 ;
443471 this . _batteryPercent = Number ( this . _hass . states [ e . battery_percentage ] ?. state ) || 0 ;
444472
@@ -472,6 +500,8 @@ class B2500DCard extends LitElement {
472500 total_input_power : "solar_power" ,
473501 input_1_power : "p1_power" ,
474502 input_2_power : "p2_power" ,
503+ input_3_power : "p3_power" ,
504+ input_4_power : "p4_power" ,
475505 total_output_power : "output_power" ,
476506 } ;
477507
@@ -576,12 +606,15 @@ class B2500DCard extends LitElement {
576606 const maxInputPower = this . config . max_input_power || 600 ;
577607 const p1Pct = Math . round ( ( this . _p1 / maxInputPower ) * 100 ) ;
578608 const p2Pct = Math . round ( ( this . _p2 / maxInputPower ) * 100 ) ;
609+ const p3Pct = Math . round ( ( this . _p3 / maxInputPower ) * 100 ) ;
610+ const p4Pct = Math . round ( ( this . _p4 / maxInputPower ) * 100 ) ;
611+
579612
580613 const selectEntity = this . _hass . states [ `select.${ this . config . device } _charging_mode` ] ;
581614 const switchEntity = this . _hass . states [ `switch.${ this . config . device } _adaptive_mode` ] ;
582615
583616
584- return html `
617+ return html `
585618 < div class ="container ">
586619 < div class ="device ">
587620 <!-- Header -->
@@ -614,15 +647,24 @@ class B2500DCard extends LitElement {
614647 < div class ="barlabels ">
615648 < div > ${ this . _p1 } W</ div >
616649 < div > ${ this . _p2 } W</ div >
650+ ${ this . _p3 != null ? html `< div > ${ this . _p3 } W</ div > ` : "" }
651+ ${ this . _p4 != null ? html `< div > ${ this . _p4 } W</ div > ` : "" }
617652 </ div >
618653 < div class ="barwrap ">
619- < div class ="bar p1 "> < div class ="fill " style ="width:${ p1Pct } % "> </ div > </ div >
620- < div class ="bar p2 r "> < div class ="fill " style ="width:${ p2Pct } % "> </ div > </ div >
654+ < div class ="bar "> < div class ="fill " style ="width:${ p1Pct } % "> </ div > </ div >
655+ < div class ="bar ${ this . _p3 == null && this . _p4 == null ? "r" : "" } "> < div class ="fill " style ="width:${ p2Pct } % "> </ div > </ div >
656+ ${ this . _p3 != null ? html `< div class ="bar r "> < div class ="fill " style ="width:${ p3Pct } % "> </ div > </ div > `
657+ : "" }
658+ ${ this . _p4 != null ? html `< div class ="bar r "> < div class ="fill " style ="width:${ p4Pct } % "> </ div > </ div > `
659+ : "" }
621660 </ div >
622661 < div class ="barlabels ">
623662 < div class ="hint "> P1</ div >
624663 < div class ="hint "> P2</ div >
664+ ${ this . _p3 != null ? html `< div class ="hint "> P3</ div > ` : "" }
665+ ${ this . _p4 != null ? html `< div class ="hint "> P4</ div > ` : "" }
625666 </ div >
667+
626668 </ div >
627669 < div class ="icon "> < ha-icon icon ="mdi:solar-power-variant-outline "> </ ha-icon > ︎</ div >
628670 </ article > ` : '' }
0 commit comments