change Master play_previous, change all Modules decode_json in a eval

This commit is contained in:
Marko Oldenburg 2018-02-28 10:08:41 +01:00
parent 3a71f505f5
commit 3acc0dc955
3 changed files with 27 additions and 8 deletions

View File

@ -38,7 +38,7 @@ use JSON qw(decode_json);
use Encode qw(encode_utf8); use Encode qw(encode_utf8);
my $version = "1.0.0"; my $version = "1.0.3";
@ -433,8 +433,13 @@ sub HEOSGroup_Parse($$) {
my $decode_json; my $decode_json;
my $code; my $code;
$decode_json = eval{decode_json(encode_utf8($json))};
if($@){
Log3 $name, 3, "HEOSGroup ($name) - JSON error while request: $@";
return;
}
$decode_json = decode_json(encode_utf8($json));
Log3 $name, 4, "HEOSGroup ($name) - ParseFn wurde aufgerufen"; Log3 $name, 4, "HEOSGroup ($name) - ParseFn wurde aufgerufen";
if( defined($decode_json->{gid}) ) { if( defined($decode_json->{gid}) ) {

View File

@ -65,7 +65,7 @@ eval "use Encode;1" or $missingModul .= "Encode ";
my $version = "1.0.2"; my $version = "1.0.3";
my %heosCmds = ( my %heosCmds = (
'enableChangeEvents' => 'system/register_for_change_events?enable=', 'enableChangeEvents' => 'system/register_for_change_events?enable=',
@ -94,7 +94,7 @@ my %heosCmds = (
'setMute' => 'player/set_mute?', 'setMute' => 'player/set_mute?',
'setGroupMute' => 'group/set_mute?', 'setGroupMute' => 'group/set_mute?',
'playNext' => 'player/play_next?', 'playNext' => 'player/play_next?',
'playPrev' => 'player/play_prev?', 'playPrev' => 'player/play_previous?',
'playPresetStation' => 'browse/play_preset?', 'playPresetStation' => 'browse/play_preset?',
'playInput' => 'browse/play_input?', 'playInput' => 'browse/play_input?',
'playStream' => 'browse/play_stream?', 'playStream' => 'browse/play_stream?',
@ -514,7 +514,12 @@ sub HEOSMaster_ProcessRead($$) {
$hash->{LAST_RECV} = time(); $hash->{LAST_RECV} = time();
Log3 $name, 5, "HEOSMaster ($name) - Decoding JSON message. Length: " . length($json) . " Content: " . $json; Log3 $name, 5, "HEOSMaster ($name) - Decoding JSON message. Length: " . length($json) . " Content: " . $json;
my $obj = decode_json($json);
my $obj = eval{decode_json($json)};
if($@){
Log3 $name, 3, "HEOSMaster ($name) - JSON error while request: $@";
return;
}
if(defined($obj->{heos})) { if(defined($obj->{heos})) {
@ -548,7 +553,11 @@ sub HEOSMaster_ResponseProcessing($$) {
unless( defined($json)); unless( defined($json));
Log3 $name, 4, "HEOSMaster ($name) - JSON detected!"; Log3 $name, 4, "HEOSMaster ($name) - JSON detected!";
$decode_json = decode_json(encode_utf8($json)); $decode_json = eval{decode_json(encode_utf8($json))};
if($@){
Log3 $name, 3, "HEOSMaster ($name) - JSON error while request: $@";
return;
}
return Log3 $name, 3, "HEOSMaster ($name) - decode_json has no Hash" return Log3 $name, 3, "HEOSMaster ($name) - decode_json has no Hash"
unless(ref($decode_json) eq "HASH"); unless(ref($decode_json) eq "HASH");

View File

@ -39,7 +39,7 @@ use Encode qw(encode_utf8);
use URI::Escape; use URI::Escape;
#use Data::Dumper; #use Data::Dumper;
my $version = "1.0.2"; my $version = "1.0.3";
@ -790,8 +790,13 @@ sub HEOSPlayer_Parse($$) {
my $decode_json; my $decode_json;
my $code; my $code;
$decode_json = eval{decode_json(encode_utf8($json))};
if($@){
Log3 $name, 3, "HEOSPlayer ($name) - JSON error while request: $@";
return;
}
$decode_json = decode_json(encode_utf8($json));
Log3 $name, 4, "HEOSPlayer - ParseFn wurde aufgerufen"; Log3 $name, 4, "HEOSPlayer - ParseFn wurde aufgerufen";
if( defined($decode_json->{pid}) ) { if( defined($decode_json->{pid}) ) {