mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-01 20:20:10 +00:00
37_Spotify: applied API updates
git-svn-id: https://svn.fhem.de/fhem/trunk@16967 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
18969ecb51
commit
ee917a35f4
@ -327,7 +327,7 @@ sub Spotify_pausePlayback($) { # pause playback
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
$hash->{helper}{is_playing} = 0;
|
$hash->{helper}{is_playing} = 0;
|
||||||
readingsSingleUpdate($hash, 'is_playing', 0, 1);
|
readingsSingleUpdate($hash, 'is_playing', 0, 1);
|
||||||
Spotify_apiRequest($hash, 'me/player/pause', undef, 'PUT', 0);
|
Spotify_apiRequest($hash, 'me/player/pause', {}, 'PUT', 0);
|
||||||
Log3 $name, 4, "$name: pause";
|
Log3 $name, 4, "$name: pause";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -338,7 +338,7 @@ sub Spotify_resumePlayback($$) { # resume playback
|
|||||||
$device_id = Spotify_getTargetDeviceID($hash, $device_id, 0); # resolve target device id
|
$device_id = Spotify_getTargetDeviceID($hash, $device_id, 0); # resolve target device id
|
||||||
$hash->{helper}{is_playing} = 1;
|
$hash->{helper}{is_playing} = 1;
|
||||||
readingsSingleUpdate($hash, 'is_playing', 1, 1);
|
readingsSingleUpdate($hash, 'is_playing', 1, 1);
|
||||||
Spotify_apiRequest($hash, 'me/player/play' . (defined $device_id ? "?device_id=$device_id" : ''), undef, 'PUT', 0);
|
Spotify_apiRequest($hash, 'me/player/play' . (defined $device_id ? "?device_id=$device_id" : ''), {}, 'PUT', 0);
|
||||||
Log3 $name, 4, "$name: resume";
|
Log3 $name, 4, "$name: resume";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -357,7 +357,7 @@ sub Spotify_setVolume($$$$) { # set the volume
|
|||||||
delete $hash->{helper}{fading} if($blocking && defined $hash->{helper}{fading}); # stop volumeFade if currently active (override)
|
delete $hash->{helper}{fading} if($blocking && defined $hash->{helper}{fading}); # stop volumeFade if currently active (override)
|
||||||
|
|
||||||
$device_id = Spotify_getTargetDeviceID($hash, $device_id, 0); # resolve target device id
|
$device_id = Spotify_getTargetDeviceID($hash, $device_id, 0); # resolve target device id
|
||||||
Spotify_apiRequest($hash, "me/player/volume?volume_percent=$volume". (defined $device_id ? "&device_id=$device_id" : ''), undef, 'PUT', $blocking);
|
Spotify_apiRequest($hash, "me/player/volume?volume_percent=$volume". (defined $device_id ? "&device_id=$device_id" : ''), {}, 'PUT', $blocking);
|
||||||
Log3 $name, 4, "$name: volume $volume" if(!defined $hash->{helper}{fading});
|
Log3 $name, 4, "$name: volume $volume" if(!defined $hash->{helper}{fading});
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -365,7 +365,7 @@ sub Spotify_setVolume($$$$) { # set the volume
|
|||||||
sub Spotify_skipToNext($) { # skip to next track
|
sub Spotify_skipToNext($) { # skip to next track
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
Spotify_apiRequest($hash, 'me/player/next', undef, 'POST', 0);
|
Spotify_apiRequest($hash, 'me/player/next', encode_json {}, 'POST', 0);
|
||||||
Log3 $name, 4, "$name: skipToNext";
|
Log3 $name, 4, "$name: skipToNext";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -373,7 +373,7 @@ sub Spotify_skipToNext($) { # skip to next track
|
|||||||
sub Spotify_skipToPrevious($) { # skip to previous track
|
sub Spotify_skipToPrevious($) { # skip to previous track
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
Spotify_apiRequest($hash, 'me/player/previous', undef, 'POST', 0);
|
Spotify_apiRequest($hash, 'me/player/previous', encode_json {}, 'POST', 0);
|
||||||
Log3 $name, 4, "$name: skipToPrevious";
|
Log3 $name, 4, "$name: skipToPrevious";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -384,7 +384,7 @@ sub Spotify_seekToPosition($$) { # seek to position in track
|
|||||||
my (undef, $minutes, $seconds) = $position =~ m/(([0-9]+):)?([0-9]+)/;
|
my (undef, $minutes, $seconds) = $position =~ m/(([0-9]+):)?([0-9]+)/;
|
||||||
return 'wrong syntax: set <name> seekToPosition <position_in_s>' if(!defined $minutes && !defined $seconds);
|
return 'wrong syntax: set <name> seekToPosition <position_in_s>' if(!defined $minutes && !defined $seconds);
|
||||||
$position = ($minutes * 60 + $seconds) * 1000;
|
$position = ($minutes * 60 + $seconds) * 1000;
|
||||||
Spotify_apiRequest($hash, "me/player/seek?position_ms=$position", undef, 'PUT', 0);
|
Spotify_apiRequest($hash, "me/player/seek?position_ms=$position", {}, 'PUT', 0);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,7 +395,7 @@ sub Spotify_setRepeat($$) { # set the repeat mode
|
|||||||
$mode = 'track' if($mode eq 'one');
|
$mode = 'track' if($mode eq 'one');
|
||||||
$mode = 'context' if($mode eq 'all');
|
$mode = 'context' if($mode eq 'all');
|
||||||
my $device_id = Spotify_getTargetDeviceID($hash, undef, 0);
|
my $device_id = Spotify_getTargetDeviceID($hash, undef, 0);
|
||||||
Spotify_apiRequest($hash, "me/player/repeat?state=$mode". (defined $device_id ? "&device_id=$device_id" : ""), undef, 'PUT', 0);
|
Spotify_apiRequest($hash, "me/player/repeat?state=$mode". (defined $device_id ? "&device_id=$device_id" : ""), {}, 'PUT', 0);
|
||||||
Log3 $name, 4, "$name: repeat $mode";
|
Log3 $name, 4, "$name: repeat $mode";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -406,7 +406,7 @@ sub Spotify_setShuffle($$) { # set the shuffle mode
|
|||||||
return 'wrong syntax: set <name> shuffle <off,on>' if(!defined $mode || ($mode ne 'on' && $mode ne 'off'));
|
return 'wrong syntax: set <name> shuffle <off,on>' if(!defined $mode || ($mode ne 'on' && $mode ne 'off'));
|
||||||
$mode = $mode eq 'on' ? 'true' : 'false';
|
$mode = $mode eq 'on' ? 'true' : 'false';
|
||||||
my $device_id = Spotify_getTargetDeviceID($hash, undef, 0);
|
my $device_id = Spotify_getTargetDeviceID($hash, undef, 0);
|
||||||
Spotify_apiRequest($hash, "me/player/shuffle?state=$mode". (defined $device_id ? "&device_id=$device_id" : ""), undef, 'PUT', 0);
|
Spotify_apiRequest($hash, "me/player/shuffle?state=$mode". (defined $device_id ? "&device_id=$device_id" : ""), {}, 'PUT', 0);
|
||||||
Log3 $name, 4, "$name: shuffle $mode";
|
Log3 $name, 4, "$name: shuffle $mode";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -668,12 +668,12 @@ sub Spotify_volumeStep($$$$) {
|
|||||||
my @devices = @{$hash->{helper}{devices}};
|
my @devices = @{$hash->{helper}{devices}};
|
||||||
foreach my $device (@devices) {
|
foreach my $device (@devices) {
|
||||||
if(defined $device->{id} && $device->{id} eq $device_id) {
|
if(defined $device->{id} && $device->{id} eq $device_id) {
|
||||||
$nextVolume = min(100, max(0, $device->{volume_percent} + $step * $direction));
|
$nextVolume = $device->{volume_percent} + $step * $direction;
|
||||||
$device->{volume_percent} = $nextVolume;
|
$device->{volume_percent} = $nextVolume;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$nextVolume = min(100, max(0, $hash->{helper}{device_active}{volume_percent} + $step * $direction));
|
$nextVolume = $hash->{helper}{device_active}{volume_percent} + $step * $direction;
|
||||||
$hash->{helper}{device_active}{volume_percent} = $nextVolume;
|
$hash->{helper}{device_active}{volume_percent} = $nextVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user