2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

71_YAMAHA_AVR: PBP review part 1 - remove prototypes

git-svn-id: https://svn.fhem.de/fhem/trunk@26762 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Beta-User 2022-12-02 07:28:04 +00:00
parent 33fa68fcc4
commit 66ba47c455
2 changed files with 155 additions and 152 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- change: 71_YAMAHA_AVR: PBP code restructured (part I)
- change: 93_DbLog: revise commandref - change: 93_DbLog: revise commandref
- bugfix: 98_vitoconnect: Missing update interval after login failure - bugfix: 98_vitoconnect: Missing update interval after login failure
- bugfix: 73_km200 : Forward declaration made obsolete - bugfix: 73_km200 : Forward declaration made obsolete

View File

@ -34,24 +34,17 @@ use Time::HiRes qw(gettimeofday sleep);
use Encode qw(decode encode); use Encode qw(decode encode);
use HttpUtils; use HttpUtils;
sub YAMAHA_AVR_Get($@);
sub YAMAHA_AVR_Define($$);
sub YAMAHA_AVR_GetStatus($;$);
sub YAMAHA_AVR_Attr(@);
sub YAMAHA_AVR_ResetTimer($;$);
sub YAMAHA_AVR_Undefine($$);
################################### ###################################
sub sub
YAMAHA_AVR_Initialize($) YAMAHA_AVR_Initialize
{ {
my ($hash) = @_; my $hash = shift;
$hash->{GetFn} = "YAMAHA_AVR_Get"; $hash->{GetFn} = \&YAMAHA_AVR_Get;
$hash->{SetFn} = "YAMAHA_AVR_Set"; $hash->{SetFn} = \&YAMAHA_AVR_Set;
$hash->{DefFn} = "YAMAHA_AVR_Define"; $hash->{DefFn} = \&YAMAHA_AVR_Define;
$hash->{AttrFn} = "YAMAHA_AVR_Attr"; $hash->{AttrFn} = \&YAMAHA_AVR_Attr;
$hash->{UndefFn} = "YAMAHA_AVR_Undefine"; $hash->{UndefFn} = \&YAMAHA_AVR_Undefine;
$hash->{AttrList} = "do_not_notify:0,1 ". $hash->{AttrList} = "do_not_notify:0,1 ".
"disable:0,1 ". "disable:0,1 ".
@ -68,50 +61,52 @@ YAMAHA_AVR_Initialize($)
"volume-smooth-change" => "volumeSmoothChange", "volume-smooth-change" => "volumeSmoothChange",
"volume-smooth-steps" => "volumeSmoothSteps" "volume-smooth-steps" => "volumeSmoothSteps"
}; };
return;
} }
############################# #############################
sub sub
YAMAHA_AVR_Define($$) YAMAHA_AVR_Define
{ {
my ($hash, $def) = @_; my $hash = shift // return;
my @a = split("[ \t][ \t]*", $def); my $def = shift // return;
my $name = $hash->{NAME}; my @arr = split m{\s+}xms, $def;
my $name = shift @arr;
if(!@a >= 4) if(@arr < 2)
{ {
my $msg = "wrong syntax: define <name> YAMAHA_AVR <ip-or-hostname> [<zone>] [<ON-statusinterval>] [<OFF-statusinterval>] "; my $msg = 'wrong syntax: define <name> YAMAHA_AVR <ip-or-hostname> [<zone>] [<ON-statusinterval>] [<OFF-statusinterval>] ';
Log3 $name, 2, $msg; Log3($name, 2, $msg);
return $msg; return $msg;
} }
my $address = $a[2]; my $address = $arr[1];
$hash->{helper}{ADDRESS} = $address; $hash->{helper}{ADDRESS} = $address;
# if a zone was given, use it, otherwise use the mainzone # if a zone was given, use it, otherwise use the mainzone
if(defined($a[3])) if(defined($arr[2]))
{ {
$hash->{helper}{SELECTED_ZONE} = $a[3]; $hash->{helper}{SELECTED_ZONE} = $arr[2];
} }
else else
{ {
$hash->{helper}{SELECTED_ZONE} = "mainzone"; $hash->{helper}{SELECTED_ZONE} = 'mainzone';
} }
# if an update interval was given which is greater than zero, use it. # if an update interval was given which is greater than zero, use it.
if(defined($a[4]) and $a[4] > 0) if ( defined $arr[3] && $arr[3] > 0 )
{ {
$hash->{helper}{OFF_INTERVAL} = $a[4]; $hash->{helper}{OFF_INTERVAL} = $arr[3];
} }
else else
{ {
$hash->{helper}{OFF_INTERVAL} = 30; $hash->{helper}{OFF_INTERVAL} = 30;
} }
if(defined($a[5]) and $a[5] > 0) if ( defined $arr[4] && $arr[4] > 0 )
{ {
$hash->{helper}{ON_INTERVAL} = $a[5]; $hash->{helper}{ON_INTERVAL} = $arr[4];
} }
else else
{ {
@ -119,12 +114,12 @@ YAMAHA_AVR_Define($$)
} }
$hash->{helper}{CMD_QUEUE} = []; $hash->{helper}{CMD_QUEUE} = [];
delete($hash->{helper}{".HTTP_CONNECTION"}) if(exists($hash->{helper}{".HTTP_CONNECTION"})); delete $hash->{helper}{".HTTP_CONNECTION"} if exists $hash->{helper}{".HTTP_CONNECTION"};
# In case of a redefine, check the zone parameter if the specified zone exist, otherwise use the main zone # 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 $hash->{helper}{ZONES} && length $hash->{helper}{ZONES} > 0 )
{ {
if(defined(YAMAHA_AVR_getParamName($hash, lc $hash->{helper}{SELECTED_ZONE}, $hash->{helper}{ZONES}))) if ( defined YAMAHA_AVR_getParamName($hash, lc $hash->{helper}{SELECTED_ZONE}, $hash->{helper}{ZONES}) )
{ {
$hash->{ACTIVE_ZONE} = lc $hash->{helper}{SELECTED_ZONE}; $hash->{ACTIVE_ZONE} = lc $hash->{helper}{SELECTED_ZONE};
} }
@ -145,55 +140,56 @@ YAMAHA_AVR_Define($$)
# start the status update timer # start the status update timer
YAMAHA_AVR_ResetTimer($hash,1); YAMAHA_AVR_ResetTimer($hash,1);
return undef; return;
} }
################################### ###################################
sub sub
YAMAHA_AVR_GetStatus($;$) YAMAHA_AVR_GetStatus #($;$)
{ {
my ($hash, $local) = @_; my $hash = shift // return;
my $local = shift // 0;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $power; my $power;
$local = 0 unless(defined($local)); #$local = 0 unless(defined($local));
return "" if(!defined($hash->{helper}{ADDRESS}) or !defined($hash->{helper}{OFF_INTERVAL}) or !defined($hash->{helper}{ON_INTERVAL})); return '' if !defined $hash->{helper}{ADDRESS} || !defined $hash->{helper}{OFF_INTERVAL} || !defined $hash->{helper}{ON_INTERVAL};
my $device = $hash->{helper}{ADDRESS}; my $device = $hash->{helper}{ADDRESS};
# get the model informations and available zones if no informations are available # get the model informations and available zones if no informations are available
if(not defined($hash->{ACTIVE_ZONE}) or not defined($hash->{helper}{ZONES}) or not defined($hash->{MODEL}) or not defined($hash->{FIRMWARE})) if ( !defined $hash->{ACTIVE_ZONE} || !defined $hash->{helper}{ZONES} || !defined$hash->{MODEL} || !defined $hash->{FIRMWARE} )
{ {
YAMAHA_AVR_getModel($hash); YAMAHA_AVR_getModel($hash);
} }
# get all available inputs and scenes if nothing is available # get all available inputs and scenes if nothing is available
if((not defined($hash->{helper}{INPUTS}) or length($hash->{helper}{INPUTS}) == 0)) if( !defined($hash->{helper}{INPUTS}) || length $hash->{helper}{INPUTS} == 0 )
{ {
YAMAHA_AVR_getInputs($hash); YAMAHA_AVR_getInputs($hash);
} }
my $zone = YAMAHA_AVR_getParamName($hash, $hash->{ACTIVE_ZONE}, $hash->{helper}{ZONES}); my $zone = YAMAHA_AVR_getParamName($hash, $hash->{ACTIVE_ZONE}, $hash->{helper}{ZONES});
if(not defined($zone)) if ( !defined $zone )
{ {
YAMAHA_AVR_ResetTimer($hash) unless($local == 1); YAMAHA_AVR_ResetTimer($hash) if $local != 1;
return "No Zone available"; return 'No Zone available';
} }
YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><$zone><Basic_Status>GetParam</Basic_Status></$zone></YAMAHA_AV>", "statusRequest", "basicStatus"); YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><$zone><Basic_Status>GetParam</Basic_Status></$zone></YAMAHA_AV>", "statusRequest", "basicStatus");
if($hash->{ACTIVE_ZONE} eq "mainzone" and (!exists($hash->{helper}{SUPPORT_PARTY_MODE}) or $hash->{helper}{SUPPORT_PARTY_MODE})) if ( $hash->{ACTIVE_ZONE} eq 'mainzone' && ( !exists $hash->{helper}{SUPPORT_PARTY_MODE} || $hash->{helper}{SUPPORT_PARTY_MODE} ) )
{ {
YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Party_Mode><Mode>GetParam</Mode></Party_Mode></System></YAMAHA_AV>", "statusRequest", "partyModeStatus", {options => {can_fail => 1}}); YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Party_Mode><Mode>GetParam</Mode></Party_Mode></System></YAMAHA_AV>", "statusRequest", "partyModeStatus", {options => {can_fail => 1}});
} }
elsif($hash->{ACTIVE_ZONE} ne "mainzone" and (!exists($hash->{helper}{SUPPORT_PARTY_MODE}) or $hash->{helper}{SUPPORT_PARTY_MODE})) elsif ( $hash->{ACTIVE_ZONE} ne 'mainzone' && ( !exists $hash->{helper}{SUPPORT_PARTY_MODE} || $hash->{helper}{SUPPORT_PARTY_MODE} ) )
{ {
YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Party_Mode><Target_Zone>GetParam</Target_Zone></Party_Mode></System></YAMAHA_AV>", "statusRequest", "partyModeZones", {options => {can_fail => 1}}); YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Party_Mode><Target_Zone>GetParam</Target_Zone></Party_Mode></System></YAMAHA_AV>", "statusRequest", "partyModeZones", {options => {can_fail => 1}});
} }
if($hash->{ACTIVE_ZONE} eq "mainzone" and (!exists($hash->{helper}{SUPPORT_SURROUND_DECODER}) or $hash->{helper}{SUPPORT_SURROUND_DECODER})) if ( $hash->{ACTIVE_ZONE} eq 'mainzone' && ( !exists $hash->{helper}{SUPPORT_SURROUND_DECODER} || $hash->{helper}{SUPPORT_SURROUND_DECODER} ) )
{ {
YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><$zone><Surround><Sound_Program_Param><SUR_DECODE>GetParam</SUR_DECODE></Sound_Program_Param></Surround></$zone></YAMAHA_AV>", "statusRequest", "surroundDecoder", {options => {can_fail => 1}}); YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><$zone><Surround><Sound_Program_Param><SUR_DECODE>GetParam</SUR_DECODE></Sound_Program_Param></Surround></$zone></YAMAHA_AV>", "statusRequest", "surroundDecoder", {options => {can_fail => 1}});
} }
@ -254,26 +250,24 @@ YAMAHA_AVR_GetStatus($;$)
YAMAHA_AVR_ResetTimer($hash) unless($local == 1); YAMAHA_AVR_ResetTimer($hash) unless($local == 1);
return undef; return;
} }
################################### ###################################
sub sub
YAMAHA_AVR_Get($@) YAMAHA_AVR_Get #($@)
{ {
my ($hash, @a) = @_; my ($hash, @arr) = @_;
my $what;
my $return;
return "argument is missing" if(int(@a) != 2); return 'argument is missing' if @arr != 2;
$what = $a[1]; my $what = $arr[1];
return ReadingsVal($hash->{NAME}, $what, "") if(defined(ReadingsVal($hash->{NAME}, $what, undef))); return ReadingsVal($hash->{NAME}, $what, '') if defined ReadingsVal($hash->{NAME}, $what, undef);
$return = "unknown argument $what, choose one of"; my $return = "unknown argument $what, choose one of";
foreach my $reading (keys %{$hash->{READINGS}}) for my $reading (keys %{$hash->{READINGS}})
{ {
$return .= " $reading:noArg"; $return .= " $reading:noArg";
} }
@ -284,7 +278,7 @@ YAMAHA_AVR_Get($@)
################################### ###################################
sub sub
YAMAHA_AVR_Set($@) YAMAHA_AVR_Set #($@)
{ {
my ($hash, @a) = @_; my ($hash, @a) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -356,7 +350,7 @@ YAMAHA_AVR_Set($@)
"statusRequest:noArg"; "statusRequest:noArg";
# number of seconds to wait after on/off was executed (DSP based: 3 sec, other models: 2 sec) # number of seconds to wait after on/off was executed (DSP based: 3 sec, other models: 2 sec)
my $powerCmdDelay = (YAMAHA_AVR_isModel_DSP($hash) ? "3" : "2"); my $powerCmdDelay = YAMAHA_AVR_isModel_DSP($hash) ? 3 : 2;
Log3 $name, 5, "YAMAHA_AVR ($name) - set ".join(" ", @a); Log3 $name, 5, "YAMAHA_AVR ($name) - set ".join(" ", @a);
@ -1140,19 +1134,18 @@ YAMAHA_AVR_Set($@)
{ {
return $usage; return $usage;
} }
return;
} }
########################## ##########################
sub sub
YAMAHA_AVR_Attr(@) YAMAHA_AVR_Attr #(@)
{ {
my ($cmd, $name, $attr, $val) = @_; my ($cmd, $name, $attr, $val) = @_;
my $hash = $defs{$name}; my $hash = $defs{$name} // return;
return unless($hash); if($attr eq 'disable')
if($attr eq "disable")
{ {
# Start/Stop Timer according to new disabled-Value # Start/Stop Timer according to new disabled-Value
YAMAHA_AVR_ResetTimer($hash, 1); YAMAHA_AVR_ResetTimer($hash, 1);
@ -1179,15 +1172,15 @@ YAMAHA_AVR_Attr(@)
} }
} }
return;
return undef;
} }
############################# #############################
sub sub
YAMAHA_AVR_Undefine($$) YAMAHA_AVR_Undefine #($$)
{ {
my($hash, $name) = @_; my $hash = shift // return;
my $name = shift // return;
# Stop all timers and exit # Stop all timers and exit
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
@ -1197,7 +1190,7 @@ YAMAHA_AVR_Undefine($$)
delete($modules{YAMAHA_AVR}{defptr}{$hash->{SYSTEM_ID}}{$hash->{ACTIVE_ZONE}}); delete($modules{YAMAHA_AVR}{defptr}{$hash->{SYSTEM_ID}}{$hash->{ACTIVE_ZONE}});
} }
return undef; return;
} }
@ -1243,9 +1236,14 @@ YAMAHA_AVR_Undefine($$)
############################# #############################
# sends a command to the receiver via HTTP # sends a command to the receiver via HTTP
sub sub
YAMAHA_AVR_SendCommand($$$$;$) YAMAHA_AVR_SendCommand #($$$$;$)
{ {
my ($hash, $data,$cmd,$arg,$additional_args) = @_; #my ($hash, $data,$cmd,$arg,$additional_args) = @_;
my $hash = shift // return;
my $data = shift // return;
my $cmd = shift // return;
my $arg = shift // return;
my $additional_args = shift; #if set, this should be HASH type arg
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $options; my $options;
@ -1302,16 +1300,15 @@ YAMAHA_AVR_SendCommand($$$$;$)
} }
YAMAHA_AVR_HandleCmdQueue($device); YAMAHA_AVR_HandleCmdQueue($device);
return;
return undef;
} }
############################# #############################
# starts http requests from cmd queue # starts http requests from cmd queue
sub sub
YAMAHA_AVR_HandleCmdQueue($) YAMAHA_AVR_HandleCmdQueue #($)
{ {
my ($hash) = @_; my $hash = shift // return;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $address = $hash->{helper}{ADDRESS}; my $address = $hash->{helper}{ADDRESS};
@ -1331,16 +1328,16 @@ YAMAHA_AVR_HandleCmdQueue($)
my $request = YAMAHA_AVR_getNextRequestHash($hash); my $request = YAMAHA_AVR_getNextRequestHash($hash);
unless(defined($request)) if ( !defined $request )
{ {
# still request in queue, but not mentioned to be executed now # still request in queue, but not mentioned to be executed now
Log3 $name, 5, "YAMAHA_AVR ($name) - still requests in queue, but no command shall be executed at the moment. Retry in 1 second."; Log3 $name, 5, "YAMAHA_AVR ($name) - still requests in queue, but no command shall be executed at the moment. Retry in 1 second.";
RemoveInternalTimer($hash, "YAMAHA_AVR_HandleCmdQueue"); RemoveInternalTimer($hash, "YAMAHA_AVR_HandleCmdQueue");
InternalTimer(gettimeofday()+1,"YAMAHA_AVR_HandleCmdQueue", $hash); InternalTimer(gettimeofday()+1,"YAMAHA_AVR_HandleCmdQueue", $hash);
return undef; return;
} }
$request->{options}{priority} = 3 unless(exists($request->{options}{priority})); $request->{options}{priority} = 3 if !exists $request->{options}{priority};
delete($request->{data}) if(exists($request->{data}) and !$request->{data}); delete($request->{data}) if(exists($request->{data}) and !$request->{data});
$request->{data}=~ s/\[CURRENT_INPUT_TAG\]/$hash->{helper}{CURRENT_INPUT_TAG}/g if(exists($request->{data}) and exists($hash->{helper}{CURRENT_INPUT_TAG})); $request->{data}=~ s/\[CURRENT_INPUT_TAG\]/$hash->{helper}{CURRENT_INPUT_TAG}/g if(exists($request->{data}) and exists($hash->{helper}{CURRENT_INPUT_TAG}));
@ -1367,14 +1364,14 @@ YAMAHA_AVR_HandleCmdQueue($)
$hash->{CMDs_pending} = @{$hash->{helper}{CMD_QUEUE}}; $hash->{CMDs_pending} = @{$hash->{helper}{CMD_QUEUE}};
delete($hash->{CMDs_pending}) unless($hash->{CMDs_pending}); delete($hash->{CMDs_pending}) unless($hash->{CMDs_pending});
return undef; return;
} }
############################# #############################
# selects the next command from command queue that has to be executed (undef if no command has to be executed now) # selects the next command from command queue that has to be executed (undef if no command has to be executed now)
sub YAMAHA_AVR_getNextRequestHash($) sub YAMAHA_AVR_getNextRequestHash #($)
{ {
my ($hash) = @_; my $hash = shift // return;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
if(@{$hash->{helper}{CMD_QUEUE}}) if(@{$hash->{helper}{CMD_QUEUE}})
@ -1451,16 +1448,18 @@ sub YAMAHA_AVR_getNextRequestHash($)
} }
Log3 $name, 5, "YAMAHA_AVR ($name) - no suitable command item found"; Log3 $name, 5, "YAMAHA_AVR ($name) - no suitable command item found";
return undef; return;
} }
} }
############################# #############################
# parses the receiver response # parses the receiver response
sub sub
YAMAHA_AVR_ParseResponse($$$) YAMAHA_AVR_ParseResponse #($$$)
{ {
my ( $param, $err, $data ) = @_; my $param = shift // return;
my $err = shift // q{};
my $data = shift // q{};
my $hash = $param->{hash}; my $hash = $param->{hash};
my $queue_hash = $param->{hash}; my $queue_hash = $param->{hash};
@ -1469,9 +1468,6 @@ YAMAHA_AVR_ParseResponse($$$)
my $arg = $param->{arg}; my $arg = $param->{arg};
my $options = $param->{options}; my $options = $param->{options};
$data = "" unless(defined($data));
$err = "" unless(defined($err));
$hash->{helper}{RUNNING_REQUEST} = 0; $hash->{helper}{RUNNING_REQUEST} = 0;
delete($hash->{helper}{".HTTP_CONNECTION"}) unless($param->{keepalive}); delete($hash->{helper}{".HTTP_CONNECTION"}) unless($param->{keepalive});
@ -2130,7 +2126,7 @@ YAMAHA_AVR_ParseResponse($$$)
Log3 $name, 4 ,"YAMAHA_AVR ($name) - menu browsing to $arg is finished. requesting basic status"; Log3 $name, 4 ,"YAMAHA_AVR ($name) - menu browsing to $arg is finished. requesting basic status";
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
YAMAHA_AVR_GetStatus($hash, 1); YAMAHA_AVR_GetStatus($hash, 1);
return undef; return;
} }
# initialization sequence # initialization sequence
@ -2260,37 +2256,37 @@ YAMAHA_AVR_ParseResponse($$$)
} }
YAMAHA_AVR_HandleCmdQueue($queue_hash); YAMAHA_AVR_HandleCmdQueue($queue_hash);
return;
} }
############################# #############################
# Converts all Values to FHEM usable command lists # Converts all Values to FHEM usable command lists
sub YAMAHA_AVR_Param2Fhem($$) sub YAMAHA_AVR_Param2Fhem #($$)
{ {
my ($param, $replace_pipes) = @_; my $param = shift // return;
my $replace_pipes = shift;
$param =~ s/\s+//g; $param =~ s/\s+//g;
$param =~ s/,//g; $param =~ s/,//g;
$param =~ s/_//g; $param =~ s/_//g;
$param =~ s/\(/_/g; $param =~ s/\(/_/g;
$param =~ s/\)//g; $param =~ s/\)//g;
$param =~ s/\|/,/g if($replace_pipes == 1); $param =~ s/\|/,/g if $replace_pipes;
return lc $param; return lc $param;
} }
############################# #############################
# Returns the Yamaha Parameter Name for the FHEM like aquivalents # Returns the Yamaha Parameter Name for the FHEM like aquivalents
sub YAMAHA_AVR_getParamName($$$) sub YAMAHA_AVR_getParamName #($$$)
{ {
my ($hash, $name, $list) = @_; my $hash = shift // return;
my $item; my $name = shift // return;
my $list = shift // return;
return undef if(not defined($list));
my @commands = split("\\|", $list); my @commands = split("\\|", $list);
foreach $item (@commands) for my $item (@commands)
{ {
if(YAMAHA_AVR_Param2Fhem($item, 0) eq $name) if(YAMAHA_AVR_Param2Fhem($item, 0) eq $name)
{ {
@ -2298,25 +2294,29 @@ sub YAMAHA_AVR_getParamName($$$)
} }
} }
return undef; return;
} }
############################# #############################
# queries the receiver model, system-id, version and all available zones # queries the receiver model, system-id, version and all available zones
sub YAMAHA_AVR_getModel($) sub YAMAHA_AVR_getModel #($)
{ {
my ($hash) = @_; my $hash = shift // return;
YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Config>GetParam</Config></System></YAMAHA_AV>", "statusRequest","systemConfig", {options => {at_first => 1, priority => 1}}); YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Config>GetParam</Config></System></YAMAHA_AV>", "statusRequest","systemConfig", {options => {at_first => 1, priority => 1}});
YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Unit_Desc>GetParam</Unit_Desc></System></YAMAHA_AV>", "statusRequest","unitDescription", {options => {at_first => 1, priority => 1}}); YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><System><Unit_Desc>GetParam</Unit_Desc></System></YAMAHA_AV>", "statusRequest","unitDescription", {options => {at_first => 1, priority => 1}});
return;
} }
############################# #############################
# parses the HTTP response for unit description XML file # parses the HTTP response for unit description XML file
sub sub
YAMAHA_AVR_ParseXML($$$) YAMAHA_AVR_ParseXML #($$$)
{ {
my ($param, $err, $data) = @_; my $param = shift // return;
my $err = shift // return;
my $data = shift // return;
my $hash = $param->{hash}; my $hash = $param->{hash};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -2326,10 +2326,10 @@ YAMAHA_AVR_ParseXML($$$)
$hash->{helper}{RUNNING_REQUEST} = 0; $hash->{helper}{RUNNING_REQUEST} = 0;
delete($hash->{helper}{".HTTP_CONNECTION"}) unless($param->{keepalive}); delete($hash->{helper}{".HTTP_CONNECTION"}) unless($param->{keepalive});
if($data eq "") if($data eq '')
{ {
YAMAHA_AVR_HandleCmdQueue($hash); YAMAHA_AVR_HandleCmdQueue($hash);
return undef return;
} }
delete($hash->{helper}{ZONES}) if(exists($hash->{helper}{ZONES})); delete($hash->{helper}{ZONES}) if(exists($hash->{helper}{ZONES}));
@ -2460,13 +2460,14 @@ YAMAHA_AVR_ParseXML($$$)
$modules{YAMAHA_AVR}{defptr}{$hash->{SYSTEM_ID}}{$hash->{ACTIVE_ZONE}} = $hash if(exists($hash->{SYSTEM_ID}) and exists($hash->{ACTIVE_ZONE})); $modules{YAMAHA_AVR}{defptr}{$hash->{SYSTEM_ID}}{$hash->{ACTIVE_ZONE}} = $hash if(exists($hash->{SYSTEM_ID}) and exists($hash->{ACTIVE_ZONE}));
YAMAHA_AVR_HandleCmdQueue($hash); YAMAHA_AVR_HandleCmdQueue($hash);
return;
} }
############################# #############################
# converts decibal volume in percentage volume (-80.5 .. 16.5dB => 0 .. 100%) # converts decibal volume in percentage volume (-80.5 .. 16.5dB => 0 .. 100%)
sub YAMAHA_AVR_volume_rel2abs($) sub YAMAHA_AVR_volume_rel2abs #($)
{ {
my ($percentage) = @_; my $percentage = shift;
# 0 - 100% -equals 80.5 to 16.5 dB # 0 - 100% -equals 80.5 to 16.5 dB
return int((($percentage / 100 * 97) - 80.5) / 0.5) * 0.5; return int((($percentage / 100 * 97) - 80.5) / 0.5) * 0.5;
@ -2474,9 +2475,9 @@ sub YAMAHA_AVR_volume_rel2abs($)
############################# #############################
# converts percentage volume in decibel volume (0 .. 100% => -80.5 .. 16.5dB) # converts percentage volume in decibel volume (0 .. 100% => -80.5 .. 16.5dB)
sub YAMAHA_AVR_volume_abs2rel($) sub YAMAHA_AVR_volume_abs2rel #($)
{ {
my ($absolute) = @_; my $absolute = shift // return;
# -80.5 to 16.5 dB equals 0 - 100% # -80.5 to 16.5 dB equals 0 - 100%
return int(($absolute + 80.5) / 97 * 100); return int(($absolute + 80.5) / 97 * 100);
@ -2484,35 +2485,36 @@ sub YAMAHA_AVR_volume_abs2rel($)
############################# #############################
# queries all available inputs and scenes # queries all available inputs and scenes
sub YAMAHA_AVR_getInputs($) sub YAMAHA_AVR_getInputs #($)
{ {
my ($hash) = @_; my $hash = shift // return;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $address = $hash->{helper}{ADDRESS}; my $address = $hash->{helper}{ADDRESS};
my $zone = YAMAHA_AVR_getParamName($hash, $hash->{ACTIVE_ZONE}, $hash->{helper}{ZONES}); my $zone = YAMAHA_AVR_getParamName($hash, $hash->{ACTIVE_ZONE}, $hash->{helper}{ZONES});
return undef if(not defined($zone) or $zone eq ""); return if !defined $zone || $zone eq '';
# query all inputs # query all inputs
YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><$zone><Input><Input_Sel_Item>GetParam</Input_Sel_Item></Input></$zone></YAMAHA_AV>", "statusRequest","getInputs", {options => {at_first => 1, priority => 1}}); YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><$zone><Input><Input_Sel_Item>GetParam</Input_Sel_Item></Input></$zone></YAMAHA_AV>", "statusRequest","getInputs", {options => {at_first => 1, priority => 1}});
# query all available scenes (only in mainzone available) # query all available scenes (only in mainzone available)
YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><$zone><Scene><Scene_Sel_Item>GetParam</Scene_Sel_Item></Scene></$zone></YAMAHA_AV>", "statusRequest","getScenes", {options => {can_fail => 1, at_first => 1, priority => 1}}) if($hash->{ACTIVE_ZONE} eq "mainzone"); YAMAHA_AVR_SendCommand($hash, "<YAMAHA_AV cmd=\"GET\"><$zone><Scene><Scene_Sel_Item>GetParam</Scene_Sel_Item></Scene></$zone></YAMAHA_AV>", "statusRequest","getScenes", {options => {can_fail => 1, at_first => 1, priority => 1}}) if $hash->{ACTIVE_ZONE} eq 'mainzone';
return;
} }
############################# #############################
# Restarts the internal status request timer according to the given interval or current receiver state # Restarts the internal status request timer according to the given interval or current receiver state
sub YAMAHA_AVR_ResetTimer($;$) sub YAMAHA_AVR_ResetTimer #($;$)
{ {
my ($hash, $interval) = @_; my $hash = shift // return;
my $interval = shift;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
RemoveInternalTimer($hash, "YAMAHA_AVR_GetStatus"); RemoveInternalTimer($hash, "YAMAHA_AVR_GetStatus");
unless(IsDisabled($name)) return if IsDisabled($name);
{ if ( defined $interval )
if(defined($interval))
{ {
InternalTimer(gettimeofday()+$interval, "YAMAHA_AVR_GetStatus", $hash); InternalTimer(gettimeofday()+$interval, "YAMAHA_AVR_GetStatus", $hash);
} }
@ -2524,16 +2526,15 @@ sub YAMAHA_AVR_ResetTimer($;$)
{ {
InternalTimer(gettimeofday()+$hash->{helper}{OFF_INTERVAL}, "YAMAHA_AVR_GetStatus", $hash); InternalTimer(gettimeofday()+$hash->{helper}{OFF_INTERVAL}, "YAMAHA_AVR_GetStatus", $hash);
} }
}
return undef; return;
} }
############################# #############################
# convert all HTML entities into UTF-8 aquivalents # convert all HTML entities into UTF-8 aquivalents
sub YAMAHA_AVR_html2txt($) sub YAMAHA_AVR_html2txt #($)
{ {
my ($string) = @_; my $string = shift // return '';
$string =~ s/&amp;/&/g; $string =~ s/&amp;/&/g;
$string =~ s/&amp;/&/g; $string =~ s/&amp;/&/g;
@ -2560,11 +2561,11 @@ sub YAMAHA_AVR_html2txt($)
return $string; return $string;
} }
sub YAMAHA_AVR_generateSurroundDecoderList($) sub YAMAHA_AVR_generateSurroundDecoderList #($)
{ {
my ($hash) = @_; my $hash = shift // return;
if(defined($hash->{MODEL})) if ( defined $hash->{MODEL} )
{ {
if($hash->{MODEL} =~ /^(?:RX-V[67]79|RX-A750|RX-AS710D?)$/) # RX-V679, RX-V779, RX-A750, RX-AS710, RX-AS710D (from RX-Vx79/RX-Ax50 series) if($hash->{MODEL} =~ /^(?:RX-V[67]79|RX-A750|RX-AS710D?)$/) # RX-V679, RX-V779, RX-A750, RX-AS710, RX-AS710D (from RX-Vx79/RX-Ax50 series)
{ {
@ -2583,15 +2584,16 @@ sub YAMAHA_AVR_generateSurroundDecoderList($)
$hash->{helper}{SURROUND_DECODERS} = "Dolby PL|Dolby PLII Movie|Dolby PLII Music|Dolby PLII Game|Dolby PLIIx Movie|Dolby PLIIx Music|Dolby PLIIx Game|DTS NEO:6 Cinema|DTS NEO:6 Music"; $hash->{helper}{SURROUND_DECODERS} = "Dolby PL|Dolby PLII Movie|Dolby PLII Music|Dolby PLII Game|Dolby PLIIx Movie|Dolby PLIIx Music|Dolby PLIIx Game|DTS NEO:6 Cinema|DTS NEO:6 Music";
} }
} }
return;
} }
############################# #############################
# Check if amp is one of these models: DSP-Z7, DSP-Z9, DSP-Z11, RX-Z7, RX-Z9, RX-Z11, RX-V2065, RX-V3900, DSP-AX3900 # Check if amp is one of these models: DSP-Z7, DSP-Z9, DSP-Z11, RX-Z7, RX-Z9, RX-Z11, RX-V2065, RX-V3900, DSP-AX3900
# Tested models: DSP-Z7 # Tested models: DSP-Z7
sub YAMAHA_AVR_isModel_DSP($) sub YAMAHA_AVR_isModel_DSP #($)
{ {
my($hash) = @_; my $hash = shift // return;
if(exists($hash->{MODEL}) && (($hash->{MODEL} =~ /DSP-Z/) || ($hash->{MODEL} =~ /RX-Z/) || ($hash->{MODEL} =~ /RX-V2065/) || ($hash->{MODEL} =~ /RX-V3900/) || ($hash->{MODEL} =~ /DSP-AX3900/))) if(exists($hash->{MODEL}) && (($hash->{MODEL} =~ /DSP-Z/) || ($hash->{MODEL} =~ /RX-Z/) || ($hash->{MODEL} =~ /RX-V2065/) || ($hash->{MODEL} =~ /RX-V3900/) || ($hash->{MODEL} =~ /DSP-AX3900/)))
{ {