2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-07 16:59:18 +00:00

70_KODI: added reading jsonResponse which contains the last received message from Kodi (really this time)

git-svn-id: https://svn.fhem.de/fhem/trunk@15355 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
vbs 2017-10-30 14:42:22 +00:00
parent 33848b7b77
commit 84d06c26a5

View File

@ -113,7 +113,7 @@ sub KODI_Initialize($$)
$hash->{ReadyFn} = "KODI_Ready"; $hash->{ReadyFn} = "KODI_Ready";
$hash->{UndefFn} = "KODI_Undefine"; $hash->{UndefFn} = "KODI_Undefine";
$hash->{AttrFn} = "KODI_Attr"; $hash->{AttrFn} = "KODI_Attr";
$hash->{AttrList} = "fork:enable,disable compatibilityMode:kodi,plex offMode:quit,hibernate,shutdown,suspend updateInterval disable:1,0 " . $readingFnAttributes; $hash->{AttrList} = "fork:enable,disable compatibilityMode:kodi,plex offMode:quit,hibernate,shutdown,suspend updateInterval disable:0,1 jsonResponseReading:0,1 " . $readingFnAttributes;
$data{RC_makenotify}{XBMC} = "KODI_RCmakenotify"; $data{RC_makenotify}{XBMC} = "KODI_RCmakenotify";
$data{RC_layout}{KODI_RClayout} = "KODI_RClayout"; $data{RC_layout}{KODI_RClayout} = "KODI_RClayout";
@ -482,7 +482,9 @@ sub KODI_ProcessRead($$)
#processes all complete messages #processes all complete messages
while($msg) { while($msg) {
$hash->{LAST_RECV} = time(); $hash->{LAST_RECV} = time();
Log3($name, 4, "KODI_Read: Decoding JSON message. Length: " . length($msg) . " Content: " . $msg); Log3($name, 4, "KODI_Read: Decoding JSON message. Length: " . length($msg) . " Content: " . $msg);
KODI_SetJsonResponseReading($hash, $msg);
my $obj = JSON->new->utf8(0)->decode($msg); my $obj = JSON->new->utf8(0)->decode($msg);
#it is a notification if a method name is present #it is a notification if a method name is present
if(defined($obj->{method})) { if(defined($obj->{method})) {
@ -505,6 +507,14 @@ sub KODI_ProcessRead($$)
return; return;
} }
sub KODI_SetJsonResponseReading($$)
{
my ($hash, $json) = @_;
return if AttrVal($hash->{NAME}, 'jsonResponseReading', 0) == 0;
readingsSingleUpdate($hash, "jsonResponse", $json, 1);
}
sub KODI_ResetMediaReadings($) sub KODI_ResetMediaReadings($)
{ {
my ($hash) = @_; my ($hash) = @_;
@ -1486,7 +1496,11 @@ sub KODI_HTTP_Call($$$)
if($ret =~ /^error:(\d{3})$/) { if($ret =~ /^error:(\d{3})$/) {
return "HTTP Error Code " . $1; return "HTTP Error Code " . $1;
} }
return KODI_ProcessResponse($hash,JSON->new->utf8(0)->decode($ret)) if($id);
if($id) {
KODI_SetJsonResponseReading($hash, $ret);
return KODI_ProcessResponse($hash, JSON->new->utf8(0)->decode($ret)) ;
}
return undef; return undef;
} }