2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-04 05:16:45 +00:00

98_DOIF.pm: improvements: card color gradient, DOIF_Readings, event_Readings: card data hash is now saved

git-svn-id: https://svn.fhem.de/fhem/trunk@26909 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Damian 2022-12-27 15:21:12 +00:00
parent 742ec12ac9
commit 5f3523098e

View File

@ -2825,6 +2825,20 @@ DOIF_Notify($$)
} }
} }
for my $attr ("DOIF_Readings","event_Readings") {
my $defs=AttrVal($pn, $attr, 0);
if ($defs) {
my ($def,$err)=addDOIF_Readings($hash,$defs,$attr);
if ($err) {
Log3 ($pn,3,"$pn: error in $def, $err") ;
} else {
foreach my $reading (keys %{$hash->{$attr}}) {
setDOIF_Reading ($hash,$reading,"",$attr,"","","");
}
}
}
}
if (AttrVal($pn,"initialize",0) and !AttrVal($pn,"disable",0)) { if (AttrVal($pn,"initialize",0) and !AttrVal($pn,"disable",0)) {
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate ($hash,"state",AttrVal($pn,"initialize",0)); readingsBulkUpdate ($hash,"state",AttrVal($pn,"initialize",0));
@ -2846,6 +2860,7 @@ DOIF_Notify($$)
} }
} }
my $startup=AttrVal($pn, "startup", 0); my $startup=AttrVal($pn, "startup", 0);
if ($startup and !AttrVal($pn,"disable",0)) { if ($startup and !AttrVal($pn,"disable",0)) {
$startup =~ s/\$SELF/$pn/g; $startup =~ s/\$SELF/$pn/g;
@ -3847,12 +3862,12 @@ DOIF_Attr(@)
delete ($defs{$hash->{NAME}}{READINGS}{waitsame}); delete ($defs{$hash->{NAME}}{READINGS}{waitsame});
@{$hash->{attr}{waitsame}}=SplitDoIf(':',$a[3]); @{$hash->{attr}{waitsame}}=SplitDoIf(':',$a[3]);
} elsif($a[0] eq "set" && ($a[2] eq "DOIF_Readings" or $a[2] eq "event_Readings")) { } elsif($a[0] eq "set" && ($a[2] eq "DOIF_Readings" or $a[2] eq "event_Readings")) {
my ($def,$err)=addDOIF_Readings($hash,$a[3],$a[2]); if ($init_done) {
if ($err) { my ($def,$err)=addDOIF_Readings($hash,$a[3],$a[2]);
$hs=$cur_hs; if ($err) {
return ("error in $a[2] $def, $err"); $hs=$cur_hs;
} else { return ("error in $a[2] $def, $err");
if ($init_done) { } else {
foreach my $reading (keys %{$hash->{$a[2]}}) { foreach my $reading (keys %{$hash->{$a[2]}}) {
setDOIF_Reading ($hash,$reading,"",$a[2],"","",""); setDOIF_Reading ($hash,$reading,"",$a[2],"","","");
} }
@ -4570,8 +4585,6 @@ sub footer {
} }
sub plot { sub plot {
my ($collect,$min_a,$max_a,$minColor,$maxColor,$dec,$func,$steps,$x_prop,$chart_dim,$noColor,$lmm,$ln,$lr,$plot,$bwidth,$footerPos,$fill,$pos,$anchor,$unitColor,$unit)=@_; my ($collect,$min_a,$max_a,$minColor,$maxColor,$dec,$func,$steps,$x_prop,$chart_dim,$noColor,$lmm,$ln,$lr,$plot,$bwidth,$footerPos,$fill,$pos,$anchor,$unitColor,$unit)=@_;
@ -4660,16 +4673,17 @@ sub plot {
$minVal=$value if (!defined $minVal); $minVal=$value if (!defined $minVal);
$maxVal=$value if (!defined $maxVal); $maxVal=$value if (!defined $maxVal);
my $opacity=0.5; my $opacity=0.4;
my $minopacity=0.05;
if ($minPlot < 0 and $maxPlot > 0) { if ($minPlot < 0 and $maxPlot > 0) {
$xpos=50-int($n*10)/10; $xpos=50-int($n*10)/10;
$topVal=($maxVal > 0 ? $maxVal : 0); $topVal=($maxVal > 0 ? $maxVal : 0);
$bottomVal=($minVal < 0 ? $minVal : 0); $bottomVal=($minVal < 0 ? $minVal : 0);
($nullColor)=get_color(0,$min,$max,$minColor,$maxColor,$func); ($nullColor)=get_color(0,$min,$max,$minColor,$maxColor,$func);
$nullProp=int ($topVal/($topVal-$bottomVal)*100)/100 if ($bottomVal<0 and $topVal>0); $nullProp=int ($topVal/($topVal-$bottomVal)*100)/100 if ($bottomVal<0 and $topVal>0);
$topOpacity=($topVal==0 ? 0 : $opacity); $topOpacity=($topVal==0 ? $minopacity : $opacity);
$bottomOpacity=($bottomVal==0 ? 0: $opacity); $bottomOpacity=($bottomVal==0 ? $minopacity: $opacity);
$nullOpacity=0.0; $nullOpacity=$minopacity;
} elsif ($maxPlot <= 0) { } elsif ($maxPlot <= 0) {
$xpos=0; $xpos=0;
$topVal=$maxPlot; $topVal=$maxPlot;
@ -4680,7 +4694,7 @@ sub plot {
$xpos=50; $xpos=50;
$topVal=$maxVal; $topVal=$maxVal;
$topOpacity=$opacity; $topOpacity=$opacity;
$bottomOpacity=0; $bottomOpacity=$minopacity;
$bottomVal=$minPlot; $bottomVal=$minPlot;
} }
@ -4754,14 +4768,14 @@ sub plot {
if (!defined $unitColor) { if (!defined $unitColor) {
$out.=sprintf('<path d="M%s,%s L',$chart_dim,$xpos); $out.=sprintf('<path d="M%s,%s L',$chart_dim,$xpos);
$out.= $points; $out.= $points;
$out.= sprintf('" style="fill:url(#gradplotLight_%s_%s_%s);stroke:url(#gradplot_%s_%s_%s);stroke-width:0.4" />',$topValColor,$bottomValColor,(defined $lr ? $lr:0),$topValColor,$bottomValColor,(defined $lr ? $lr:0)); $out.= sprintf('" style="fill:url(#gradplotLight_%s_%s_%s);stroke:url(#gradplot_%s_%s_%s);stroke-width:0.4;stroke-opacity:1" />',$topValColor,$bottomValColor,(defined $lr ? $lr:0),$topValColor,$bottomValColor,(defined $lr ? $lr:0));
} else { } else {
$out.=sprintf('<path d="M%s,%s L',$chart_dim,$xpos); $out.=sprintf('<path d="M%s,%s L',$chart_dim,$xpos);
$out.= $points; $out.= $points;
$out.= sprintf('" style="fill:url(#gradplotLight_%s);stroke:%s;stroke-width:0.5" />',$unitColor,$unitColor); $out.= sprintf('" style="fill:url(#gradplotLight_%s);stroke:%s;stroke-width:0.4;stroke-opacity:1" />',$unitColor,$unitColor);
} }
} }
$out.=sprintf('<polyline points="0,%s %s,%s" style="stroke:gray; stroke-width:0.2; stroke-opacity:1" />',$xpos,$chart_dim,$xpos); $out.=sprintf('<polyline points="0,%s %s,%s" style="stroke:gray; stroke-width:0.3; stroke-opacity:1" />',$xpos,$chart_dim,$xpos);
##$out.=sprintf('<circle cx="%s" cy="%s" r="2" fill="%s" opacity="0.7" />',$maxValSlot*$x_prop,(50-int((${$a}[$maxValSlot]*$m+$n)*10)/10),defined $unitColor ? $unitColor:color($maxValColor,$ln)) if (defined $maxValSlot); ##$out.=sprintf('<circle cx="%s" cy="%s" r="2" fill="%s" opacity="0.7" />',$maxValSlot*$x_prop,(50-int((${$a}[$maxValSlot]*$m+$n)*10)/10),defined $unitColor ? $unitColor:color($maxValColor,$ln)) if (defined $maxValSlot);
my ($x1,$y1)=($maxValSlot*$x_prop,(50-int((${$a}[$maxValSlot]*$m+$n)*10)/10)-2.3); my ($x1,$y1)=($maxValSlot*$x_prop,(50-int((${$a}[$maxValSlot]*$m+$n)*10)/10)-2.3);