mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-22 14:16:42 +00:00
98_DSBMobile.pm: Fix JSON issue and temporarily disable DSBMobile due to change in API
git-svn-id: https://svn.fhem.de/fhem/trunk@21733 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
e5655f2e28
commit
447e70fbfc
@ -1,4 +1,4 @@
|
|||||||
# $Id$
|
# $Id$
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# 98_DSBMobile.pm
|
# 98_DSBMobile.pm
|
||||||
@ -54,7 +54,8 @@ sub DSBMobile_Initialize($) {
|
|||||||
|
|
||||||
$hash->{DefFn} = "DSBMobile_Define";
|
$hash->{DefFn} = "DSBMobile_Define";
|
||||||
$hash->{UndefFn} = "DSBMobile_Undefine";
|
$hash->{UndefFn} = "DSBMobile_Undefine";
|
||||||
$hash->{GetFn} = "DSBMobile_Get";
|
|
||||||
|
#$hash->{GetFn} = "DSBMobile_Get";
|
||||||
|
|
||||||
#$hash->{SetFn} = "DSBMobile_Set";
|
#$hash->{SetFn} = "DSBMobile_Set";
|
||||||
$hash->{AttrFn} = "DSBMobile_Attr";
|
$hash->{AttrFn} = "DSBMobile_Attr";
|
||||||
@ -67,7 +68,9 @@ sub DSBMobile_Initialize($) {
|
|||||||
. "dsb_classReading "
|
. "dsb_classReading "
|
||||||
. "dsb_outputFormat:textField-long " );
|
. "dsb_outputFormat:textField-long " );
|
||||||
$hash->{AttrList} = join( " ", @DSBMobile_attr ) . " " . $readingFnAttributes;
|
$hash->{AttrList} = join( " ", @DSBMobile_attr ) . " " . $readingFnAttributes;
|
||||||
|
|
||||||
return FHEM::Meta::InitMod( __FILE__, $hash );
|
return FHEM::Meta::InitMod( __FILE__, $hash );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
@ -90,11 +93,19 @@ sub DSBMobile_Define($@) {
|
|||||||
|
|
||||||
$hash->{NAME} = $name;
|
$hash->{NAME} = $name;
|
||||||
|
|
||||||
|
#Temporary death of DSBMobile module ###
|
||||||
|
|
||||||
|
Log3 $name, 3, "[$name] DSBMobile API was changed thus the Module currently can't be used and is disabled";
|
||||||
|
CommandAttr( undef, $name . " dsb_interval 0" );
|
||||||
|
$hash->{STATE} = 'Currently unavailable';
|
||||||
|
return;
|
||||||
|
|
||||||
#start timer
|
#start timer
|
||||||
if ( AttrNum( $name, "dsb_interval", 0 ) > 0 && $init_done ) {
|
if ( AttrNum( $name, "dsb_interval", 0 ) > 0 && $init_done ) {
|
||||||
my $next = int( gettimeofday() ) + 1;
|
my $next = int( gettimeofday() ) + 1;
|
||||||
InternalTimer( $next, 'DSBMobile_ProcessTimer', $hash, 0 );
|
InternalTimer( $next, 'DSBMobile_ProcessTimer', $hash, 0 );
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
###################################
|
###################################
|
||||||
sub DSBMobile_Undefine($$) {
|
sub DSBMobile_Undefine($$) {
|
||||||
@ -215,12 +226,12 @@ sub DSBMobile_getDataCallback($) {
|
|||||||
|
|
||||||
Log3 $name, 5, "[$name] 1st nonblocking HTTP Call returning";
|
Log3 $name, 5, "[$name] 1st nonblocking HTTP Call returning";
|
||||||
Log3 $name, 5, "[$name] GetData - received $data";
|
Log3 $name, 5, "[$name] GetData - received $data";
|
||||||
my $j = decode_json($data);
|
my $j = DSBMobile_safe_decode_json( $hash, $data );
|
||||||
my $d64 = decode_base64( $j->{d} );
|
my $d64 = decode_base64( $j->{d} );
|
||||||
my $json;
|
my $json;
|
||||||
IO::Uncompress::Gunzip::gunzip \$d64 => \$json;
|
IO::Uncompress::Gunzip::gunzip \$d64 => \$json;
|
||||||
$json = latin1ToUtf8($json);
|
$json = latin1ToUtf8($json);
|
||||||
my $res = decode_json($json);
|
my $res = DSBMobile_safe_decode_json( $hash, $json );
|
||||||
if ( $res->{Resultcode} == 1 ) {
|
if ( $res->{Resultcode} == 1 ) {
|
||||||
readingsSingleUpdate( $hash, "error", $res->{ResultStatusInfo}, 0 );
|
readingsSingleUpdate( $hash, "error", $res->{ResultStatusInfo}, 0 );
|
||||||
return undef;
|
return undef;
|
||||||
@ -255,18 +266,12 @@ sub DSBMobile_getDataCallback($) {
|
|||||||
my $d = $topic->{Root}{Childs};
|
my $d = $topic->{Root}{Childs};
|
||||||
|
|
||||||
for my $tile (@$d) {
|
for my $tile (@$d) {
|
||||||
my $subtile = $tile->{Childs};
|
my %au = (
|
||||||
my $i = 1;
|
title => $tile->{Title},
|
||||||
for my $stile (@$subtile) {
|
url => $tile->{Childs}[0]->{Detail},
|
||||||
my %au = (
|
date => $tile->{Childs}[0]->{Date}
|
||||||
title => $tile->{Title}.$i,
|
);
|
||||||
url => $stile->{Detail},
|
push( @aus, \%au );
|
||||||
date => $stile->{Date}
|
|
||||||
);
|
|
||||||
$i++;
|
|
||||||
push( @aus, \%au );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -687,6 +692,22 @@ sub DSBMobile_simpleHTML($;$) {
|
|||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub DSBMobile_safe_decode_json($$) {
|
||||||
|
my ( $hash, $data ) = @_;
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
my $json = undef;
|
||||||
|
eval {
|
||||||
|
$json = decode_json($data);
|
||||||
|
1;
|
||||||
|
} or do {
|
||||||
|
my $error = $@ || 'Unknown failure';
|
||||||
|
Log3 $name, 1, "[$name] - Received invalid JSON: $error";
|
||||||
|
|
||||||
|
};
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
###################################
|
###################################
|
||||||
sub DSBMobile_tableHTML($;$) {
|
sub DSBMobile_tableHTML($;$) {
|
||||||
my ( $name, $infoDay ) = @_;
|
my ( $name, $infoDay ) = @_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user