From 6bea1ae0a13b87ec85fe96278446770018f6bcd2 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Sat, 5 Oct 2024 22:21:58 +0000 Subject: [PATCH] 76_SolarForecast: contrib 1.34.2 git-svn-id: https://svn.fhem.de/fhem/trunk@29201 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/DS_Starter/76_SolarForecast.pm | 80 ++++++++++++++++----- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/fhem/contrib/DS_Starter/76_SolarForecast.pm b/fhem/contrib/DS_Starter/76_SolarForecast.pm index 6ada85dbc..c223b7a8d 100644 --- a/fhem/contrib/DS_Starter/76_SolarForecast.pm +++ b/fhem/contrib/DS_Starter/76_SolarForecast.pm @@ -157,7 +157,7 @@ BEGIN { # Versions History intern my %vNotesIntern = ( "1.34.2" => "05.10.2024 _flowGraphic: replace sun by FHEM SVG-Icon, sun or icon of moon phases according day/night ". - "new optional key 'icon' in attr setupInverterDev ", + "new optional key 'icon' in attr setupInverterDev, resize all icons to a standard scaling ", "1.34.1" => "04.10.2024 _flowGraphic: replace house by FHEM SVG-Icon ", "1.34.0" => "03.10.2024 implement ___areaFactorTrack for calculation of direct area factor and share of direct radiation ". "note in Reading pvCorrectionFactor_XX if AI prediction was used in relevant hour ". @@ -13969,6 +13969,7 @@ sub _flowGraphic { my $soc = ReadingsNum ($name, 'Current_BatCharge', 100); my $cc_dummy = $cc; + my $scale = 0.10; # default Scale my $hasbat = 1; # initial Batterie vorhanden my $flowgprods = 1; # Producer in der Energieflußgrafik anzeigen per default my $ppcurr = {}; # Hashref Producer current power @@ -14104,12 +14105,15 @@ END0 my ($picon) = __substituteIcon ( { hash => $hash, # Icon des Producerdevices name => $name, pn => $prnxnum, - pcurr => $ppcurr->{$prnxnum} + pcurr => $ppcurr->{$prnxnum}, + lang => $lang } ); - $ret .= ''; - $ret .= "$palias".FW_makeImage($picon, ''); + $picon = FW_makeImage ($picon, ''); + $scale = __normIconScale ($name, $picon); + $ret .= qq{}; + $ret .= "$palias".$picon; $ret .= ' '; $pos_left += $consDist; @@ -14133,14 +14137,22 @@ END0 $pos_left = $consumer_start + 15; for my $c (@consumers) { - my $calias = ConsumerVal ($hash, $c, "alias", ""); # Name des Consumerdevices + my $calias = ConsumerVal ($hash, $c, "alias", ""); # Name des Consumerdevices $currentPower = $cpcurr->{$c}; - my ($cicon) = __substituteIcon ({hash => $hash, name => $name, cn => $c, pcurr => $currentPower}); # Icon des Consumerdevices + my ($cicon) = __substituteIcon ( { hash => $hash, # Icon des Consumerdevices + name => $name, + cn => $c, + pcurr => $currentPower, + lang => $lang + } + ); $cc_dummy -= $currentPower; - $ret .= ''; - $ret .= "$calias".FW_makeImage($cicon, ''); - $ret .= ' '; + $cicon = FW_makeImage ($cicon, ''); + $scale = __normIconScale ($name, $cicon); + $ret .= qq{}; + $ret .= "$calias".$cicon; + $ret .= ' '; $pos_left += $consDist; } @@ -14151,14 +14163,17 @@ END0 my ($smicon, $smtxt) = __substituteIcon ( { hash => $hash, name => $name, in => '01', - don => NexthoursVal ($hash, 'NextHour00', 'DoN', 0), # Tag oder Nacht - pcurr => $cpv + don => NexthoursVal ($hash, 'NextHour00', 'DoN', 0), # Tag oder Nacht + pcurr => $cpv, + lang => $lang } ); - $ret .= ''; # translate(X-Koordinate,Y-Koordinate), scale()-> Koordinaten ändern sich bei Größenänderung - $ret .= "$smtxt".FW_makeImage($smicon, ''); - $ret .= ' '; + $smicon = FW_makeImage ($smicon, ''); + $scale = __normIconScale ($name, $smicon); + $ret .= qq{}; # translate(X-Koordinate,Y-Koordinate), scale()-> Koordinaten ändern sich bei Größenänderung + $ret .= "$smtxt".$smicon; + $ret .= ' '; ## Batterie Icon ################## @@ -14178,8 +14193,10 @@ END1 ## Home Icon ############## - $ret .= ''; # translate(X-Koordinate,Y-Koordinate), scale()-> Koordinaten ändern sich bei Größenänderung - $ret .= "Home".FW_makeImage($homeicondef, ''); + my $hicon = FW_makeImage ($homeicondef, ''); + $scale = __normIconScale ($name, $hicon); + $ret .= qq{}; # translate(X-Koordinate,Y-Koordinate), scale()-> Koordinaten ändern sich bei Größenänderung + $ret .= "Home".$hicon; $ret .= ' '; ## Dummy Consumer Icon @@ -14187,8 +14204,10 @@ END1 if ($flowgconX) { my $dumtxt = $htitles{dumtxt}{$lang}; my $dumcol = $cc_dummy <= 0 ? '@grey' : q{}; # Einfärbung Consumer Dummy - $ret .= ''; - $ret .= "$dumtxt".FW_makeImage($cicondef.$dumcol, ''); + my $dicon = FW_makeImage ($cicondef.$dumcol, ''); + $scale = __normIconScale ($name, $dicon); + $ret .= qq{}; + $ret .= "$dumtxt".$dicon; $ret .= ' '; } @@ -14484,6 +14503,31 @@ sub __substituteIcon { return ($icon, $txt); } +################################################################ +# berechne Icon Scale auf Bezugsnorm +# widht: 470pt +# height: 470pt +# scale: 0.10 +################################################################ +sub __normIconScale { + my $name = shift; + my $icon = shift; + + my $scale = 0.10; # default Scale + my ($height, $unit) = $icon =~ /height="(\d+\.\d+|\d+)(.*?)"/xs; + + return $scale if(!$height); + + my $scale = $unit eq 'pt' ? 470 * $scale /$height : + $unit eq 'px' ? 470 * $scale /$height * 0.96 : + $unit eq 'in' ? 470 * $scale /$height * 0.0138889 : + $scale; + + $scale = sprintf "%.2f", $scale; + +return $scale; +} + ################################################################ # Inject consumer icon ################################################################