From e1a9f751f3f09bb44ee2ebbd82e90e2a69f93536 Mon Sep 17 00:00:00 2001 From: neumann <> Date: Tue, 30 May 2017 20:35:57 +0000 Subject: [PATCH] 37_Spotify: smooth volumeDown git-svn-id: https://svn.fhem.de/fhem/trunk@14434 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/37_Spotify.pm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/fhem/FHEM/37_Spotify.pm b/fhem/FHEM/37_Spotify.pm index 033b11f09..fb5d8b3dd 100644 --- a/fhem/FHEM/37_Spotify.pm +++ b/fhem/FHEM/37_Spotify.pm @@ -635,8 +635,22 @@ sub Spotify_volumeStep($$$$) { $step = $attr{$name}{volumeStep} if(!defined $step || $step !~ /^[0-9]+$/); $step = 5 if(!defined $step); - my $nextVolume = min(100, max(0, $hash->{helper}{device_active}{volume_percent} + $step * $direction)); - $hash->{helper}{device_active}{volume_percent} = $nextVolume; + my $nextVolume = undef; + if(defined $device_id) { + my @devices = @{$hash->{helper}{devices}}; + foreach my $device (@devices) { + if(defined $device->{id} && $device->{id} eq $device_id) { + $nextVolume = min(100, max(0, $device->{volume_percent} + $step * $direction)); + $device->{volume_percent} = $nextVolume; + } + } + } else { + $nextVolume = min(100, max(0, $hash->{helper}{device_active}{volume_percent} + $step * $direction)); + $hash->{helper}{device_active}{volume_percent} = $nextVolume; + } + + return "could not find device" if(!defined $nextVolume); + Spotify_setVolume($hash, 0, $nextVolume, $device_id); return undef;