2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-22 08:11:44 +00:00

02_RSS: tweaked warnings/logging

git-svn-id: https://svn.fhem.de/fhem/trunk@7200 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2014-12-14 08:47:29 +00:00
parent c6d8f0fdcb
commit 1938f8e007

View File

@ -33,6 +33,9 @@ my @valid_halign = qw(left center right justified);
# use vars qw(%FW_pos); # scroll position # use vars qw(%FW_pos); # scroll position
# use vars qw($FW_cname); # Current connection name # use vars qw($FW_cname); # Current connection name
# http://blogs.perl.org/users/mike_b/2013/06/a-little-nicer-way-to-use-smartmatch-on-perl-518.html
no if $] >= 5.017011, warnings => 'experimental::smartmatch';
######################### #########################
sub sub
RSS_addExtension($$$) { RSS_addExtension($$$) {
@ -42,7 +45,7 @@ RSS_addExtension($$$) {
$data{FWEXT}{$url}{FUNC} = $func; $data{FWEXT}{$url}{FUNC} = $func;
$data{FWEXT}{$url}{LINK} = $link; $data{FWEXT}{$url}{LINK} = $link;
$data{FWEXT}{$url}{NAME} = $friendlyname; $data{FWEXT}{$url}{NAME} = $friendlyname;
#$data{FWEXT}{$url}{FORKABLE} = 1; $data{FWEXT}{$url}{FORKABLE} = 0;
} }
################## ##################
@ -59,6 +62,7 @@ RSS_Initialize($) {
return undef; return undef;
} }
################## ##################
sub sub
RSS_readLayout($) { RSS_readLayout($) {
@ -100,13 +104,13 @@ RSS_Define($$) {
eval "use GD::Text::Align"; eval "use GD::Text::Align";
$hash->{fhem}{useTextAlign} = ($@ ? 0 : 1 ); $hash->{fhem}{useTextAlign} = ($@ ? 0 : 1 );
if(!($hash->{fhem}{useTextAlign})) { if(!($hash->{fhem}{useTextAlign})) {
Log3 $hash, 1, "Cannot use text alignment: $@"; Log3 $hash, 2, "$name: Cannot use text alignment: $@";
} }
eval "use GD::Text::Wrap"; eval "use GD::Text::Wrap";
$hash->{fhem}{useTextWrap} = ($@ ? 0 : 1 ); $hash->{fhem}{useTextWrap} = ($@ ? 0 : 1 );
if(!($hash->{fhem}{useTextWrap})) { if(!($hash->{fhem}{useTextWrap})) {
Log3 $hash, 1, "Cannot use text wrapping: $@"; Log3 $hash, 2, "$name: Cannot use text wrapping: $@";
} }
RSS_readLayout($hash); RSS_readLayout($hash);
@ -506,106 +510,112 @@ RSS_evalLayout($$@) {
#Debug "before command $line: x= " . $params{x} . ", y= " . $params{y}; #Debug "before command $line: x= " . $params{x} . ", y= " . $params{y};
if($cmd eq "rgb") { eval {
$def= "\"$def\"" if(length($def) == 6 && $def =~ /[[:xdigit:]]{6}/); if($cmd eq "rgb") {
$params{rgb}= AnalyzePerlCommand(undef, $def); $def= "\"$def\"" if(length($def) == 6 && $def =~ /[[:xdigit:]]{6}/);
} elsif($cmd eq "font") { $params{rgb}= AnalyzePerlCommand(undef, $def);
$params{font}= $def; } elsif($cmd eq "font") {
} elsif($cmd eq "pt") { $params{font}= $def;
$def= AnalyzePerlCommand(undef, $def); } elsif($cmd eq "pt") {
if($def =~ m/^[+-]/) { $def= AnalyzePerlCommand(undef, $def);
$params{pt} += $def; if($def =~ m/^[+-]/) {
} else { $params{pt} += $def;
$params{pt} = $def; } else {
} $params{pt} = $def;
$params{pt} = 6 if($params{pt} < 0); }
} elsif($cmd eq "moveto") { $params{pt} = 6 if($params{pt} < 0);
my ($tox,$toy)= split('[ \t]+', $def, 2); } elsif($cmd eq "moveto") {
my ($x,$y)= RSS_xy($S, $tox,$toy,%params); my ($tox,$toy)= split('[ \t]+', $def, 2);
$params{x} = $x; my ($x,$y)= RSS_xy($S, $tox,$toy,%params);
$params{y} = $y; $params{x} = $x;
} elsif($cmd eq "moveby") { $params{y} = $y;
my ($byx,$byy)= split('[ \t]+', $def, 2); } elsif($cmd eq "moveby") {
my ($x,$y)= RSS_xy($S, $byx,$byy,%params); my ($byx,$byy)= split('[ \t]+', $def, 2);
$params{x} += $x; my ($x,$y)= RSS_xy($S, $byx,$byy,%params);
$params{y} += $y; $params{x} += $x;
} elsif($cmd ~~ @cmd_halign) { $params{y} += $y;
my $d = AnalyzePerlCommand(undef, $def); } elsif($cmd ~~ @cmd_halign) {
if($d ~~ @valid_halign) { my $d = AnalyzePerlCommand(undef, $def);
$params{ihalign}= $d unless($cmd eq "thalign"); if($d ~~ @valid_halign) {
$params{thalign}= $d unless($cmd eq "ihalign"); $params{ihalign}= $d unless($cmd eq "thalign");
} else { $params{thalign}= $d unless($cmd eq "ihalign");
Log3 $name, 2, "$name: Illegal horizontal alignment $d"; } else {
} Log3 $name, 2, "$name: Illegal horizontal alignment $d";
} elsif($cmd ~~ @cmd_valign) { }
my $d = AnalyzePerlCommand(undef, $def); } elsif($cmd ~~ @cmd_valign) {
if( $d ~~ @valid_valign) { my $d = AnalyzePerlCommand(undef, $def);
$params{ivalign}= $d unless($cmd eq "tvalign"); if( $d ~~ @valid_valign) {
$params{tvalign}= $d unless($cmd eq "ivalign"); $params{ivalign}= $d unless($cmd eq "tvalign");
} else { $params{tvalign}= $d unless($cmd eq "ivalign");
Log3 $name, 2, "$name: Illegal vertical alignment $d"; } else {
} Log3 $name, 2, "$name: Illegal vertical alignment $d";
} elsif($cmd eq "linespace") { }
$params{linespace}= $def; } elsif($cmd eq "linespace") {
} elsif($cmd eq "text") { $params{linespace}= $def;
($x,$y,$text)= split("[ \t]+", $def, 3); } elsif($cmd eq "text") {
($x,$y)= RSS_xy($S, $x,$y,%params); ($x,$y,$text)= split("[ \t]+", $def, 3);
$params{x} = $x; ($x,$y)= RSS_xy($S, $x,$y,%params);
$params{y} = $y; $params{x} = $x;
my $txt= AnalyzePerlCommand(undef, $text); $params{y} = $y;
#Debug "$name: ($x,$y) $txt"; my $txt= AnalyzePerlCommand(undef, $text);
RSS_itemText($S,$x,$y,$txt,%params); #Debug "$name: ($x,$y) $txt";
} elsif($cmd eq "textbox") { RSS_itemText($S,$x,$y,$txt,%params);
($x,$y,$boxwidth,$text)= split("[ \t]+", $def, 4); } elsif($cmd eq "textbox") {
($x,$y)= RSS_xy($S, $x,$y,%params); ($x,$y,$boxwidth,$text)= split("[ \t]+", $def, 4);
my $txt= AnalyzePerlCommand(undef, $text); ($x,$y)= RSS_xy($S, $x,$y,%params);
#Debug "$name: ($x,$y) $txt"; my $txt= AnalyzePerlCommand(undef, $text);
$y= RSS_itemTextBox($S,$x,$y,$boxwidth,$txt,%params); #Debug "$name: ($x,$y) $txt";
$params{x} = $x; $y= RSS_itemTextBox($S,$x,$y,$boxwidth,$txt,%params);
$params{y} = $y; $params{x} = $x;
} elsif($cmd eq "line") { $params{y} = $y;
($x1,$y1,$x2,$y2,$format)= split("[ \t]+", $def, 5); } elsif($cmd eq "line") {
($x1,$y1)= RSS_xy($S, $x1,$y1,%params); ($x1,$y1,$x2,$y2,$format)= split("[ \t]+", $def, 5);
($x2,$y2)= RSS_xy($S, $x2,$y2,%params); ($x1,$y1)= RSS_xy($S, $x1,$y1,%params);
$format //= 1; # set format to 1 as default thickness for the line ($x2,$y2)= RSS_xy($S, $x2,$y2,%params);
RSS_itemLine($S,$x1,$y1,$x2,$y2, $format,%params); $format //= 1; # set format to 1 as default thickness for the line
} elsif($cmd eq "rect") { RSS_itemLine($S,$x1,$y1,$x2,$y2, $format,%params);
($x1,$y1,$x2,$y2,$format)= split("[ \t]+", $def, 5); } elsif($cmd eq "rect") {
($x1,$y1)= RSS_xy($S, $x1,$y1,%params); ($x1,$y1,$x2,$y2,$format)= split("[ \t]+", $def, 5);
($x2,$y2)= RSS_xy($S, $x2,$y2,%params); ($x1,$y1)= RSS_xy($S, $x1,$y1,%params);
$format //= 0; # set format to 0 as default (not filled) ($x2,$y2)= RSS_xy($S, $x2,$y2,%params);
RSS_itemRect($S,$x1,$y1,$x2,$y2, $format,%params); $format //= 0; # set format to 0 as default (not filled)
} elsif($cmd eq "time") { RSS_itemRect($S,$x1,$y1,$x2,$y2, $format,%params);
($x,$y)= split("[ \t]+", $def, 2); } elsif($cmd eq "time") {
($x,$y)= RSS_xy($S, $x,$y,%params); ($x,$y)= split("[ \t]+", $def, 2);
$params{x} = $x; ($x,$y)= RSS_xy($S, $x,$y,%params);
$params{y} = $y; $params{x} = $x;
RSS_itemTime($S,$x,$y,%params); $params{y} = $y;
} elsif($cmd eq "seconds") { RSS_itemTime($S,$x,$y,%params);
($x,$y,$format) = split("[ \+]", $def,3); } elsif($cmd eq "seconds") {
($x,$y)= RSS_xy($S, $x,$y,%params); ($x,$y,$format) = split("[ \+]", $def,3);
$params{x} = $x; ($x,$y)= RSS_xy($S, $x,$y,%params);
$params{y} = $y; $params{x} = $x;
RSS_itemSeconds($S,$x,$y,$format,%params); $params{y} = $y;
} elsif($cmd eq "date") { RSS_itemSeconds($S,$x,$y,$format,%params);
($x,$y)= split("[ \t]+", $def, 2); } elsif($cmd eq "date") {
($x,$y)= RSS_xy($S, $x,$y,%params); ($x,$y)= split("[ \t]+", $def, 2);
$params{x} = $x; ($x,$y)= RSS_xy($S, $x,$y,%params);
$params{y} = $y; $params{x} = $x;
RSS_itemDate($S,$x,$y,%params); $params{y} = $y;
} elsif($cmd eq "img") { RSS_itemDate($S,$x,$y,%params);
($x,$y,$scale,$imgtype,$srctype,$arg)= split("[ \t]+", $def,6); } elsif($cmd eq "img") {
($x,$y)= RSS_xy($S, $x,$y,%params); ($x,$y,$scale,$imgtype,$srctype,$arg)= split("[ \t]+", $def,6);
$params{x} = $x; ($x,$y)= RSS_xy($S, $x,$y,%params);
$params{y} = $y; $params{x} = $x;
my $arg= AnalyzePerlCommand(undef, $arg); $params{y} = $y;
RSS_itemImg($S,$x,$y,$scale,$imgtype,$srctype,$arg,%params); my $arg= AnalyzePerlCommand(undef, $arg);
} else { RSS_itemImg($S,$x,$y,$scale,$imgtype,$srctype,$arg,%params);
Log3 $name, 1, "$name: Illegal command $cmd in layout definition."; } else {
} Log3 $name, 2, "$name: Illegal command $cmd in layout definition.";
}
#Debug "after command $line: x= " . $params{x} . ", y= " . $params{y};
#Debug "after command $line: x= " . $params{x} . ", y= " . $params{y};
};
if($@) {
my $msg= "$name: Error from line \'$line\' in layout definition: $@";
chomp $msg;
Log3 $name, 2, $msg;
}
} }
} }
@ -631,7 +641,7 @@ RSS_returnIMG($$) {
# #
# create the image # create the image
# #
my $S; our $S;
# let's create a blank image, we will need it in most cases. # let's create a blank image, we will need it in most cases.
$S= GD::Image->newTrueColor($width,$height); $S= GD::Image->newTrueColor($width,$height);
my $bgcolor = AttrVal($name,'bgcolor','000000'); #default bg color = black my $bgcolor = AttrVal($name,'bgcolor','000000'); #default bg color = black
@ -641,7 +651,6 @@ RSS_returnIMG($$) {
# wrap to make problems with GD non-lethal # wrap to make problems with GD non-lethal
eval { eval {
# #
# set the background # set the background
# #
@ -701,11 +710,11 @@ RSS_returnIMG($$) {
} else { } else {
# size is as required # size is as required
# kill the predefined image and take the original # kill the predefined image and take the original
$S= undef; undef $S;
$S= $bg; $S= $bg;
} }
} else { } else {
$S= undef; undef $S;
$reason= "Something was wrong with background image \"$bgfile\"."; $reason= "Something was wrong with background image \"$bgfile\".";
} }
} }
@ -717,17 +726,24 @@ RSS_returnIMG($$) {
if(defined($S)) { if(defined($S)) {
RSS_evalLayout($S, $name, $defs{$name}{fhem}{layout}); RSS_evalLayout($S, $name, $defs{$name}{fhem}{layout});
} else { } else {
Log3 undef, 2, "$name: Could not create image. $reason"; Log3 $name, 2, "$name: Could not create image. $reason";
$S= GD::Image->newTrueColor($width,$height); # return empty image $S= GD::Image->newTrueColor($width,$height); # return empty image
} }
$defs{$name}{STATE} = localtime(); $defs{$name}{STATE} = localtime();
}; warn $@ if $@;
}; #warn $@ if $@;
if($@) {
my $msg= $@;
chomp $msg;
Log3 $name, 2, $msg;
}
# #
# return image # return image
# #
return ("image/jpeg; charset=utf-8", $S->jpeg) if $type eq 'jpg'; return ("image/jpeg; charset=utf-8", $S->jpeg) if($type eq 'jpg');
return ("image/png; charset=utf-8", $S->png) if $type eq 'png'; return ("image/png; charset=utf-8", $S->png) if($type eq 'png');
} }
################## ##################