diff --git a/fhem/FHEM/37_Spotify.pm b/fhem/FHEM/37_Spotify.pm
index d14be7150..dec4e85d2 100644
--- a/fhem/FHEM/37_Spotify.pm
+++ b/fhem/FHEM/37_Spotify.pm
@@ -26,7 +26,7 @@ sub Spotify_Initialize($) {
$hash->{SetFn} = 'Spotify_Set';
$hash->{GetFn} = 'Spotify_Get';
#$hash->{AttrFn} = "Spotify_Attr";
- $hash->{AttrList} = 'defaultPlaybackDeviceID alwaysStartOnDefaultDevice:0,1 updateInterval updateIntervalWhilePlaying disable:0,1 ';
+ $hash->{AttrList} = 'defaultPlaybackDeviceID alwaysStartOnDefaultDevice:0,1 updateInterval updateIntervalWhilePlaying disable:0,1 volumeStep ';
$hash->{AttrList} .= $readingFnAttributes;
$hash->{NOTIFYDEV} = "global";
}
@@ -93,7 +93,7 @@ sub Spotify_Set($$@) {
} else {
$list .= ' playTrackByURI playContextByURI pause:noArg resume:noArg volume:slider,0,1,100 update:noArg';
$list .= ' skipToNext:noArg skipToPrevious:noArg seekToPosition repeat:one,all,off shuffle:on,off transferPlayback volumeFade:slider,0,1,100 playTrackByName playPlaylistByName togglePlayback';
- $list .= ' playSavedTracks playRandomTrackFromPlaylistByURI findTrackByName findArtistByName playArtistByName';
+ $list .= ' playSavedTracks playRandomTrackFromPlaylistByURI findTrackByName findArtistByName playArtistByName volumeUp volumeDown';
}
if($cmd eq 'code') {
@@ -124,6 +124,7 @@ sub Spotify_Set($$@) {
return Spotify_findTrackByName($hash, @args > 0 ? join(' ', @args) : undef) if($cmd eq 'findTrackByName');
return Spotify_findArtistByName($hash, @args > 0 ? join(' ', @args) : undef) if($cmd eq 'findArtistByName');
return Spotify_playArtistByName($hash, @args > 0 ? join(' ', @args) : undef) if($cmd eq 'playArtistByName');
+ return Spotify_volumeStep($hash, $cmd eq 'volumeDown' ? -1 : 1, $args[0], defined $args[1] ? join(' ', @args[1..$#args]) : undef) if($cmd eq 'volumeUp' || $cmd eq 'volumeDown');
return "Unknown argument $cmd, choose one of $list";
}
@@ -165,7 +166,7 @@ sub Spotify_loadInternals($) {
} else {
$hash->{STATE} = 'connected';
my $pollInterval = $attr{$name}{pollInterval};
- $attr{$name}{webCmd} = 'toggle:next:prev' if(!defined $attr{$name}{webCmd});
+ $attr{$name}{webCmd} = 'toggle:next:prev:volumeUp:volumeDown' if(!defined $attr{$name}{webCmd});
Spotify_poll($hash) if(defined $hash->{helper}{refresh_token} && !Spotify_isDisabled($hash));
}
@@ -626,6 +627,20 @@ sub Spotify_togglePlayback($) { # toggle playback (pause if active, resume other
return undef;
}
+sub Spotify_volumeStep($$$$) {
+ my ($hash, $direction, $step, $device_id) = @_;
+ my $name = $hash->{NAME};
+
+ $device_id = $step . (defined $device_id ? " ". $device_id : "") if(defined $step && $step !~ /^[0-9]+$/);
+ $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));
+ Spotify_setVolume($hash, 0, $nextVolume, $device_id);
+
+ return undef;
+}
+
sub Spotify_getTargetDeviceID($$$) { # resolve target device settings
my ($hash, $device_id, $newPlayback) = @_;
@@ -1046,10 +1061,18 @@ sub Spotify_isDisabled($) {
volume <volume> [ <device_id> ]
sets the volume
+