From 460d6db9a25d5cc0ca66a4f263b30f1c596f6231 Mon Sep 17 00:00:00 2001 From: markusbloch <> Date: Sat, 23 Jan 2016 10:08:27 +0000 Subject: [PATCH] YAMAHA_BD: code makup git-svn-id: https://svn.fhem.de/fhem/trunk@10604 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/71_YAMAHA_BD.pm | 178 +++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 91 deletions(-) diff --git a/fhem/FHEM/71_YAMAHA_BD.pm b/fhem/FHEM/71_YAMAHA_BD.pm index af50f1a5c..1df8c7a75 100755 --- a/fhem/FHEM/71_YAMAHA_BD.pm +++ b/fhem/FHEM/71_YAMAHA_BD.pm @@ -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, "GetParam", "statusRequest","systemConfig"); + my $msg = "wrong syntax: define YAMAHA_BD [] []"; + Log 2, $msg; + return $msg; } - Log3 $name, 4, "YAMAHA_BD ($name) - Requesting system status"; - YAMAHA_BD_SendCommand($hash, "GetParam", "statusRequest","systemStatus"); + my $address = $a[2]; + + $hash->{helper}{ADDRESS} = $address; - Log3 $name, 4, "YAMAHA_BD ($name) - Requesting input info"; - YAMAHA_BD_SendCommand($hash, "GetParam", "statusRequest","inputInfo"); - - Log3 $name, 4, "YAMAHA_BD ($name) - Requesting power state"; - YAMAHA_BD_SendCommand($hash, "GetParam", "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, "GetParam", "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}; + } + + $hash->{helper}{CMD_QUEUE} = (); + delete($hash->{helper}{HTTP_CONNECTION}) if(exists($hash->{helper}{HTTP_CONNECTION})); - Log3 $name, 4, "YAMAHA_BD ($name) - Requesting trickPlay info"; - YAMAHA_BD_SendCommand($hash, "GetParam", "statusRequest","trickPlayInfo"); - - # 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; } ################################### @@ -423,15 +432,15 @@ YAMAHA_BD_Set($@) } elsif($what eq "play") { - YAMAHA_BD_SendCommand($hash, "Play","play", undef); + YAMAHA_BD_SendCommand($hash, "Play","play", undef); } elsif($what eq "pause") { - YAMAHA_BD_SendCommand($hash, "Pause","pause", undef); + YAMAHA_BD_SendCommand($hash, "Pause","pause", undef); } elsif($what eq "stop") { - YAMAHA_BD_SendCommand($hash, "Stop", "play",undef); + YAMAHA_BD_SendCommand($hash, "Stop", "play",undef); } elsif($what eq "statusRequest") { @@ -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 YAMAHA_BD [] []"; - 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, "GetParam", "statusRequest","systemConfig"); + } + + Log3 $name, 4, "YAMAHA_BD ($name) - Requesting system status"; + YAMAHA_BD_SendCommand($hash, "GetParam", "statusRequest","systemStatus"); + + Log3 $name, 4, "YAMAHA_BD ($name) - Requesting input info"; + YAMAHA_BD_SendCommand($hash, "GetParam", "statusRequest","inputInfo"); + + Log3 $name, 4, "YAMAHA_BD ($name) - Requesting power state"; + YAMAHA_BD_SendCommand($hash, "GetParam", "statusRequest","powerStatus"); + + Log3 $name, 4, "YAMAHA_BD ($name) - Requesting playing info"; + YAMAHA_BD_SendCommand($hash, "GetParam", "statusRequest","playInfo"); + + Log3 $name, 4, "YAMAHA_BD ($name) - Requesting trickPlay info"; + YAMAHA_BD_SendCommand($hash, "GetParam", "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>/) { # 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"); - + 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 ? 0 : 1); + $hash->{helper}{AVAILABLE} = ($err ne "" ? 0 : 1); + + YAMAHA_BD_HandleCmdQueue($hash); } #############################