feat(netd): add pause/unpause script
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-12-02 11:03:43 -05:00
parent 3fc7f54fd7
commit ce4f9c23ec
5 changed files with 98 additions and 5 deletions

View file

@ -0,0 +1,48 @@
using System;
using HomeAssistantGenerated;
using NetDaemon.AppModel;
using NetDaemon.HassModel;
using NetDaemon.HassModel.Integration;
namespace NetDaemonConfig.Apps.Spotify.PauseUnpause
{
public record PauseUnpauseData(bool pause);
[NetDaemonApp]
public class PlaySong
{
public PlaySong(IHaContext ha, Services services)
{
ha.RegisterServiceCallBack<PauseUnpauseData>(
"spotify_pause_unpause",
(e) =>
{
try
{
if (e.pause)
{
services.Spotifyplus.PlayerMediaPause(
entityId: SpotifyTypes.DefaultEntityId,
deviceId: SpotifyTypes.DefaultDevId);
}
else
{
services.Spotifyplus.PlayerMediaResume(
entityId: SpotifyTypes.DefaultEntityId,
deviceId: SpotifyTypes.DefaultDevId);
}
}
catch (Exception error)
{
services.Notify.PersistentNotification(
message: error.Message,
title: "Erreur Spotify");
}
}
);
}
}
}

View file

@ -92,7 +92,7 @@ in {
EOF EOF
)") . )") .
alejandra . alejandra -q .
rm -r "$FLAKE/.config" rm -r "$FLAKE/.config"
sed -i "s/finalImageTag = .*/finalImageTag = \"$(cat ./.version)\";/" ./images/netdaemon.nix sed -i "s/finalImageTag = .*/finalImageTag = \"$(cat ./.version)\";/" ./images/netdaemon.nix

View file

@ -46,6 +46,23 @@
slots.artist = ""; slots.artist = "";
} }
]; ];
Pause.data = [
{
sentences = [
"(pause|stop) [the] [(song|track|music)]"
"(pause|stop) spotify"
];
}
];
Unpause.data = [
{
sentences = [
"(unpause|resume) [the] [(song|track|music)]"
"(unpause|resume) spotify"
];
}
];
}; };
lists = { lists = {
@ -79,5 +96,13 @@
{% endif %} {% endif %}
on Spotify and playing it. on Spotify and playing it.
''; '';
Pause.default = ''
Pausing the music.
'';
Unpause.default = ''
Resuming the music.
'';
}; };
} }

View file

@ -24,7 +24,7 @@
config.intent_script = { config.intent_script = {
PlayAlbum = { PlayAlbum = {
async_action = "false"; async_action = false;
action = [ action = [
{ {
service = "netdaemon.spotify_play_album"; service = "netdaemon.spotify_play_album";
@ -37,7 +37,7 @@
}; };
PlayArtist = { PlayArtist = {
async_action = "false"; async_action = false;
action = [ action = [
{ {
service = "netdaemon.spotify_play_artist"; service = "netdaemon.spotify_play_artist";
@ -47,7 +47,7 @@
}; };
PlayPlaylist = { PlayPlaylist = {
async_action = "false"; async_action = false;
action = [ action = [
{ {
service = "netdaemon.spotify_play_playlist"; service = "netdaemon.spotify_play_playlist";
@ -57,7 +57,7 @@
}; };
PlaySong = { PlaySong = {
async_action = "false"; async_action = false;
action = [ action = [
{ {
service = "netdaemon.spotify_play_song"; service = "netdaemon.spotify_play_song";
@ -68,6 +68,26 @@
} }
]; ];
}; };
Pause = {
async_action = false;
action = [
{
service = "netdaemon.spotify_pause_unpause";
data.pause = true;
}
];
};
Unpause = {
async_action = false;
action = [
{
service = "netdaemon.spotify_pause_unpause";
data.pause = false;
}
];
};
}; };
}; };
} }