From d3bd84a4743bfdf5459d8efc091fed1848c32cc4 Mon Sep 17 00:00:00 2001 From: markusbloch <> Date: Thu, 8 Nov 2012 18:45:01 +0000 Subject: [PATCH] several stability improvements and reorganizations git-svn-id: https://svn.fhem.de/fhem/trunk@2095 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/71_YAMAHA_AVR.pm | 106 ++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 30 deletions(-) diff --git a/fhem/FHEM/71_YAMAHA_AVR.pm b/fhem/FHEM/71_YAMAHA_AVR.pm index 4263c9934..2ac929c99 100755 --- a/fhem/FHEM/71_YAMAHA_AVR.pm +++ b/fhem/FHEM/71_YAMAHA_AVR.pm @@ -59,10 +59,32 @@ YAMAHA_AVR_GetStatus($;$) return "" if(!defined($hash->{ADDRESS}) or !defined($hash->{INTERVAL})); my $device = $hash->{ADDRESS}; + + + + if(not defined($hash->{MODEL})) + { + getModel($hash, $device); + } + + if(not defined($hash->{INPUTS}) or length($hash->{INPUTS}) == 0) + { + getInputs($hash, $device); + } + + + my $return = SendCommand($device,"GetParam"); - - return "Can't submit command. please see fhem logfile for further information" if(not defined($return) or length($return) == 0); + Log GetLogLevel($name, 4), "YANMAHA_AVR: GetStatus-Request returned:\n$return"; + + if($return eq "") + { + + $hash->{STATE} = "unknown"; + return; + } + readingsBeginUpdate($hash); @@ -137,8 +159,10 @@ YAMAHA_AVR_Set($@) my $address = $hash->{ADDRESS}; my $result = ""; my $command; - my $inputs_piped = InputParamToFhemInput(lc($hash->{INPUTS}), 0); - my $inputs_comma = InputParamToFhemInput(lc($hash->{INPUTS}), 1); + + + my $inputs_piped = defined($hash->{INPUTS}) ? InputParamToFhemInput(lc($hash->{INPUTS}), 0) : "" ; + my $inputs_comma = defined($hash->{INPUTS}) ? InputParamToFhemInput(lc($hash->{INPUTS}), 1) : "" ; return "No Argument given" if(!defined($a[1])); @@ -168,7 +192,8 @@ YAMAHA_AVR_Set($@) if($hash->{STATE} eq "on") { $inputs_piped =~ s/,/|/g; - + if(not $inputs_piped eq "") + { if($a[2] =~ /^($inputs_piped)$/) { $command = getCommandParam($hash, $a[2]); @@ -191,12 +216,23 @@ YAMAHA_AVR_Set($@) { return $usage; } + } + else + { + return "No inputs are avaible. Please try an statusUpdate."; + } + } else { return "input can only be used when device is powered on"; } } + else + { + return $inputs_piped eq "" ? "No inputs are available. Please try an statusUpdate." : "No input parameter was given"; + } + } elsif($what eq "mute") { @@ -298,7 +334,6 @@ YAMAHA_AVR_Define($$) my ($hash, $def) = @_; my @a = split("[ \t][ \t]*", $def); my $name = $hash->{NAME}; - my @inputs; if(! @a >= 3) { @@ -310,31 +345,7 @@ YAMAHA_AVR_Define($$) my $address = $a[2]; - my $response = GetFileFromURL("http://".$address."/YamahaRemoteControl/desc.xml"); - if($response =~ //) - { - $hash->{MODEL} = $1; - } - $hash->{ADDRESS} = $address; - - $response = SendCommand($address, "GetParam"); - $response =~ s/>\n(.+?)<\/Param>/) - { - if(defined($hash->{INPUTS}) and length($hash->{INPUTS}) > 0) - { - $hash->{INPUTS} .= "|"; - } - - $hash->{INPUTS} .= $1; - - } - } if(defined($a[3]) and $a[3] > 0) @@ -409,6 +420,41 @@ sub getCommandParam($$) } +sub getModel($$) +{ + my ($hash, $address) = @_; + my $response = GetFileFromURL("http://".$address."/YamahaRemoteControl/desc.xml"); + if($response =~ //) + { + $hash->{MODEL} = $1; + } +} + +sub getInputs($$) +{ + + my ($hash, $address) = @_; + my $response = SendCommand($address, "GetParam"); + $response =~ s/>\n(.+?)<\/Param>/) + { + if(defined($hash->{INPUTS}) and length($hash->{INPUTS}) > 0) + { + $hash->{INPUTS} .= "|"; + } + + $hash->{INPUTS} .= $1; + + } + } + +} + + 1;