2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

YAMAHA_BD: code makup

git-svn-id: https://svn.fhem.de/fhem/trunk@10604 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2016-01-23 10:08:27 +00:00
parent 2ddd2df6f2
commit 460d6db9a2

View File

@ -57,46 +57,55 @@ YAMAHA_BD_Initialize($)
$data{RC_layout}{YAMAHA_BluRay} = "YAMAHA_BD_RClayout"; $data{RC_layout}{YAMAHA_BluRay} = "YAMAHA_BD_RClayout";
$data{RC_makenotify}{YAMAHA_BD} = "YAMAHA_BD_RCmakenotify"; $data{RC_makenotify}{YAMAHA_BD} = "YAMAHA_BD_RCmakenotify";
} }
################################### ###################################
sub sub
YAMAHA_BD_GetStatus($;$) YAMAHA_BD_Define($$)
{ {
my ($hash, $local) = @_; my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $power;
my $return;
$local = 0 unless(defined($local)); if(! @a >= 3)
return "" if(!defined($hash->{helper}{ADDRESS}) or !defined($hash->{helper}{ON_INTERVAL}) or !defined($hash->{helper}{OFF_INTERVAL}));
# get the model informations if no informations are available
if((not defined($hash->{MODEL})) or (not defined($hash->{FIRMWARE})))
{ {
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Config>GetParam</Config></System></YAMAHA_AV>", "statusRequest","systemConfig"); my $msg = "wrong syntax: define <name> YAMAHA_BD <ip-or-hostname> [<statusinterval>] [<presenceinterval>]";
Log 2, $msg;
return $msg;
} }
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting system status"; my $address = $a[2];
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Service_Info>GetParam</Service_Info></System></YAMAHA_AV>", "statusRequest","systemStatus");
$hash->{helper}{ADDRESS} = $address;
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting input info"; # if an update interval was given which is greater than zero, use it.
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Input_Info>GetParam</Input_Info></Main_Zone></YAMAHA_AV>", "statusRequest","inputInfo"); if(defined($a[3]) and $a[3] > 0)
{
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting power state"; $hash->{helper}{OFF_INTERVAL}=$a[3];
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Power_Control><Power>GetParam</Power></Power_Control></Main_Zone></YAMAHA_AV>", "statusRequest","powerStatus"); }
else
{
$hash->{helper}{OFF_INTERVAL}=30;
}
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting playing info"; # if a second update interval is given, use this as ON_INTERVAL, otherwise use OFF_INTERVAL instead.
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Play_Info>GetParam</Play_Info></Main_Zone></YAMAHA_AV>", "statusRequest","playInfo"); if(defined($a[4]) and $a[4] > 0)
{
$hash->{helper}{ON_INTERVAL}=$a[4];
}
else
{
$hash->{helper}{ON_INTERVAL}=$hash->{helper}{OFF_INTERVAL};
}
$hash->{helper}{CMD_QUEUE} = ();
delete($hash->{helper}{HTTP_CONNECTION}) if(exists($hash->{helper}{HTTP_CONNECTION}));
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting trickPlay info"; # start the status update timer
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Play_Control>GetParam</Play_Control></Main_Zone></YAMAHA_AV>", "statusRequest","trickPlayInfo"); $hash->{helper}{DISABLED} = 0 unless(exists($hash->{helper}{DISABLED}));
YAMAHA_BD_ResetTimer($hash, 2);
# Reset timer if this is not a local run
YAMAHA_BD_ResetTimer($hash) unless($local == 1); return undef;
} }
################################### ###################################
@ -423,15 +432,15 @@ YAMAHA_BD_Set($@)
} }
elsif($what eq "play") elsif($what eq "play")
{ {
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Play>Play</Play></Play_Control></Main_Zone></YAMAHA_AV>","play", undef); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Play>Play</Play></Play_Control></Main_Zone></YAMAHA_AV>","play", undef);
} }
elsif($what eq "pause") elsif($what eq "pause")
{ {
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Play>Pause</Play></Play_Control></Main_Zone></YAMAHA_AV>","pause", undef); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Play>Pause</Play></Play_Control></Main_Zone></YAMAHA_AV>","pause", undef);
} }
elsif($what eq "stop") elsif($what eq "stop")
{ {
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Play>Stop</Play></Play_Control></Main_Zone></YAMAHA_AV>", "play",undef); YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Play_Control><Play>Stop</Play></Play_Control></Main_Zone></YAMAHA_AV>", "play",undef);
} }
elsif($what eq "statusRequest") elsif($what eq "statusRequest")
{ {
@ -445,57 +454,7 @@ YAMAHA_BD_Set($@)
return undef; return undef;
} }
###################################
#############################
sub
YAMAHA_BD_Define($$)
{
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
my $name = $hash->{NAME};
if(! @a >= 3)
{
my $msg = "wrong syntax: define <name> YAMAHA_BD <ip-or-hostname> [<statusinterval>] [<presenceinterval>]";
Log 2, $msg;
return $msg;
}
my $address = $a[2];
$hash->{helper}{ADDRESS} = $address;
# if an update interval was given which is greater than zero, use it.
if(defined($a[3]) and $a[3] > 0)
{
$hash->{helper}{OFF_INTERVAL}=$a[3];
}
else
{
$hash->{helper}{OFF_INTERVAL}=30;
}
# if a second update interval is given, use this as ON_INTERVAL, otherwise use OFF_INTERVAL instead.
if(defined($a[4]) and $a[4] > 0)
{
$hash->{helper}{ON_INTERVAL}=$a[4];
}
else
{
$hash->{helper}{ON_INTERVAL}=$hash->{helper}{OFF_INTERVAL};
}
$hash->{helper}{CMD_QUEUE} = ();
delete($hash->{helper}{HTTP_CONNECTION}) if(exists($hash->{helper}{HTTP_CONNECTION}));
# start the status update timer
$hash->{helper}{DISABLED} = 0 unless(exists($hash->{helper}{DISABLED}));
YAMAHA_BD_ResetTimer($hash, 2);
return undef;
}
##########################
sub sub
YAMAHA_BD_Attr(@) YAMAHA_BD_Attr(@)
{ {
@ -526,7 +485,7 @@ YAMAHA_BD_Attr(@)
return undef; return undef;
} }
############################# ###################################
sub sub
YAMAHA_BD_Undefine($$) YAMAHA_BD_Undefine($$)
{ {
@ -545,6 +504,44 @@ YAMAHA_BD_Undefine($$)
############################################################################################################ ############################################################################################################
###################################
# get status of player
sub
YAMAHA_BD_GetStatus($;$)
{
my ($hash, $local) = @_;
my $name = $hash->{NAME};
my $power;
my $return;
$local = 0 unless(defined($local));
return "" if(!defined($hash->{helper}{ADDRESS}) or !defined($hash->{helper}{ON_INTERVAL}) or !defined($hash->{helper}{OFF_INTERVAL}));
# get the model informations if no informations are available
if((not defined($hash->{MODEL})) or (not defined($hash->{FIRMWARE})))
{
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Config>GetParam</Config></System></YAMAHA_AV>", "statusRequest","systemConfig");
}
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting system status";
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Service_Info>GetParam</Service_Info></System></YAMAHA_AV>", "statusRequest","systemStatus");
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting input info";
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Input_Info>GetParam</Input_Info></Main_Zone></YAMAHA_AV>", "statusRequest","inputInfo");
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting power state";
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Power_Control><Power>GetParam</Power></Power_Control></Main_Zone></YAMAHA_AV>", "statusRequest","powerStatus");
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting playing info";
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Play_Info>GetParam</Play_Info></Main_Zone></YAMAHA_AV>", "statusRequest","playInfo");
Log3 $name, 4, "YAMAHA_BD ($name) - Requesting trickPlay info";
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><Main_Zone><Play_Control>GetParam</Play_Control></Main_Zone></YAMAHA_AV>", "statusRequest","trickPlayInfo");
# Reset timer if this is not a local run
YAMAHA_BD_ResetTimer($hash) unless($local == 1);
}
############################# #############################
# pushes new command to cmd queue # pushes new command to cmd queue
@ -618,6 +615,9 @@ YAMAHA_BD_ParseResponse($$$)
my $cmd = $param->{cmd}; my $cmd = $param->{cmd};
my $arg = $param->{arg}; my $arg = $param->{arg};
$data = "" unless(defined($data));
$err = "" unless(defined($err));
$hash->{helper}{RUNNING_REQUEST} = 0; $hash->{helper}{RUNNING_REQUEST} = 0;
delete($hash->{helper}{HTTP_CONNECTION}) unless($param->{keepalive}); delete($hash->{helper}{HTTP_CONNECTION}) unless($param->{keepalive});
@ -680,6 +680,7 @@ YAMAHA_BD_ParseResponse($$$)
{ {
$power = "off"; $power = "off";
} }
readingsBulkUpdate($hash, "power", lc($power)); readingsBulkUpdate($hash, "power", lc($power));
readingsBulkUpdate($hash, "state", lc($power)); readingsBulkUpdate($hash, "state", lc($power));
} }
@ -689,10 +690,8 @@ YAMAHA_BD_ParseResponse($$$)
if($data =~ /RC="0"/ and $data =~ /<Power><\/Power>/) if($data =~ /RC="0"/ and $data =~ /<Power><\/Power>/)
{ {
# As the player startup takes about 5 seconds, the status will be already set, if the return code of the command is 0. # As the player startup takes about 5 seconds, the status will be already set, if the return code of the command is 0.
readingsBulkUpdate($hash, "power", "on"); readingsBulkUpdate($hash, "power", "on");
readingsBulkUpdate($hash, "state","on"); readingsBulkUpdate($hash, "state","on");
} }
else else
{ {
@ -781,12 +780,9 @@ YAMAHA_BD_ParseResponse($$$)
YAMAHA_BD_ResetTimer($hash, 10) if($cmd eq "on"); YAMAHA_BD_ResetTimer($hash, 10) if($cmd eq "on");
} }
if(@{$hash->{helper}{CMD_QUEUE}}) $hash->{helper}{AVAILABLE} = ($err ne "" ? 0 : 1);
{
YAMAHA_BD_HandleCmdQueue($hash); YAMAHA_BD_HandleCmdQueue($hash);
}
$hash->{helper}{AVAILABLE} = ($err ? 0 : 1);
} }
############################# #############################