diff --git a/devices/homie/modules/home-assistant/netdaemon/HomeAssistantGenerated b/devices/homie/modules/home-assistant/netdaemon/HomeAssistantGenerated index a7ed1b79..2a5adaaa 100644 Binary files a/devices/homie/modules/home-assistant/netdaemon/HomeAssistantGenerated and b/devices/homie/modules/home-assistant/netdaemon/HomeAssistantGenerated differ diff --git a/devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PauseUnpause/PauseUnpause.cs b/devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PauseUnpause/PauseUnpause.cs new file mode 100644 index 00000000..400b5c9a --- /dev/null +++ b/devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PauseUnpause/PauseUnpause.cs @@ -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( + "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"); + } + } + ); + } + } +} diff --git a/devices/homie/modules/home-assistant/netdaemon/default.nix b/devices/homie/modules/home-assistant/netdaemon/default.nix index b873a5e1..ca407fdf 100644 --- a/devices/homie/modules/home-assistant/netdaemon/default.nix +++ b/devices/homie/modules/home-assistant/netdaemon/default.nix @@ -92,7 +92,7 @@ in { EOF )") . - alejandra . + alejandra -q . rm -r "$FLAKE/.config" sed -i "s/finalImageTag = .*/finalImageTag = \"$(cat ./.version)\";/" ./images/netdaemon.nix diff --git a/devices/homie/modules/home-assistant/spotify-sentences.nix b/devices/homie/modules/home-assistant/spotify-sentences.nix index cd7d1c14..d782dfbf 100644 --- a/devices/homie/modules/home-assistant/spotify-sentences.nix +++ b/devices/homie/modules/home-assistant/spotify-sentences.nix @@ -46,6 +46,23 @@ 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 = { @@ -79,5 +96,13 @@ {% endif %} on Spotify and playing it. ''; + + Pause.default = '' + Pausing the music. + ''; + + Unpause.default = '' + Resuming the music. + ''; }; } diff --git a/devices/homie/modules/home-assistant/spotify.nix b/devices/homie/modules/home-assistant/spotify.nix index e3255557..75b929d9 100644 --- a/devices/homie/modules/home-assistant/spotify.nix +++ b/devices/homie/modules/home-assistant/spotify.nix @@ -24,7 +24,7 @@ config.intent_script = { PlayAlbum = { - async_action = "false"; + async_action = false; action = [ { service = "netdaemon.spotify_play_album"; @@ -37,7 +37,7 @@ }; PlayArtist = { - async_action = "false"; + async_action = false; action = [ { service = "netdaemon.spotify_play_artist"; @@ -47,7 +47,7 @@ }; PlayPlaylist = { - async_action = "false"; + async_action = false; action = [ { service = "netdaemon.spotify_play_playlist"; @@ -57,7 +57,7 @@ }; PlaySong = { - async_action = "false"; + async_action = false; action = [ { 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; + } + ]; + }; }; }; }