70_PIONEERAVR.pm: Volume fix (was off by 1) - code cleanup: foreach -> for

71_PIONEERAVRZONE.pm: Volume fix (was off by 1) - code cleanup: foreach -> for

git-svn-id: https://svn.fhem.de/fhem/trunk@22807 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
50watt 2020-09-20 19:31:17 +00:00
parent 49a8b90d30
commit 33fa579656
2 changed files with 29 additions and 29 deletions

View File

@ -1337,7 +1337,7 @@ sub PIONEERAVR_Undef {
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
# deleting port for clients # deleting port for clients
foreach my $d ( sort keys %defs ) { for my $d ( sort keys %defs ) {
if ( defined( $defs{$d} ) if ( defined( $defs{$d} )
&& defined( $defs{$d}{IODev} ) && defined( $defs{$d}{IODev} )
&& $defs{$d}{IODev} == $hash ) && $defs{$d}{IODev} == $hash )
@ -1399,7 +1399,7 @@ sub PIONEERAVR_Notify {
# work on global events related to us # work on global events related to us
if ( $devName eq "global" ) { if ( $devName eq "global" ) {
foreach my $change ( @{ $dev->{CHANGED} } ) { for my $change ( @{ $dev->{CHANGED} } ) {
if ( $change !~ /^(\w+)\s(\w+)\s?(\w*)\s?(.*)$/ if ( $change !~ /^(\w+)\s(\w+)\s?(\w*)\s?(.*)$/
|| $2 ne $name ) || $2 ne $name )
{ {
@ -1441,7 +1441,7 @@ sub PIONEERAVR_Notify {
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
foreach my $change ( @{ $dev->{CHANGED} } ) { for my $change ( @{ $dev->{CHANGED} } ) {
# DISCONNECTED # DISCONNECTED
if ( $change eq "DISCONNECTED" ) { if ( $change eq "DISCONNECTED" ) {
@ -1593,7 +1593,7 @@ sub PIONEERAVR_Set {
# get all input names (preferable the aliasName) of the enabled inputs for the drop down list of "set <device> input xxx" # get all input names (preferable the aliasName) of the enabled inputs for the drop down list of "set <device> input xxx"
my @listInputNames = (); my @listInputNames = ();
foreach my $key ( keys %{ $hash->{helper}{INPUTNAMES} } ) { for my $key ( keys %{ $hash->{helper}{INPUTNAMES} } ) {
if ( defined( $hash->{helper}{INPUTNAMES}->{$key}{enabled} ) ) { if ( defined( $hash->{helper}{INPUTNAMES}->{$key}{enabled} ) ) {
if ( $hash->{helper}{INPUTNAMES}->{$key}{enabled} eq "1" ) { if ( $hash->{helper}{INPUTNAMES}->{$key}{enabled} eq "1" ) {
if ( $hash->{helper}{INPUTNAMES}{$key}{aliasName} ) { if ( $hash->{helper}{INPUTNAMES}{$key}{aliasName} ) {
@ -1820,7 +1820,7 @@ sub PIONEERAVR_Set {
} }
elsif ( $cmd eq "input" ) { elsif ( $cmd eq "input" ) {
Log3 $name, 5, "PIONEERAVR $name: set $cmd " . dq($arg); Log3 $name, 5, "PIONEERAVR $name: set $cmd " . dq($arg);
foreach my $key ( keys %{ $hash->{helper}{INPUTNAMES} } ) { for my $key ( keys %{ $hash->{helper}{INPUTNAMES} } ) {
if ( defined $hash->{helper}{INPUTNAMES}->{$key}{aliasName} ) { if ( defined $hash->{helper}{INPUTNAMES}->{$key}{aliasName} ) {
if ( if (
$hash->{helper}{INPUTNAMES}->{$key}{aliasName} eq $arg ) $hash->{helper}{INPUTNAMES}->{$key}{aliasName} eq $arg )
@ -1839,7 +1839,7 @@ sub PIONEERAVR_Set {
} }
elsif ( $cmd eq "hdmiOut" ) { elsif ( $cmd eq "hdmiOut" ) {
Log3 $name, 5, "PIONEERAVR $name: set $cmd " . dq($arg); Log3 $name, 5, "PIONEERAVR $name: set $cmd " . dq($arg);
foreach my $key ( keys %{ $hash->{helper}{HDMIOUT} } ) { for my $key ( keys %{ $hash->{helper}{HDMIOUT} } ) {
if ( $hash->{helper}{LISTENINGMODES}->{$key} eq $arg ) { if ( $hash->{helper}{LISTENINGMODES}->{$key} eq $arg ) {
Log3 $name, 5, Log3 $name, 5,
"PIONEERAVR $name: set $cmd " "PIONEERAVR $name: set $cmd "
@ -1861,7 +1861,7 @@ sub PIONEERAVR_Set {
} }
elsif ( $cmd eq "listeningMode" ) { elsif ( $cmd eq "listeningMode" ) {
Log3 $name, 5, "PIONEERAVR $name: set $cmd " . dq($arg); Log3 $name, 5, "PIONEERAVR $name: set $cmd " . dq($arg);
foreach my $key ( keys %{ $hash->{helper}{LISTENINGMODES} } ) { for my $key ( keys %{ $hash->{helper}{LISTENINGMODES} } ) {
if ( $hash->{helper}{LISTENINGMODES}->{$key} eq $arg ) { if ( $hash->{helper}{LISTENINGMODES}->{$key} eq $arg ) {
Log3 $name, 5, Log3 $name, 5,
"PIONEERAVR $name: set $cmd " "PIONEERAVR $name: set $cmd "
@ -1916,11 +1916,11 @@ sub PIONEERAVR_Set {
# PioneerAVR expects values between 000 - 185 # PioneerAVR expects values between 000 - 185
} }
elsif ( $cmd eq "volume" ) { elsif ( $cmd eq "volume" ) {
if ( AttrVal( $name, "volumeLimit", 100 ) < $arg ) { if ( AttrVal( $name, "volumeLimit", 100 ) < $arg ) {
$arg = AttrVal( $name, "volumeLimit", 100 ); $arg = AttrVal( $name, "volumeLimit", 100 );
} }
Log3 $name, 5, "PIONEERAVR $name: set $cmd " . dq($arg); Log3 $name, 5, "PIONEERAVR $name: set $cmd " . dq($arg);
my $pioneerVol = sprintf "%d", $arg * 1.85; my $pioneerVol = sprintf "%.0f", $arg * 1.85;
if ( AttrVal( $name, "alternateVolumeControl", "disable" ) eq if ( AttrVal( $name, "alternateVolumeControl", "disable" ) eq
"enable" ) "enable" )
{ {
@ -2177,7 +2177,7 @@ sub PIONEERAVR_Set {
Log3 $name, 5, Log3 $name, 5,
"PIONEERAVR $name: set $cmd for inputName: $arg new name: $arg2 !"; "PIONEERAVR $name: set $cmd for inputName: $arg new name: $arg2 !";
my $inputToChange = undef; my $inputToChange = undef;
foreach my $key ( keys %{ $hash->{helper}{INPUTNAMES} } ) { for my $key ( keys %{ $hash->{helper}{INPUTNAMES} } ) {
if ( $hash->{helper}{INPUTNAMES}->{$key}{aliasName} eq $arg ) { if ( $hash->{helper}{INPUTNAMES}->{$key}{aliasName} eq $arg ) {
$inputToChange = sprintf "%02d", $key; $inputToChange = sprintf "%02d", $key;
} }
@ -2201,7 +2201,7 @@ sub PIONEERAVR_Set {
Log3 $name, 5, Log3 $name, 5,
"PIONEERAVR $name: set $cmd for inputName: $arg skip: $arg2 !"; "PIONEERAVR $name: set $cmd for inputName: $arg skip: $arg2 !";
my $inputToChange = undef; my $inputToChange = undef;
foreach my $key ( keys %{ $hash->{helper}{INPUTNAMES} } ) { for my $key ( keys %{ $hash->{helper}{INPUTNAMES} } ) {
if ( $hash->{helper}{INPUTNAMES}->{$key}{aliasName} eq $arg ) { if ( $hash->{helper}{INPUTNAMES}->{$key}{aliasName} eq $arg ) {
$inputToChange = sprintf "%02d", $key; $inputToChange = sprintf "%02d", $key;
} }
@ -2308,7 +2308,7 @@ sub PIONEERAVR_Get {
} }
elsif ( !defined( $hash->{helper}{GETS}{main}{$cmd} ) ) { elsif ( !defined( $hash->{helper}{GETS}{main}{$cmd} ) ) {
my $gets = ""; my $gets = "";
foreach my $key ( keys %{ $hash->{helper}{GETS}{main} } ) { for my $key ( keys %{ $hash->{helper}{GETS}{main} } ) {
$gets .= $key . ":noArg "; $gets .= $key . ":noArg ";
} }
return return
@ -2395,7 +2395,7 @@ sub PIONEERAVR_Read {
my $volume_st = $volume / 2 - 80.5; my $volume_st = $volume / 2 - 80.5;
my $volume_vl = $volume / 1.85; my $volume_vl = $volume / 1.85;
readingsBulkUpdate( $hash, "volumeStraight", $volume_st ); readingsBulkUpdate( $hash, "volumeStraight", $volume_st );
readingsBulkUpdate( $hash, "volume", sprintf "%d", $volume_vl ); readingsBulkUpdate( $hash, "volume", sprintf "%.0f", $volume_vl );
Log3 $name, 5, Log3 $name, 5,
"PIONEERAVR $name: " "PIONEERAVR $name: "
. dq($line) . dq($line)
@ -2664,14 +2664,14 @@ m/^(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(
$hash->{helper}{main}{CURINPUTNR} = $inputNr; $hash->{helper}{main}{CURINPUTNR} = $inputNr;
# clear screen information on input change... # clear screen information on input change...
foreach my $key ( keys %{ $hash->{helper}{CLEARONINPUTCHANGE} } ) { for my $key ( keys %{ $hash->{helper}{CLEARONINPUTCHANGE} } ) {
readingsBulkUpdate( $hash, readingsBulkUpdate( $hash,
$hash->{helper}{CLEARONINPUTCHANGE}->{$key}, "" ); $hash->{helper}{CLEARONINPUTCHANGE}->{$key}, "" );
Log3 $hash, 5, Log3 $hash, 5,
"PIONEERAVR $name: Main Input change ... clear screen... reading:" "PIONEERAVR $name: Main Input change ... clear screen... reading:"
. $hash->{helper}{CLEARONINPUTCHANGE}->{$key}; . $hash->{helper}{CLEARONINPUTCHANGE}->{$key};
} }
foreach my $key ( keys %{ $hash->{helper}{CLEARONINPUTCHANGE} } ) { for my $key ( keys %{ $hash->{helper}{CLEARONINPUTCHANGE} } ) {
readingsBulkUpdate( $hash, readingsBulkUpdate( $hash,
$hash->{helper}{CLEARONINPUTCHANGE}->{$key}, "" ); $hash->{helper}{CLEARONINPUTCHANGE}->{$key}, "" );
Log3 $hash, 5, Log3 $hash, 5,
@ -4193,8 +4193,8 @@ sub PIONEERAVR_statusUpdate {
Log3 $name, 5, "PIONEERAVR $name: PIONEERAVR_statusUpdate()"; Log3 $name, 5, "PIONEERAVR $name: PIONEERAVR_statusUpdate()";
foreach my $zone ( keys %{ $hash->{helper}{GETS} } ) { for my $zone ( keys %{ $hash->{helper}{GETS} } ) {
foreach my $key ( keys %{ $hash->{helper}{GETS}{$zone} } ) { for my $key ( keys %{ $hash->{helper}{GETS}{$zone} } ) {
PIONEERAVR_Write( $hash, $hash->{helper}{GETS}->{$zone}->{$key} ); PIONEERAVR_Write( $hash, $hash->{helper}{GETS}->{$zone}->{$key} );
sleep(0.1); sleep(0.1);
} }

View File

@ -126,7 +126,7 @@ sub PIONEERAVRZONE_Set {
# get all input names (preferable the aliasName) of the enabled inputs for the drop down list of "set <device> input xxx" # get all input names (preferable the aliasName) of the enabled inputs for the drop down list of "set <device> input xxx"
my @listInputNames = (); my @listInputNames = ();
foreach my $key ( keys %{ $IOhash->{helper}{INPUTNAMES} } ) { for my $key ( keys %{ $IOhash->{helper}{INPUTNAMES} } ) {
if ( defined( $IOhash->{helper}{INPUTNAMES}->{$key}{enabled} ) ) { if ( defined( $IOhash->{helper}{INPUTNAMES}->{$key}{enabled} ) ) {
if ( $IOhash->{helper}{INPUTNAMES}->{$key}{enabled} eq "1" ) { if ( $IOhash->{helper}{INPUTNAMES}->{$key}{enabled} eq "1" ) {
if ( $IOhash->{helper}{INPUTNAMES}{$key}{aliasName} ) { if ( $IOhash->{helper}{INPUTNAMES}{$key}{aliasName} ) {
@ -201,7 +201,7 @@ sub PIONEERAVRZONE_Set {
} }
elsif ( $cmd eq "statusRequest" ) { elsif ( $cmd eq "statusRequest" ) {
Log3 $name, 5, "PIONEERAVR $name: Set $cmd "; Log3 $name, 5, "PIONEERAVR $name: Set $cmd ";
foreach my $key ( keys %{ $IOhash->{helper}{GETS}{$zone} } ) { for my $key ( keys %{ $IOhash->{helper}{GETS}{$zone} } ) {
IOWrite( $hash, $IOhash->{helper}{GETS}->{$zone}->{$key} ); IOWrite( $hash, $IOhash->{helper}{GETS}->{$zone}->{$key} );
} }
return; return;
@ -215,7 +215,7 @@ sub PIONEERAVRZONE_Set {
if ( $cmd eq "input" ) { if ( $cmd eq "input" ) {
Log3 $name, 5, "PIONEERAVRZONE $name: set $cmd " . dq($arg); Log3 $name, 5, "PIONEERAVRZONE $name: set $cmd " . dq($arg);
foreach my $key ( keys %{ $IOhash->{helper}{INPUTNAMES} } ) { for my $key ( keys %{ $IOhash->{helper}{INPUTNAMES} } ) {
if ( $IOhash->{helper}{INPUTNAMES}->{$key}{aliasName} eq $arg ) if ( $IOhash->{helper}{INPUTNAMES}->{$key}{aliasName} eq $arg )
{ {
if ( $zone eq "zone2" ) { if ( $zone eq "zone2" ) {
@ -255,15 +255,15 @@ sub PIONEERAVRZONE_Set {
} }
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate( $hash, "volumeStraight", $arg ); readingsBulkUpdate( $hash, "volumeStraight", $arg );
readingsBulkUpdate( $hash, "volume", sprintf "%d", readingsBulkUpdate( $hash, "volume", sprintf "%.0f",
( $a[2] + 80 ) / 0.8 ); ( $a[2] + 80 ) / 0.81 );
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
return; return;
####Volume (0 - 100) in % ####Volume (0 - 100) in %
####according to http://www.fhemwiki.de/wiki/DevelopmentGuidelinesAV ####according to http://www.fhemwiki.de/wiki/DevelopmentGuidelinesAV
} }
elsif ( $cmd eq "volume" ) { elsif ( $cmd eq "volume" ) {
$zahl = sprintf "%d", $arg * 0.8; $zahl = sprintf "%.0f", $arg * 0.81;
if ( $zone eq "zone2" ) { if ( $zone eq "zone2" ) {
IOWrite( $hash, sprintf "%02dZV", $zahl ); IOWrite( $hash, sprintf "%02dZV", $zahl );
} }
@ -272,7 +272,7 @@ sub PIONEERAVRZONE_Set {
} }
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate( $hash, "volumeStraight", $zahl - 80 ); readingsBulkUpdate( $hash, "volumeStraight", $zahl - 80 );
readingsBulkUpdate( $hash, "volume", sprintf "%d", $a[2] ); readingsBulkUpdate( $hash, "volume", sprintf "%.0f", $a[2] );
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
return; return;
####Mute (on|off|toggle) ####Mute (on|off|toggle)
@ -318,7 +318,7 @@ sub PIONEERAVRZONE_Parse {
#Debug "Trying to find a match for \"" . escapeLogLine($msg) ."\""; #Debug "Trying to find a match for \"" . escapeLogLine($msg) ."\"";
# walk over all clients # walk over all clients
foreach my $d ( keys %defs ) { for my $d ( keys %defs ) {
my $hash = $defs{$d}; my $hash = $defs{$d};
if ( $hash->{TYPE} eq "PIONEERAVRZONE" && $hash->{IODev} eq $IOhash ) { if ( $hash->{TYPE} eq "PIONEERAVRZONE" && $hash->{IODev} eq $IOhash ) {
my $zone = $hash->{helper}{ZONE}; my $zone = $hash->{helper}{ZONE};
@ -338,8 +338,8 @@ sub PIONEERAVRZONE_Parse {
. $1 . $1
. " (raw volume data)."; . " (raw volume data).";
readingsBulkUpdate( $hash, "volumeStraight", $1 - 81 ); readingsBulkUpdate( $hash, "volumeStraight", $1 - 81 );
readingsBulkUpdate( $hash, "volume", sprintf "%d", readingsBulkUpdate( $hash, "volume", sprintf "%.0f",
$1 / 0.8 ); $1 / 0.81 );
push @matches, $d; push @matches, $d;
# Mute zone2 # Mute zone2
@ -447,8 +447,8 @@ sub PIONEERAVRZONE_Parse {
. $1 . $1
. " (raw volume data)."; . " (raw volume data).";
readingsBulkUpdate( $hash, "volumeStraight", $1 - 81 ); readingsBulkUpdate( $hash, "volumeStraight", $1 - 81 );
readingsBulkUpdate( $hash, "volume", sprintf "%d", readingsBulkUpdate( $hash, "volume", sprintf "%.0f",
$1 / 0.8 ); $1 / 0.81 );
push @matches, $d; push @matches, $d;
# Mute zone3 # Mute zone3