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 +
  • + volumeDown [ <step> ] [ <device_id / device_name> ]
    + decreases the volume by step (if not set it uses volumeStep) +
  • volumeFade <volume> [ <duration> <step> ] [ <device_id> ]
    fades the volume
  • +
  • + volumeDown [ <step> ] [ <device_id / device_name> ]
    + increases the volume by step (if not set it uses volumeStep) +

  • @@ -1085,6 +1108,11 @@ sub Spotify_isDisabled($) { the interval to update your playback status while music is running (in seconds)
    default: 10 +
  • + volumeStep
    + the value by which the volume is in-/decreased by default (in percent)
    + default: 5 +
  • @@ -1201,10 +1229,18 @@ sub Spotify_isDisabled($) { volume <volume> [ <device_id> ]
    setzt die Lautstärke +
  • + volumeDown [ <step> ] [ <device_id / device_name> ]
    + verringert die Lautstärke um step (falls nicht gesetzt, um volumeStep) +
  • volumeFade <volume> [ <duration> <step> ] [ <device_id> ]
    setzt die Lautstärke schrittweise
  • +
  • + volumeUp [ <step> ] [ <device_id / device_name> ]
    + erhöht die Lautstärke um step (falls nicht gesetzt, um volumeStep) +

  • @@ -1240,6 +1276,11 @@ sub Spotify_isDisabled($) { Intervall in Sekunden, in dem der Status aktualisiert wird, wenn Musik läuft
    default: 10 +
  • + volumeStep
    + der Wert, um den die Lautstärke bei volumeUp/volumeDown standardmäßig verändert wird (in Prozent)
    + default: 5 +