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_makenotify}{YAMAHA_BD} = "YAMAHA_BD_RCmakenotify";
}
###################################
sub
YAMAHA_BD_GetStatus($;$)
YAMAHA_BD_Define($$)
{
my ($hash, $local) = @_;
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
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})))
if(! @a >= 3)
{
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";
YAMAHA_BD_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Service_Info>GetParam</Service_Info></System></YAMAHA_AV>", "statusRequest","systemStatus");
my $address = $a[2];
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");
$hash->{helper}{ADDRESS} = $address;
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");
# 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;
}
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");
# 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};
}
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");
$hash->{helper}{CMD_QUEUE} = ();
delete($hash->{helper}{HTTP_CONNECTION}) if(exists($hash->{helper}{HTTP_CONNECTION}));
# Reset timer if this is not a local run
YAMAHA_BD_ResetTimer($hash) unless($local == 1);
# start the status update timer
$hash->{helper}{DISABLED} = 0 unless(exists($hash->{helper}{DISABLED}));
YAMAHA_BD_ResetTimer($hash, 2);
return undef;
}
###################################
@ -445,57 +454,7 @@ YAMAHA_BD_Set($@)
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
YAMAHA_BD_Attr(@)
{
@ -526,7 +485,7 @@ YAMAHA_BD_Attr(@)
return undef;
}
#############################
###################################
sub
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
@ -618,6 +615,9 @@ YAMAHA_BD_ParseResponse($$$)
my $cmd = $param->{cmd};
my $arg = $param->{arg};
$data = "" unless(defined($data));
$err = "" unless(defined($err));
$hash->{helper}{RUNNING_REQUEST} = 0;
delete($hash->{helper}{HTTP_CONNECTION}) unless($param->{keepalive});
@ -680,6 +680,7 @@ YAMAHA_BD_ParseResponse($$$)
{
$power = "off";
}
readingsBulkUpdate($hash, "power", lc($power));
readingsBulkUpdate($hash, "state", lc($power));
}
@ -689,10 +690,8 @@ YAMAHA_BD_ParseResponse($$$)
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.
readingsBulkUpdate($hash, "power", "on");
readingsBulkUpdate($hash, "state","on");
}
else
{
@ -781,12 +780,9 @@ YAMAHA_BD_ParseResponse($$$)
YAMAHA_BD_ResetTimer($hash, 10) if($cmd eq "on");
}
if(@{$hash->{helper}{CMD_QUEUE}})
{
YAMAHA_BD_HandleCmdQueue($hash);
}
$hash->{helper}{AVAILABLE} = ($err ne "" ? 0 : 1);
$hash->{helper}{AVAILABLE} = ($err ? 0 : 1);
YAMAHA_BD_HandleCmdQueue($hash);
}
#############################