mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-21 07:56:03 +00:00
98_weekprofile: improve error logging
git-svn-id: https://svn.fhem.de/fhem/trunk@15778 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5131482231
commit
2ff4cc0289
@ -10,7 +10,9 @@ package main;
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use JSON; #libjson-perl
|
|
||||||
|
use JSON; #libjson-perl
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
use vars qw(%defs);
|
use vars qw(%defs);
|
||||||
use vars qw($FW_ME);
|
use vars qw($FW_ME);
|
||||||
@ -278,7 +280,11 @@ sub weekprofile_sendDevProfile(@)
|
|||||||
|
|
||||||
if ($type eq "WEEKPROFILE") {
|
if ($type eq "WEEKPROFILE") {
|
||||||
my $json = JSON->new;
|
my $json = JSON->new;
|
||||||
my $json_text = $json->encode($prf->{DATA});
|
my $json_text = undef;
|
||||||
|
|
||||||
|
eval ( $json_text = $json->encode($prf->{DATA}) );
|
||||||
|
return "Error in profile data" if (!defined($json_text));
|
||||||
|
|
||||||
return fhem("set $device profile_data $prf->{TOPIC}:$prf->{NAME} $json_text",1);
|
return fhem("set $device profile_data $prf->{TOPIC}:$prf->{NAME} $json_text",1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +493,7 @@ sub weekprofile_updateReadings($)
|
|||||||
sub weekprofile_Initialize($)
|
sub weekprofile_Initialize($)
|
||||||
{
|
{
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
$hash->{DefFn} = "weekprofile_Define";
|
$hash->{DefFn} = "weekprofile_Define";
|
||||||
$hash->{SetFn} = "weekprofile_Set";
|
$hash->{SetFn} = "weekprofile_Set";
|
||||||
$hash->{GetFn} = "weekprofile_Get";
|
$hash->{GetFn} = "weekprofile_Get";
|
||||||
@ -547,6 +553,21 @@ sub sort_by_name
|
|||||||
return lc("$a->{TOPIC}:$a->{NAME}") cmp lc("$b->{TOPIC}:$b->{NAME}");
|
return lc("$a->{TOPIC}:$a->{NAME}") cmp lc("$b->{TOPIC}:$b->{NAME}");
|
||||||
}
|
}
|
||||||
##############################################
|
##############################################
|
||||||
|
sub dumpData($$$)
|
||||||
|
{
|
||||||
|
my ($hash,$prefix,$data) = @_;
|
||||||
|
|
||||||
|
my $me = $hash->{NAME};
|
||||||
|
my $dmp = Dumper($data);
|
||||||
|
|
||||||
|
$dmp =~ s/^\s+|\s+$//g; #trim whitespace both ends
|
||||||
|
if (AttrVal($me,"verbose",3) < 4) {
|
||||||
|
Log3 $me, 1, "$me$prefix - set verbose to 4 to see the data";
|
||||||
|
} else {
|
||||||
|
Log3 $me, 4, "$me$prefix $dmp";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
##############################################
|
||||||
sub weekprofile_Get($$@)
|
sub weekprofile_Get($$@)
|
||||||
{
|
{
|
||||||
my ($hash, $name, $cmd, @params) = @_;
|
my ($hash, $name, $cmd, @params) = @_;
|
||||||
@ -578,7 +599,11 @@ sub weekprofile_Get($$@)
|
|||||||
return "profile $params[0] has no data" if (!defined($prf->{DATA}));
|
return "profile $params[0] has no data" if (!defined($prf->{DATA}));
|
||||||
|
|
||||||
my $json = JSON->new;
|
my $json = JSON->new;
|
||||||
my $json_text = $json->encode($prf->{DATA});
|
my $json_text = undef;
|
||||||
|
|
||||||
|
eval { $json_text = $json->encode($prf->{DATA}) };
|
||||||
|
dumpData($hash,"(Get): invalid profile data",$prf->{DATA}) if (!defined($json_text));
|
||||||
|
|
||||||
return $json_text;
|
return $json_text;
|
||||||
}
|
}
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
@ -638,7 +663,9 @@ sub weekprofile_Get($$@)
|
|||||||
if($cmd eq "sndDevList") {
|
if($cmd eq "sndDevList") {
|
||||||
my $json = JSON->new;
|
my $json = JSON->new;
|
||||||
my @sortDevList = sort {lc($a->{ALIAS}) cmp lc($b->{ALIAS})} @{$hash->{SNDDEVLIST}};
|
my @sortDevList = sort {lc($a->{ALIAS}) cmp lc($b->{ALIAS})} @{$hash->{SNDDEVLIST}};
|
||||||
my $json_text = $json->encode(\@sortDevList);
|
my $json_text = undef;
|
||||||
|
eval { $json_text = $json->encode(\@sortDevList) };
|
||||||
|
dumpData($hash,"(Get): invalid device list",\@sortDevList) if (!defined($json_text));
|
||||||
return $json_text;
|
return $json_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -718,8 +745,9 @@ sub weekprofile_Set($$@)
|
|||||||
|
|
||||||
my $json = JSON->new;
|
my $json = JSON->new;
|
||||||
my $data = undef;
|
my $data = undef;
|
||||||
|
|
||||||
eval { $data = $json->decode($jsonData); };
|
eval { $data = $json->decode($jsonData); };
|
||||||
if ($@) {
|
if (!defined($data)) {
|
||||||
Log3 $me, 1, "$me(Set): Error parsing profile data.";
|
Log3 $me, 1, "$me(Set): Error parsing profile data.";
|
||||||
return "Error parsing profile data. No valid json format";
|
return "Error parsing profile data. No valid json format";
|
||||||
};
|
};
|
||||||
@ -983,6 +1011,8 @@ sub weekprofile_Attr($$$)
|
|||||||
|
|
||||||
my $hash = $defs{$me};
|
my $hash = $defs{$me};
|
||||||
|
|
||||||
|
return if (!defined($attrVal));
|
||||||
|
|
||||||
Log3 $me, 5, "$me(weekprofile_Attr): $cmd, $attrName, $attrVal";
|
Log3 $me, 5, "$me(weekprofile_Attr): $cmd, $attrName, $attrVal";
|
||||||
|
|
||||||
$attr{$me}{$attrName} = $attrVal;
|
$attr{$me}{$attrName} = $attrVal;
|
||||||
@ -1066,7 +1096,7 @@ sub weekprofile_readProfilesFromFile(@)
|
|||||||
if (!$version || $version < 1.1) {
|
if (!$version || $version < 1.1) {
|
||||||
my $prfData=undef;
|
my $prfData=undef;
|
||||||
eval { $prfData = $json->decode($data[1]); };
|
eval { $prfData = $json->decode($data[1]); };
|
||||||
if ($@) {
|
if (!defined($prfData)) {
|
||||||
Log3 $me, 1, "$me(readProfilesFromFile): Error parsing profile data $data[1]";
|
Log3 $me, 1, "$me(readProfilesFromFile): Error parsing profile data $data[1]";
|
||||||
next;
|
next;
|
||||||
};
|
};
|
||||||
@ -1086,7 +1116,7 @@ sub weekprofile_readProfilesFromFile(@)
|
|||||||
elsif ($version = 1.1) {
|
elsif ($version = 1.1) {
|
||||||
my $prfNew=undef;
|
my $prfNew=undef;
|
||||||
eval { $prfNew = $json->decode($data[1]); };
|
eval { $prfNew = $json->decode($data[1]); };
|
||||||
if ($@) {
|
if (!defined($prfNew)) {
|
||||||
Log3 $me, 1, "$me(readProfilesFromFile): Error parsing profile data $data[1]";
|
Log3 $me, 1, "$me(readProfilesFromFile): Error parsing profile data $data[1]";
|
||||||
next;
|
next;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user