diff --git a/FHEM/71_YAMAHA_AVR.pm b/FHEM/71_YAMAHA_AVR.pm
index 4a840373d..c3f5fae76 100755
--- a/FHEM/71_YAMAHA_AVR.pm
+++ b/FHEM/71_YAMAHA_AVR.pm
@@ -67,7 +67,7 @@ YAMAHA_AVR_Initialize($)
###################################
sub
-YAMAHA_AVR_GetStatus($;$)
+YAMAHA_AVR_GetStatus($;$$)
{
my ($hash, $local) = @_;
my $name = $hash->{NAME};
@@ -82,23 +82,22 @@ YAMAHA_AVR_GetStatus($;$)
if(not defined($hash->{MODEL}))
{
- getModel($hash, $device);
+ YAMAHA_AVR_getModel($hash, $device);
}
if(not defined($hash->{INPUTS}) or length($hash->{INPUTS}) == 0)
{
- getInputs($hash, $device);
+ YAMAHA_AVR_getInputs($hash, $device);
}
- my $return = SendCommand($device,"GetParam");
+ my $return = YAMAHA_AVR_SendCommand($device,"GetParam");
Log GetLogLevel($name, 4), "YANMAHA_AVR: GetStatus-Request returned:\n$return";
if($return eq "")
{
-
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "YAMAHA_AVR_GetStatus", $hash, 1) unless($local == 1);
return;
}
@@ -118,15 +117,18 @@ YAMAHA_AVR_GetStatus($;$)
$hash->{STATE} = lc($power);
}
+
+
if($return =~ /(.+)<\/Val>(.+)<\/Exp>.+<\/Unit><\/Lvl>(.+)<\/Mute><\/Volume>/)
{
readingsBulkUpdate($hash, "volume_level", ($1 / 10 ** $2));
readingsBulkUpdate($hash, "mute", lc($3));
}
+
if($return =~ /(.+)<\/Input_Sel>/)
{
- readingsBulkUpdate($hash, "input", InputParamToFhemInput(lc($1), 0));
+ readingsBulkUpdate($hash, "input", YAMAHA_AVR_InputParam2Fhem(lc($1), 0));
}
readingsEndUpdate($hash, 1);
@@ -152,9 +154,10 @@ YAMAHA_AVR_Get($@)
if($what =~ /^(power|input|volume|mute)$/)
{
YAMAHA_AVR_GetStatus($hash, 1);
+
if(defined($hash->{READINGS}{$what}))
{
- return $a[0]." ".$what." => ".$hash->{READINGS}{$what}{VAL};
+ return $a[0]." ".$what." => ".$hash->{READINGS}{$what}{VAL};
}
else
{
@@ -179,8 +182,8 @@ YAMAHA_AVR_Set($@)
my $command;
- my $inputs_piped = defined($hash->{INPUTS}) ? InputParamToFhemInput(lc($hash->{INPUTS}), 0) : "" ;
- my $inputs_comma = defined($hash->{INPUTS}) ? InputParamToFhemInput(lc($hash->{INPUTS}), 1) : "" ;
+ my $inputs_piped = defined($hash->{INPUTS}) ? YAMAHA_AVR_InputParam2Fhem(lc($hash->{INPUTS}), 0) : "" ;
+ my $inputs_comma = defined($hash->{INPUTS}) ? YAMAHA_AVR_InputParam2Fhem(lc($hash->{INPUTS}), 1) : "" ;
return "No Argument given" if(!defined($a[1]));
@@ -188,9 +191,11 @@ YAMAHA_AVR_Set($@)
my $usage = "Unknown argument $what, choose one of on off volume:slider,-80,1,16 input:".$inputs_comma." mute:on,off statusRequest";
readingsBeginUpdate($hash);
+
if($what eq "on")
{
- $result = SendCommand($address, "On");
+ $result = YAMAHA_AVR_SendCommand($address, "On");
+
if($result =~ /RC="0"/ and $result =~ /<\/Power>/)
{
# As the receiver startup takes about 5 seconds, the status will be already set, if the return code of the command is 0.
@@ -198,10 +203,11 @@ YAMAHA_AVR_Set($@)
$hash->{STATE} = "on";
return undef;
}
+
}
elsif($what eq "off")
{
- SendCommand($address, "Standby");
+ YAMAHA_AVR_SendCommand($address, "Standby");
}
elsif($what eq "input")
{
@@ -209,15 +215,15 @@ YAMAHA_AVR_Set($@)
{
if($hash->{STATE} eq "on")
{
- $inputs_piped =~ s/,/|/g;
- if(not $inputs_piped eq "")
- {
+ $inputs_piped =~ s/,/|/g;
+ if(not $inputs_piped eq "")
+ {
if($a[2] =~ /^($inputs_piped)$/)
{
- $command = getCommandParam($hash, $a[2]);
+ $command = YAMAHA_AVR_getCommandParam($hash, $a[2]);
if(defined($command) and length($command) > 0)
{
- $result = SendCommand($address,"".$command."");
+ $result = YAMAHA_AVR_SendCommand($address,"".$command."");
}
else
{
@@ -227,7 +233,7 @@ YAMAHA_AVR_Set($@)
if(not $result =~ /RC="0"/)
{
# if the returncode isn't 0, than the command was not successful
- return "Could not set input to ".$a[2].". Please use only available inputs on your specific receiver";
+ return "Could not set input to ".$a[2].".";
}
}
else
@@ -250,7 +256,7 @@ YAMAHA_AVR_Set($@)
{
return $inputs_piped eq "" ? "No inputs are available. Please try an statusUpdate." : "No input parameter was given";
}
-
+
}
elsif($what eq "mute")
{
@@ -260,12 +266,11 @@ YAMAHA_AVR_Set($@)
{
if( $a[2] eq "on")
{
- SendCommand($address, "On");
+ YAMAHA_AVR_SendCommand($address, "On");
}
elsif($a[2] eq "off")
{
- SendCommand($address, "Off");
-
+ YAMAHA_AVR_SendCommand($address, "Off");
}
else
{
@@ -308,20 +313,15 @@ YAMAHA_AVR_Set($@)
{
Log GetLogLevel($name, 4), "YAMAHA_AV: set volume to ".($current_volume + ($diff * $step))." dB";
- SendCommand($address,"".(($current_volume + ($diff * $step))*10)."1dB");
+ YAMAHA_AVR_SendCommand($address,"".(($current_volume + ($diff * $step))*10)."1dB");
- sleep $sleep unless ($time == 0);
+ sleep $sleep unless ($time == 0);
}
}
-
- # After complete smoothing, set the real wanted volume
- Log GetLogLevel($name, 4), "YAMAHA_AV set volume to ".$a[2]." dB";
- SendCommand($address,"".($a[2]*10)."1dB");
- }
- else
- {
- SendCommand($address,"".($a[2]*10)."1dB");
}
+
+ Log GetLogLevel($name, 4), "YAMAHA_AV set volume to ".$a[2]." dB";
+ YAMAHA_AVR_SendCommand($address,"".($a[2]*10)."1dB");
}
else
{
@@ -383,7 +383,7 @@ YAMAHA_AVR_Define($$)
#############################
sub
-SendCommand($$)
+YAMAHA_AVR_SendCommand($$)
{
my($address, $command) = @_;
@@ -403,7 +403,7 @@ YAMAHA_AVR_Undefine($$)
#############################
# Converts all Inputs to FHEM usable command lists
-sub InputParamToFhemInput($$)
+sub YAMAHA_AVR_InputParam2Fhem($$)
{
my ($inputs, $replace_pipes) = @_;
@@ -418,7 +418,7 @@ sub InputParamToFhemInput($$)
#############################
# Returns the Yamaha Parameter Name for the FHEM like input channel
-sub getCommandParam($$)
+sub YAMAHA_AVR_getCommandParam($$)
{
my ($hash, $command) = @_;
my $item;
@@ -426,7 +426,7 @@ sub getCommandParam($$)
foreach $item (@commands)
{
- if(lc(InputParamToFhemInput($item, 0)) eq $command)
+ if(lc(YAMAHA_AVR_InputParam2Fhem($item, 0)) eq $command)
{
return $item;
}
@@ -438,7 +438,7 @@ sub getCommandParam($$)
}
-sub getModel($$)
+sub YAMAHA_AVR_getModel($$)
{
my ($hash, $address) = @_;
my $response = GetFileFromURL("http://".$address."/YamahaRemoteControl/desc.xml");
@@ -449,11 +449,11 @@ sub getModel($$)
}
}
-sub getInputs($$)
+sub YAMAHA_AVR_getInputs($$)
{
my ($hash, $address) = @_;
- my $response = SendCommand($address, "GetParam");
+ my $response = YAMAHA_AVR_SendCommand($address, "GetParam");
return undef unless (defined($response));
$response =~ s/>>\n