mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-28 05:01:57 +00:00
70_KODI: reworked/fixed handling of attribute "disable"
git-svn-id: https://svn.fhem.de/fhem/trunk@25898 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
e4e5dc7630
commit
3cba270070
@ -158,28 +158,54 @@ sub KODI_Define($$)
|
|||||||
|
|
||||||
$attr{$hash->{NAME}}{"updateInterval"} = 60;
|
$attr{$hash->{NAME}}{"updateInterval"} = 60;
|
||||||
|
|
||||||
return KODI_Connect( $hash, 0 );
|
my $ret = undef;
|
||||||
|
$ret = KODI_Connect( $hash, 0 ) if (!AttrVal($hash->{NAME}, 'disable', 0));
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub KODI_Attr($$$$)
|
sub KODI_Attr($$$$)
|
||||||
{
|
{
|
||||||
my ($cmd, $name, $attr, $value) = @_;
|
my ($mode, $devName, $attrName, $attrValue) = @_;
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$devName};
|
||||||
|
|
||||||
if($attr eq "disable") {
|
# handling for "disable" borrowed from 70_MEDIAPORTAL, thanks
|
||||||
if($cmd eq "set" && ($value || !defined($value))) {
|
|
||||||
KODI_Disconnect($hash);
|
my $disableChange = 0;
|
||||||
$hash->{STATE} = "Disabled";
|
if($mode eq 'set') {
|
||||||
} else {
|
if ($attrName eq 'disable') {
|
||||||
if (AttrVal($hash->{NAME}, 'disable', 0)) {
|
if ($attrValue && AttrVal($devName, $attrName, 0) != 1) {
|
||||||
$hash->{STATE} = "Initialized";
|
$disableChange = 1;
|
||||||
|
}
|
||||||
my $dev = $hash->{DeviceName};
|
|
||||||
$readyfnlist{"$name.$dev"} = $hash;
|
if (!$attrValue && AttrVal($devName, $attrName, 0) != 0) {
|
||||||
|
$disableChange = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elsif ($mode eq 'del') {
|
||||||
|
if ($attrName eq 'disable') {
|
||||||
|
if (AttrVal($devName, $attrName, 0) != 0) {
|
||||||
|
$disableChange = 1;
|
||||||
|
$attrValue = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($disableChange) {
|
||||||
|
# Wenn die Verbindung beendet werden muss...
|
||||||
|
if ($attrValue) {
|
||||||
|
Log3($devName, 3, "$devName: Call AttributeFn: Stop Connection...");
|
||||||
|
DevIo_CloseDev($hash);
|
||||||
|
$hash->{STATE} = "Disabled";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Wenn die Verbindung gestartet werden muss...
|
||||||
|
if (!$attrValue) {
|
||||||
|
Log3($devName, 3, "$devName: Call AttributeFn: Start Connection...");
|
||||||
|
$hash->{STATE} = "Initialized";
|
||||||
|
KODI_Connect($hash, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +276,7 @@ sub KODI_OnConnect($)
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub KODI_OnConnectError($$) {
|
sub KODI_OnConnectError($$) {
|
||||||
my ( $hash, $err ) = @_;
|
my ( $hash, $err ) = @_;
|
||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
@ -265,8 +291,6 @@ sub KODI_Undefine($$)
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
Log3($name, 4, "$name: KODI_Undefine");
|
Log3($name, 4, "$name: KODI_Undefine");
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
|
||||||
|
|
||||||
KODI_Disconnect($hash);
|
KODI_Disconnect($hash);
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -276,6 +300,7 @@ sub KODI_Disconnect($)
|
|||||||
{
|
{
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
if($hash->{Protocol} eq 'tcp') {
|
if($hash->{Protocol} eq 'tcp') {
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
DevIo_CloseDev($hash);
|
DevIo_CloseDev($hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -713,10 +738,10 @@ sub KODI_ProcessNotification($$)
|
|||||||
elsif($obj->{method} eq "Player.OnStop") {
|
elsif($obj->{method} eq "Player.OnStop") {
|
||||||
Log3($name, 5, "$name: KODI_ProcessNotification: player stopped");
|
Log3($name, 5, "$name: KODI_ProcessNotification: player stopped");
|
||||||
readingsSingleUpdate($hash,"playStatus",'stopped',1);
|
readingsSingleUpdate($hash,"playStatus",'stopped',1);
|
||||||
|
|
||||||
#HACK: We want to fetch GUI.Properties here to update for example stereoscopicmode.
|
#HACK: We want to fetch GUI.Properties here to update for example stereoscopicmode.
|
||||||
# When doing this here we still get the in-movie stereo mode. So we define a timer
|
# When doing this here we still get the in-movie stereo mode. So we define a timer
|
||||||
# to invoke the update in some (tm) seconds
|
# to invoke the update in some (tm) seconds
|
||||||
KODI_QueueIntervalUpdate($hash, 2);
|
KODI_QueueIntervalUpdate($hash, 2);
|
||||||
}
|
}
|
||||||
elsif($obj->{method} eq "Player.OnPause") {
|
elsif($obj->{method} eq "Player.OnPause") {
|
||||||
@ -727,7 +752,7 @@ sub KODI_ProcessNotification($$)
|
|||||||
Log3($name, 5, "$name: KODI_ProcessNotification: player started playing");
|
Log3($name, 5, "$name: KODI_ProcessNotification: player started playing");
|
||||||
KODI_ResetMediaReadings($hash);
|
KODI_ResetMediaReadings($hash);
|
||||||
KODI_PlayerOnPlay($hash, $obj);
|
KODI_PlayerOnPlay($hash, $obj);
|
||||||
KODI_Update($hash);
|
KODI_Update($hash);
|
||||||
}
|
}
|
||||||
elsif($obj->{method} eq "Player.OnResume") {
|
elsif($obj->{method} eq "Player.OnResume") {
|
||||||
Log3($name, 5, "$name: KODI_ProcessNotification: player resumed");
|
Log3($name, 5, "$name: KODI_ProcessNotification: player resumed");
|
||||||
@ -749,7 +774,7 @@ sub KODI_ProcessNotification($$)
|
|||||||
#and force a connection check in some seconds when we think KODI actually has shut down
|
#and force a connection check in some seconds when we think KODI actually has shut down
|
||||||
$hash->{LAST_RECV} = 0;
|
$hash->{LAST_RECV} = 0;
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
KODI_QueueIntervalUpdate($hash, 5);
|
KODI_QueueIntervalUpdate($hash, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1363,11 +1388,11 @@ sub KODI_Set_Seek($@)
|
|||||||
my $obj = {
|
my $obj = {
|
||||||
'method' => 'Player.Seek',
|
'method' => 'Player.Seek',
|
||||||
'params' => {
|
'params' => {
|
||||||
'value' => {
|
'value' => {
|
||||||
'seconds' => $seconds + 0,
|
'seconds' => $seconds + 0,
|
||||||
'minutes' => $minutes + 0 ,
|
'minutes' => $minutes + 0 ,
|
||||||
'hours' => $hours + 0
|
'hours' => $hours + 0
|
||||||
},
|
},
|
||||||
'playerid' => 0 #will be replaced with the active player
|
'playerid' => 0 #will be replaced with the active player
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1940,7 +1965,7 @@ sub KODI_HTTP_Request($$@)
|
|||||||
<li><b>audiolibrary</b> - Possible values: cleanfinished, cleanstarted, remove, scanfinished, scanstarted, update</li>
|
<li><b>audiolibrary</b> - Possible values: cleanfinished, cleanstarted, remove, scanfinished, scanstarted, update</li>
|
||||||
<li><b>currentAlbum</b> - album of the current song/musicvideo</li>
|
<li><b>currentAlbum</b> - album of the current song/musicvideo</li>
|
||||||
<li><b>currentArtist</b> - artist of the current song/musicvideo</li>
|
<li><b>currentArtist</b> - artist of the current song/musicvideo</li>
|
||||||
<li><b>currentAudioStream_*</b> - informations about currently active audio stream</li>
|
<li><b>currentAudioStream_*</b> - information about currently active audio stream</li>
|
||||||
<li><b>currentMedia</b> - file/URL of the media item being played</li>
|
<li><b>currentMedia</b> - file/URL of the media item being played</li>
|
||||||
<li><b>currentTitle</b> - title of the current media item</li>
|
<li><b>currentTitle</b> - title of the current media item</li>
|
||||||
<li><b>currentTrack</b> - track of the current song/musicvideo</li>
|
<li><b>currentTrack</b> - track of the current song/musicvideo</li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user