From 0312e8305eb39e48dd596aba5b5c75e717623e02 Mon Sep 17 00:00:00 2001 From: vbs2 Date: Sun, 25 Oct 2015 12:44:05 +0000 Subject: [PATCH] 70_XBMC: added attribute "disable", added reading "tvshowid" git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@9661 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 ++ fhem/FHEM/70_XBMC.pm | 62 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 8dd17099f..8d504ced6 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 70_XBMC: -added disable attribute + -added reading tvshowid - feature: new module 00_SIGNALduino.pm and 90_SIGNALduino_un: added SIGNALduino module and firmware - feature: new module 14_Hideki.pm: added module for sensors with hideki diff --git a/fhem/FHEM/70_XBMC.pm b/fhem/FHEM/70_XBMC.pm index 551e583f3..991c4581a 100644 --- a/fhem/FHEM/70_XBMC.pm +++ b/fhem/FHEM/70_XBMC.pm @@ -29,7 +29,8 @@ sub XBMC_Initialize($$) $hash->{ReadFn} = "XBMC_Read"; $hash->{ReadyFn} = "XBMC_Ready"; $hash->{UndefFn} = "XBMC_Undefine"; - $hash->{AttrList} = "fork:enable,disable compatibilityMode:xbmc,plex offMode:quit,hibernate,shutdown,standby updateInterval " . $readingFnAttributes; + $hash->{AttrFn} = "XBMC_Attr"; + $hash->{AttrList} = "fork:enable,disable compatibilityMode:xbmc,plex offMode:quit,hibernate,shutdown,standby updateInterval disable:1,0 " . $readingFnAttributes; $data{RC_makenotify}{XBMC} = "XBMC_RCmakenotify"; $data{RC_layout}{XBMC_RClayout} = "XBMC_RClayout"; @@ -75,6 +76,28 @@ sub XBMC_Define($$) return undef; } +sub XBMC_Attr($$$$) +{ + my ($cmd, $name, $attr, $value) = @_; + my $hash = $defs{$name}; + + if($attr eq "disable") { + if($cmd eq "set" && ($value || !defined($value))) { + XBMC_Disconnect($hash); + $hash->{STATE} = "Disabled"; + } else { + if (AttrVal($hash->{NAME}, 'disable', 0)) { + $hash->{STATE} = "Initialized"; + + my $dev = $hash->{DeviceName}; + $readyfnlist{"$name.$dev"} = $hash; + } + } + } + + return undef; +} + # Force a connection attempt to XBMC as soon as possible # (e.g. you know you just started it and want to connect immediately without waiting up to 60 s) sub XBMC_Connect($) @@ -99,13 +122,29 @@ sub XBMC_Connect($) } else { $hash->{NEXT_OPEN} = 0; # force NEXT_OPEN used in DevIO } - + return undef; } +# kills child process trying to connect (if existing) +sub XBMC_KillConnectionChild($) +{ + my ($hash) = @_; + + return if !$hash->{CHILDPID}; + + kill 'KILL', $hash->{CHILDPID}; + undef $hash->{CHILDPID}; +} + sub XBMC_Ready($) { my ($hash) = @_; + + if (AttrVal($hash->{NAME}, 'disable', 0)) { + return; + } + if($hash->{Protocol} eq 'tcp') { if(AttrVal($hash->{NAME},'fork','disable') eq 'enable') { if($hash->{CHILDPID} && !(kill 0, $hash->{CHILDPID})) { @@ -153,10 +192,19 @@ sub XBMC_Undefine($$) RemoveInternalTimer($hash); + XBMC_Disconnect($hash); + + return undef; +} + +sub XBMC_Disconnect($) +{ + my ($hash) = @_; if($hash->{Protocol} eq 'tcp') { DevIo_CloseDev($hash); } - return undef; + + XBMC_KillConnectionChild($hash); } sub XBMC_Init($) @@ -293,7 +341,7 @@ sub XBMC_PlayerGetItem($$) "method" => "Player.GetItem", "params" => { "properties" => ["artist", "album", "thumbnail", "file", "title", - "track", "year", "streamdetails"] + "track", "year", "streamdetails", "tvshowid"] } }; if($playerid >= 0) { @@ -387,7 +435,7 @@ sub XBMC_ResetMediaReadings($) # delete streamdetails readings # NOTE: we actually delete the readings (unlike the other readings) # because they are stream count dependent - fhem("deletereading $hash->{NAME} sd_.*"); + fhem("deletereading $hash->{NAME} sd_.*", 1); } sub XBMC_ResetPlayerReadings($) @@ -1588,8 +1636,10 @@ sub XBMC_HTTP_Request($$@) If XBMC does not run all the time it used to be the case that FHEM blocks because it cannot reach XBMC (only happened if TCP was used). If you encounter problems like FHEM not responding for a few seconds then you should set attr <XBMC_device> fork enable which will move the search for XBMC into a separate process. -
  • updateInterval
    +
  • updateInterval
    The interval which is used to check if Kodi is still alive (by sending a JSON ping) and also it is used to update current player item.
  • +
  • disable
    + Disables the device. All connections will be closed immediately.