From b88c95cdbf20fe6c4b59e4f6275e8903671db65f Mon Sep 17 00:00:00 2001
From: markusbloch <>
Date: Sun, 18 May 2014 11:17:32 +0000
Subject: [PATCH] YAMAHA_AVR: new commands 3dCinemaDsp,adaptiveDrc,direct and
sleep and corresponding readings; minor code optimizations.
git-svn-id: https://svn.fhem.de/fhem/trunk@5884 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 2 +-
fhem/FHEM/71_YAMAHA_AVR.pm | 446 ++++++++++++++++++++++++++-----------
2 files changed, 311 insertions(+), 137 deletions(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index 31961f4ec..7e3e26b0f 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -2,7 +2,7 @@
# Do not insert empty lines here, update check depends on it.
- feature: YAMAHA_AVR: new set commands and readings for controlling
the sound output behavior (Enhancer, DSP and straight
- output). For details, see commandref.
+ output) and sleep timer. For details, see commandref.
- bugfix: configdb filemove not working after previous changes
- change: IMPORTANT CHANGES TO configDB!
changed: all files will be imported as binary
diff --git a/fhem/FHEM/71_YAMAHA_AVR.pm b/fhem/FHEM/71_YAMAHA_AVR.pm
index 8eac09dbd..bf88ccdd2 100755
--- a/fhem/FHEM/71_YAMAHA_AVR.pm
+++ b/fhem/FHEM/71_YAMAHA_AVR.pm
@@ -95,7 +95,7 @@ YAMAHA_AVR_GetStatus($;$)
}
}
- my $zone = YAMAHA_AVR_getZoneName($hash, $hash->{ACTIVE_ZONE});
+ my $zone = YAMAHA_AVR_getParamName($hash, $hash->{ACTIVE_ZONE}, $hash->{helper}{ZONES});
if(not defined($zone))
{
@@ -105,7 +105,7 @@ YAMAHA_AVR_GetStatus($;$)
my $return = YAMAHA_AVR_SendCommand($hash, "<$zone>GetParam$zone>");
- Log3 $name, 4, "YAMAHA_AVR: GetStatus-Request returned: $return" if(defined($return));
+ #Log3 $name, 4, "YAMAHA_AVR: GetStatus-Request returned: $return" if(defined($return));
if(not defined($return) or $return eq "")
{
@@ -278,6 +278,37 @@ YAMAHA_AVR_GetStatus($;$)
readingsBulkUpdate($hash, "dsp", YAMAHA_AVR_Param2Fhem($1, 0));
}
+ if($return =~ /.*?<_3D_Cinema_DSP>(.+?)<\/_3D_Cinema_DSP>*?<\/Surround>/)
+ {
+ readingsBulkUpdate($hash, "3dCinemaDsp", lc($1));
+ }
+
+ if($return =~ /.*?(.+?)<\/Adaptive_DRC>.*?<\/Sound_Video>/)
+ {
+ readingsBulkUpdate($hash, "adaptiveDrc", lc($1));
+ }
+
+ if($return =~ /.*?(.+?)<\/Sleep>.*?<\/Power_Control>/)
+ {
+ readingsBulkUpdate($hash, "sleep", YAMAHA_AVR_Param2Fhem($1, 0));
+ }
+
+ if($return =~ /.*?.*?(.+?)<\/Mode>.*?<\/Direct>.*?<\/Sound_Video>/)
+ {
+ readingsBulkUpdate($hash, "direct", lc($1));
+ $hash->{helper}{DIRECT_TAG} = "Direct";
+ }
+ elsif($return =~ /.*?.*?(.+?)<\/Mode>.*?<\/Pure_Direct>.*?<\/Sound_Video>/)
+ {
+ readingsBulkUpdate($hash, "direct", lc($1));
+ $hash->{helper}{DIRECT_TAG} = "Pure_Direct";
+ }
+ else
+ {
+ delete($hash->{helper}{DIRECT_TAG}) if(exists($hash->{helper}{DIRECT_TAG}));
+ }
+
+
readingsEndUpdate($hash, 1);
@@ -350,7 +381,7 @@ YAMAHA_AVR_Set($@)
YAMAHA_AVR_getInputs($hash);
}
- my $zone = YAMAHA_AVR_getZoneName($hash, $hash->{ACTIVE_ZONE});
+ my $zone = YAMAHA_AVR_getParamName($hash, $hash->{ACTIVE_ZONE}, $hash->{helper}{ZONES});
my $inputs_piped = defined($hash->{helper}{INPUTS}) ? YAMAHA_AVR_Param2Fhem(lc($hash->{helper}{INPUTS}), 0) : "" ;
my $inputs_comma = defined($hash->{helper}{INPUTS}) ? YAMAHA_AVR_Param2Fhem(lc($hash->{helper}{INPUTS}), 1) : "" ;
@@ -367,7 +398,7 @@ YAMAHA_AVR_Set($@)
return "No Argument given" if(!defined($a[1]));
my $what = $a[1];
- my $usage = "Unknown argument $what, choose one of on:noArg off:noArg volumeStraight:slider,-80,1,16 volume:slider,0,1,100 volumeUp volumeDown input:".$inputs_comma." mute:on,off,toggle remoteControl:setup,up,down,left,right,return,option,display,tunerPresetUp,tunerPresetDown,enter ".(defined($hash->{helper}{SCENES})?"scene:".$scenes_comma." ":"").($hash->{helper}{SELECTED_ZONE} eq "mainzone" ? "straight:on,off ".(defined($hash->{helper}{SCENES}) ? "dsp:".$dsp_modes_comma." " : "")." enhancer:on,off " : "")."statusRequest:noArg";
+ my $usage = "Unknown argument $what, choose one of on:noArg off:noArg volumeStraight:slider,-80,1,16 volume:slider,0,1,100 volumeUp volumeDown input:".$inputs_comma." mute:on,off,toggle remoteControl:setup,up,down,left,right,return,option,display,tunerPresetUp,tunerPresetDown,enter ".(defined($hash->{helper}{SCENES})?"scene:".$scenes_comma." ":"").($hash->{helper}{SELECTED_ZONE} eq "mainzone" ? "straight:on,off 3dCinemaDsp:off,auto adaptiveDrc:off,auto ".(exists($hash->{helper}{DIRECT_TAG}) ? "direct:on,off " : "").(exists($hash->{helper}{DSP_MODES}) ? "dsp:".$dsp_modes_comma." " : "")." enhancer:on,off " : "")."sleep:off,30min,60min,90min,120min,last statusRequest:noArg";
# Depending on the status response, use the short or long Volume command
@@ -415,7 +446,7 @@ YAMAHA_AVR_Set($@)
{
if($a[2] =~ /^($inputs_piped)$/)
{
- $command = YAMAHA_AVR_getParam($hash, $a[2], $hash->{helper}{INPUTS});
+ $command = YAMAHA_AVR_getParamName($hash, $a[2], $hash->{helper}{INPUTS});
if(defined($command) and length($command) > 0)
{
$result = YAMAHA_AVR_SendCommand($hash, "<$zone>".$command."$zone>");
@@ -603,7 +634,7 @@ YAMAHA_AVR_Set($@)
}
}
elsif($what eq "dsp")
- {
+ {
if(defined($a[2]))
{
@@ -611,122 +642,259 @@ YAMAHA_AVR_Set($@)
{
if($a[2] =~ /^($dsp_modes_piped)$/)
{
- $command = YAMAHA_AVR_getParamName($hash, $a[2],$hash->{helper}{DSP_MODES});
- if(defined($command) and length($command) > 0)
- {
- $result = YAMAHA_AVR_SendCommand($hash, "<$zone>$command$zone>");
- }
- else
- {
- return "invalid dsp mode: ".$a[2];
- }
+ $command = YAMAHA_AVR_getParamName($hash, $a[2],$hash->{helper}{DSP_MODES});
+ if(defined($command) and length($command) > 0)
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>$command$zone>");
+ }
+ else
+ {
+ return "invalid dsp mode: ".$a[2];
+ }
- if(not $result =~ /RC="0"/)
- {
- # if the returncode isn't 0, than the command was not successful
- return "Could not set dsp mode to ".$a[2].".";
- }
- }
- else
- {
- return $usage;
- }
- }
- else
- {
- return "No DSP presets are avaible. Please try an statusUpdate.";
- }
- }
- else
- {
- return $dsp_modes_piped eq "" ? "No dsp presets are available. Please try an statusUpdate." : "No dsp preset was given";
- }
+ if(not $result =~ /RC="0"/)
+ {
+ # if the returncode isn't 0, than the command was not successful
+ return "Could not set dsp mode to ".$a[2].".";
+ }
+ }
+ else
+ {
+ return $usage;
+ }
+ }
+ else
+ {
+ return "No DSP presets are avaible. Please try an statusUpdate.";
+ }
+ }
+ else
+ {
+ return $dsp_modes_piped eq "" ? "No dsp presets are available. Please try an statusUpdate." : "No dsp preset was given";
+ }
}
elsif($what eq "straight")
- {
+ {
+
+ $result = undef;
+
if($a[2] eq "on")
- {
- YAMAHA_AVR_SendCommand($hash, "<$zone>On$zone>");
- }
- elsif($a[2] eq "off")
- {
- YAMAHA_AVR_SendCommand($hash, "<$zone>Off$zone>");
- }
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>On$zone>");
+ }
+ elsif($a[2] eq "off")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>Off$zone>");
+ }
+ else
+ {
+ return $usage;
+ }
+
+ if(not defined($result) or not $result =~ /RC="0"/)
+ {
+ # if the returncode isn't 0, than the command was not successful
+ return "Could not set straight to ".$a[2].".";
+ }
+ }
+ elsif($what eq "3dCinemaDsp")
+ {
+
+ $result = undef;
+
+ if($a[2] eq "auto")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone><_3D_Cinema_DSP>Auto$zone>");
+ }
+ elsif($a[2] eq "off")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone><_3D_Cinema_DSP>Off$zone>");
+ }
+ else
+ {
+ return $usage;
+ }
+
+ if(not defined($result) or not $result =~ /RC="0"/)
+ {
+ # if the returncode isn't 0, than the command was not successful
+ return "Could not set 3dCinemaDsp to ".$a[2].".";
+ }
+ }
+ elsif($what eq "adaptiveDrc")
+ {
+
+ $result = undef;
+
+ if($a[2] eq "auto")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>Auto$zone>");
+ }
+ elsif($a[2] eq "off")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>Off$zone>");
+ }
+ else
+ {
+ return $usage;
+ }
+
+ if(not defined($result) or not $result =~ /RC="0"/)
+ {
+ # if the returncode isn't 0, than the command was not successful
+ return "Could not set adaptiveDrc to ".$a[2].".";
+ }
}
elsif($what eq "enhancer")
- {
+ {
+
+ $result = undef;
+
if($a[2] eq "on")
- {
- YAMAHA_AVR_SendCommand($hash, "<$zone>On$zone>");
- }
- elsif($a[2] eq "off")
- {
- YAMAHA_AVR_SendCommand($hash, "<$zone>Off$zone>");
- }
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>On$zone>");
+ }
+ elsif($a[2] eq "off")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>Off$zone>");
+ }
+ else
+ {
+ return $usage;
+ }
+
+ if(not defined($result) or not $result =~ /RC="0"/)
+ {
+ # if the returncode isn't 0, than the command was not successful
+ return "Could not set enhancer to ".$a[2].".";
+ }
}
- elsif($what eq "remoteControl")
+ elsif($what eq "direct" and exists($hash->{helper}{DIRECT_TAG}))
+ {
+
+ $result = undef;
+
+ if($a[2] eq "on")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone><".$hash->{helper}{DIRECT_TAG}.">On".$hash->{helper}{DIRECT_TAG}.">$zone>");
+ }
+ elsif($a[2] eq "off")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone><".$hash->{helper}{DIRECT_TAG}.">Off".$hash->{helper}{DIRECT_TAG}.">$zone>");
+ }
+ else
+ {
+ return $usage;
+ }
+
+ if(not defined($result) or not $result =~ /RC="0"/)
+ {
+ # if the returncode isn't 0, than the command was not successful
+ return "Could not set direct to ".$a[2].".";
+ }
+ }
+ elsif($what eq "sleep")
{
+ $result = undef;
+
+ if($a[2] eq "off")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>Off$zone>");
+ }
+ elsif($a[2] eq "30min")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>30 min$zone>");
+ }
+ elsif($a[2] eq "60min")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>60 min$zone>");
+ }
+ elsif($a[2] eq "90min")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>90 min$zone>");
+ }
+ elsif($a[2] eq "120min")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>120 min$zone>");
+ }
+ elsif($a[2] eq "last")
+ {
+ $result = YAMAHA_AVR_SendCommand($hash, "<$zone>Last$zone>");
+ }
+ else
+ {
+ return $usage;
+ }
+
+ if(not defined($result) or not $result =~ /RC="0"/)
+ {
+ # if the returncode isn't 0, than the command was not successful
+ return "Could not set sleep timer to ".$a[2].".";
+ }
+ }
+ elsif($what eq "remoteControl")
+ {
+
+ # the RX-Vx75 series use a different tag name to access the remoteControl commands
+ my $control_tag = ($hash->{MODEL} =~ /RX-V\d75/ ? "Cursor_Control" : "List_Control");
- # the RX-Vx75 series use a different tag name to access the remoteControl commands
- my $control_tag = ($hash->{MODEL} =~ /RX-V\d75/ ? "Cursor_Control" : "List_Control");
-
- if($a[2] eq "up")
- {
- YAMAHA_AVR_SendCommand($hash, "<$zone><$control_tag>Up$control_tag>$zone>");
- }
- elsif($a[2] eq "down")
- {
- YAMAHA_AVR_SendCommand($hash, "<$zone><$control_tag>Down$control_tag>$zone>");
- }
- elsif($a[2] eq "left")
- {
- YAMAHA_AVR_SendCommand($hash, "<$zone><$control_tag>Left$control_tag>$zone>");
- }
- elsif($a[2] eq "right")
- {
- YAMAHA_AVR_SendCommand($hash, "<$zone><$control_tag>Right$control_tag>$zone>");
- }
- elsif($a[2] eq "display")
- {
- YAMAHA_AVR_SendCommand($hash,"<$zone><$control_tag>Display$control_tag>$zone>");
- }
- elsif($a[2] eq "return")
- {
- YAMAHA_AVR_SendCommand($hash,"<$zone><$control_tag>Return$control_tag>$zone>");
- }
- elsif($a[2] eq "enter")
- {
- YAMAHA_AVR_SendCommand($hash,"<$zone><$control_tag>Sel$control_tag>$zone>");
- }
- elsif($a[2] eq "setup")
- {
- YAMAHA_AVR_SendCommand($hash,"<$zone><$control_tag>On Screen$control_tag>$zone>");
- }
- elsif($a[2] eq "option")
- {
- YAMAHA_AVR_SendCommand($hash,"<$zone><$control_tag>Option$control_tag>$zone>");
- }
- elsif($a[2] eq "tunerPresetUp")
- {
- YAMAHA_AVR_SendCommand($hash,"Up");
- }
- elsif($a[2] eq "tunerPresetDown")
- {
- YAMAHA_AVR_SendCommand($hash,"Down");
- }
- else
- {
- return $usage;
- }
- }
- elsif($what eq "statusRequest")
- {
- # Will be executed anyway on the end of the function
- }
- else
- {
- return $usage;
- }
+ if($a[2] eq "up")
+ {
+ YAMAHA_AVR_SendCommand($hash, "<$zone><$control_tag>Up$control_tag>$zone>");
+ }
+ elsif($a[2] eq "down")
+ {
+ YAMAHA_AVR_SendCommand($hash, "<$zone><$control_tag>Down$control_tag>$zone>");
+ }
+ elsif($a[2] eq "left")
+ {
+ YAMAHA_AVR_SendCommand($hash, "<$zone><$control_tag>Left$control_tag>$zone>");
+ }
+ elsif($a[2] eq "right")
+ {
+ YAMAHA_AVR_SendCommand($hash, "<$zone><$control_tag>Right$control_tag>$zone>");
+ }
+ elsif($a[2] eq "display")
+ {
+ YAMAHA_AVR_SendCommand($hash,"<$zone><$control_tag>Display$control_tag>$zone>");
+ }
+ elsif($a[2] eq "return")
+ {
+ YAMAHA_AVR_SendCommand($hash,"<$zone><$control_tag>Return$control_tag>$zone>");
+ }
+ elsif($a[2] eq "enter")
+ {
+ YAMAHA_AVR_SendCommand($hash,"<$zone><$control_tag>Sel$control_tag>$zone>");
+ }
+ elsif($a[2] eq "setup")
+ {
+ YAMAHA_AVR_SendCommand($hash,"<$zone><$control_tag>On Screen$control_tag>$zone>");
+ }
+ elsif($a[2] eq "option")
+ {
+ YAMAHA_AVR_SendCommand($hash,"<$zone><$control_tag>Option$control_tag>$zone>");
+ }
+ elsif($a[2] eq "tunerPresetUp")
+ {
+ YAMAHA_AVR_SendCommand($hash,"Up");
+ }
+ elsif($a[2] eq "tunerPresetDown")
+ {
+ YAMAHA_AVR_SendCommand($hash,"Down");
+ }
+ else
+ {
+ return $usage;
+ }
+ }
+ elsif($what eq "statusRequest")
+ {
+ # Will be executed anyway on the end of the function
+ }
+ else
+ {
+ return $usage;
+ }
# Call the GetStatus() Function to retrieve the new values after setting something (with local flag, so the internal timer is not getting interupted)
@@ -792,7 +960,7 @@ YAMAHA_AVR_Define($$)
# In case of a redefine, check the zone parameter if the specified zone exist, otherwise use the main zone
if(defined($hash->{helper}{ZONES}) and length($hash->{helper}{ZONES}) > 0)
{
- if(defined(YAMAHA_AVR_getZoneName($hash, lc $hash->{helper}{SELECTED_ZONE})))
+ if(defined(YAMAHA_AVR_getParamName($hash, lc $hash->{helper}{SELECTED_ZONE}, $hash->{helper}{ZONES})))
{
$hash->{ACTIVE_ZONE} = lc $hash->{helper}{SELECTED_ZONE};
@@ -944,14 +1112,6 @@ sub YAMAHA_AVR_Param2Fhem($$)
}
-#############################
-# Returns the Yamaha Zone Name for the FHEM like zone attribute
-sub YAMAHA_AVR_getZoneName($$)
-{
- my ($hash, $zone) = @_;
- return YAMAHA_AVR_getParamName($hash, $zone, $hash->{helper}{ZONES});
-
-}
#############################
@@ -1038,6 +1198,8 @@ sub YAMAHA_AVR_getModel($)
return undef unless(defined($response));
+ delete($hash->{helper}{ZONES}) if(exists($hash->{helper}{ZONES}));
+
while($response =~ /